Here are the examples of the java api class org.apache.activemq.command.MessageDispatch taken from open source projects.
1. OpenWireMessageConverter#createMessageDispatch()
Project: activemq-artemis
File: OpenWireMessageConverter.java
File: OpenWireMessageConverter.java
public static MessageDispatch createMessageDispatch(MessageReference reference, ServerMessage message, AMQConsumer consumer) throws IOException, JMSException { ActiveMQMessage amqMessage = toAMQMessage(reference, message, consumer.getMarshaller(), consumer.getOpenwireDestination()); //we can use core message id for sequenceId amqMessage.getMessageId().setBrokerSequenceId(message.getMessageID()); MessageDispatch md = new MessageDispatch(); md.setConsumerId(consumer.getId()); md.setRedeliveryCounter(reference.getDeliveryCount() - 1); md.setDeliverySequenceId(amqMessage.getMessageId().getBrokerSequenceId()); md.setMessage(amqMessage); ActiveMQDestination destination = amqMessage.getDestination(); md.setDestination(destination); return md; }
2. ActiveMQMessageConsumerDispatchInterceptor#createTrace()
Project: pinpoint
File: ActiveMQMessageConsumerDispatchInterceptor.java
File: ActiveMQMessageConsumerDispatchInterceptor.java
@Override protected Trace createTrace(Object target, Object[] args) { if (!validate(target, args)) { return null; } MessageDispatch md = (MessageDispatch) args[0]; ActiveMQMessage message = (ActiveMQMessage) md.getMessage(); if (filterDestination(message.getDestination())) { return null; } // These might trigger unmarshalling. if (!ActiveMQClientHeader.getSampled(message, true)) { return traceContext.disableSampling(); } String transactionId = ActiveMQClientHeader.getTraceId(message, null); if (transactionId != null) { long parentSpanId = ActiveMQClientHeader.getParentSpanId(message, SpanId.NULL); long spanId = ActiveMQClientHeader.getSpanId(message, SpanId.NULL); short flags = ActiveMQClientHeader.getFlags(message, (short) 0); final TraceId traceId = traceContext.createTraceId(transactionId, parentSpanId, spanId, flags); return traceContext.continueTraceObject(traceId); } else { return traceContext.newTraceObject(); } }
3. AMQConsumer#handleDeliver()
Project: activemq-artemis
File: AMQConsumer.java
File: AMQConsumer.java
public int handleDeliver(MessageReference reference, ServerMessage message, int deliveryCount) { MessageDispatch dispatch; try { if (messagePullHandler != null && !messagePullHandler.checkForcedConsumer(message)) { return 0; } dispatch = OpenWireMessageConverter.createMessageDispatch(reference, message, this); int size = dispatch.getMessage().getSize(); reference.setProtocolData(dispatch.getMessage().getMessageId()); session.deliverMessage(dispatch); currentWindow.decrementAndGet(); return size; } catch (IOException e) { e.printStackTrace(); return 0; } catch (Throwable t) { t.printStackTrace(); return 0; } }
4. MessageDispatchTest#populateObject()
Project: activemq-artemis
File: MessageDispatchTest.java
File: MessageDispatchTest.java
@Override protected void populateObject(Object object) throws Exception { super.populateObject(object); MessageDispatch info = (MessageDispatch) object; info.setConsumerId(createConsumerId("ConsumerId:1")); info.setDestination(createActiveMQDestination("Destination:2")); info.setMessage(createMessage("Message:3")); info.setRedeliveryCounter(1); }
5. MessageDispatchTest#populateObject()
Project: activemq-artemis
File: MessageDispatchTest.java
File: MessageDispatchTest.java
@Override protected void populateObject(Object object) throws Exception { super.populateObject(object); MessageDispatch info = (MessageDispatch) object; info.setConsumerId(createConsumerId("ConsumerId:1")); info.setDestination(createActiveMQDestination("Destination:2")); info.setMessage(createMessage("Message:3")); info.setRedeliveryCounter(1); }
6. MessageDispatchTest#populateObject()
Project: activemq-artemis
File: MessageDispatchTest.java
File: MessageDispatchTest.java
@Override protected void populateObject(Object object) throws Exception { super.populateObject(object); MessageDispatch info = (MessageDispatch) object; info.setConsumerId(createConsumerId("ConsumerId:1")); info.setDestination(createActiveMQDestination("Destination:2")); info.setMessage(createMessage("Message:3")); info.setRedeliveryCounter(1); }
7. AMQConsumer#browseFinished()
Project: activemq-artemis
File: AMQConsumer.java
File: AMQConsumer.java
public void browseFinished() { MessageDispatch md = new MessageDispatch(); md.setConsumerId(info.getConsumerId()); md.setMessage(null); md.setDestination(null); session.deliverMessage(md); }
8. AMQConsumer#handleDeliverNullDispatch()
Project: activemq-artemis
File: AMQConsumer.java
File: AMQConsumer.java
public void handleDeliverNullDispatch() { MessageDispatch md = new MessageDispatch(); md.setConsumerId(getId()); md.setDestination(openwireDestination); session.deliverMessage(md); }
9. ActiveMQMessageConsumerDispatchInterceptor#validate()
Project: pinpoint
File: ActiveMQMessageConsumerDispatchInterceptor.java
File: ActiveMQMessageConsumerDispatchInterceptor.java
private boolean validate(Object target, Object[] args) { if (!(target instanceof ActiveMQMessageConsumer)) { return false; } if (!(target instanceof ActiveMQSessionGetter)) { if (isDebug) { logger.debug("Invalid target object. Need field accessor({}).", ActiveMQSessionGetter.class.getName()); } return false; } if (!validateTransport(((ActiveMQSessionGetter) target)._$PINPOINT$_getActiveMQSession())) { return false; } if (args == null || args.length < 1) { return false; } if (!(args[0] instanceof MessageDispatch)) { return false; } MessageDispatch md = (MessageDispatch) args[0]; Message message = md.getMessage(); if (!(message instanceof ActiveMQMessage)) { return false; } return true; }
10. ActiveMQMessageConsumerDispatchInterceptor#doInBeforeTrace()
Project: pinpoint
File: ActiveMQMessageConsumerDispatchInterceptor.java
File: ActiveMQMessageConsumerDispatchInterceptor.java
@Override protected void doInBeforeTrace(SpanRecorder recorder, Object target, Object[] args) { recorder.recordServiceType(ActiveMQClientConstants.ACTIVEMQ_CLIENT); ActiveMQSession session = ((ActiveMQSessionGetter) target)._$PINPOINT$_getActiveMQSession(); ActiveMQConnection connection = session.getConnection(); Transport transport = getRootTransport(((TransportGetter) connection)._$PINPOINT$_getTransport()); Socket socket = ((SocketGetter) transport)._$PINPOINT$_getSocket(); SocketAddress localSocketAddress = socket.getLocalSocketAddress(); String endPoint = ActiveMQClientUtils.getEndPoint(localSocketAddress); // Endpoint should be the local socket address of the consumer. recorder.recordEndPoint(endPoint); SocketAddress remoteSocketAddress = socket.getRemoteSocketAddress(); String remoteAddress = ActiveMQClientUtils.getEndPoint(remoteSocketAddress); // Remote address is the socket address of where the consumer is connected to. recorder.recordRemoteAddress(remoteAddress); MessageDispatch md = (MessageDispatch) args[0]; ActiveMQMessage message = (ActiveMQMessage) md.getMessage(); ActiveMQDestination destination = message.getDestination(); // Rpc name is the URI of the queue/topic we're consuming from. recorder.recordRpcName(destination.getQualifiedName()); // Record acceptor host as the queue/topic name in order to generate virtual queue node. recorder.recordAcceptorHost(destination.getPhysicalName()); String parentApplicationName = ActiveMQClientHeader.getParentApplicationName(message, null); if (!recorder.isRoot() && parentApplicationName != null) { short parentApplicationType = ActiveMQClientHeader.getParentApplicationType(message, ServiceType.UNDEFINED.getCode()); recorder.recordParentApplication(parentApplicationName, parentApplicationType); } }
11. MessageDispatchTest#createObject()
Project: activemq-artemis
File: MessageDispatchTest.java
File: MessageDispatchTest.java
@Override public Object createObject() throws Exception { MessageDispatch info = new MessageDispatch(); populateObject(info); return info; }
12. MessageDispatchTest#createObject()
Project: activemq-artemis
File: MessageDispatchTest.java
File: MessageDispatchTest.java
@Override public Object createObject() throws Exception { MessageDispatch info = new MessageDispatch(); populateObject(info); return info; }
13. MessageDispatchTest#createObject()
Project: activemq-artemis
File: MessageDispatchTest.java
File: MessageDispatchTest.java
@Override public Object createObject() throws Exception { MessageDispatch info = new MessageDispatch(); populateObject(info); return info; }
14. NetworkRouteTest#before()
Project: activemq-artemis
File: NetworkRouteTest.java
File: NetworkRouteTest.java
@Before public void before() throws Exception { control = EasyMock.createControl(); localBroker = control.createMock(Transport.class); remoteBroker = control.createMock(Transport.class); NetworkBridgeConfiguration configuration = new NetworkBridgeConfiguration(); brokerService = new BrokerService(); BrokerInfo remoteBrokerInfo = new BrokerInfo(); configuration.setDuplex(true); configuration.setNetworkTTL(5); brokerService.setBrokerId("broker-1"); brokerService.setPersistent(false); brokerService.setUseJmx(false); brokerService.start(); brokerService.waitUntilStarted(); remoteBrokerInfo.setBrokerId(new BrokerId("remote-broker-id")); remoteBrokerInfo.setBrokerName("remote-broker-name"); localBroker.setTransportListener(EasyMock.isA(TransportListener.class)); ArgHolder localListenerRef = ArgHolder.holdArgsForLastVoidCall(); remoteBroker.setTransportListener(EasyMock.isA(TransportListener.class)); ArgHolder remoteListenerRef = ArgHolder.holdArgsForLastVoidCall(); localBroker.start(); remoteBroker.start(); remoteBroker.oneway(EasyMock.isA(Object.class)); EasyMock.expectLastCall().times(4); remoteBroker.oneway(EasyMock.isA(Object.class)); ExpectationWaiter remoteInitWaiter = ExpectationWaiter.waiterForLastVoidCall(); localBroker.oneway(remoteBrokerInfo); EasyMock.expect(localBroker.request(EasyMock.isA(Object.class))).andReturn(null); localBroker.oneway(EasyMock.isA(Object.class)); ExpectationWaiter localInitWaiter = ExpectationWaiter.waiterForLastVoidCall(); control.replay(); DurableConduitBridge bridge = new DurableConduitBridge(configuration, localBroker, remoteBroker); bridge.setBrokerService(brokerService); bridge.start(); localListener = (TransportListener) localListenerRef.getArguments()[0]; Assert.assertNotNull(localListener); remoteListener = (TransportListener) remoteListenerRef.getArguments()[0]; Assert.assertNotNull(remoteListener); remoteListener.onCommand(remoteBrokerInfo); remoteInitWaiter.assertHappens(5, TimeUnit.SECONDS); localInitWaiter.assertHappens(5, TimeUnit.SECONDS); control.verify(); control.reset(); ActiveMQMessage msg = new ActiveMQMessage(); msg.setDestination(new ActiveMQTopic("test")); msgDispatch = new MessageDispatch(); msgDispatch.setMessage(msg); ConsumerInfo path1 = new ConsumerInfo(); path1.setDestination(msg.getDestination()); path1.setConsumerId(new ConsumerId(new SessionId(new ConnectionId("conn-id-1"), 1), 3)); path1.setBrokerPath(new BrokerId[] { new BrokerId("remote-broker-id"), new BrokerId("server(1)-broker-id") }); path1Msg = new ActiveMQMessage(); path1Msg.setDestination(AdvisorySupport.getConsumerAdvisoryTopic(path1.getDestination())); path1Msg.setDataStructure(path1); ConsumerInfo path2 = new ConsumerInfo(); path2.setDestination(path1.getDestination()); path2.setConsumerId(new ConsumerId(new SessionId(new ConnectionId("conn-id-2"), 2), 4)); path2.setBrokerPath(new BrokerId[] { new BrokerId("remote-broker-id"), new BrokerId("server(2)-broker-id"), new BrokerId("server(1)-broker-id") }); path2Msg = new ActiveMQMessage(); path2Msg.setDestination(path1Msg.getDestination()); path2Msg.setDataStructure(path2); RemoveInfo removePath1 = new RemoveInfo(path1.getConsumerId()); RemoveInfo removePath2 = new RemoveInfo(path2.getConsumerId()); removePath1Msg = new ActiveMQMessage(); removePath1Msg.setDestination(path1Msg.getDestination()); removePath1Msg.setDataStructure(removePath1); removePath2Msg = new ActiveMQMessage(); removePath2Msg.setDestination(path1Msg.getDestination()); removePath2Msg.setDataStructure(removePath2); }
15. OpenWireConnection#processDispatch()
Project: activemq-artemis
File: OpenWireConnection.java
File: OpenWireConnection.java
protected void processDispatch(Command command) throws IOException { MessageDispatch messageDispatch = (MessageDispatch) (command.isMessageDispatch() ? command : null); try { if (!stopping.get()) { if (messageDispatch != null) { protocolManager.preProcessDispatch(messageDispatch); } dispatch(command); } } catch (IOException e) { if (messageDispatch != null) { TransmitCallback sub = messageDispatch.getTransmitCallback(); protocolManager.postProcessDispatch(messageDispatch); if (sub != null) { sub.onFailure(); } messageDispatch = null; throw e; } } finally { if (messageDispatch != null) { TransmitCallback sub = messageDispatch.getTransmitCallback(); protocolManager.postProcessDispatch(messageDispatch); if (sub != null) { sub.onSuccess(); } } } }