Search in sources :

Example 16 with MessageDispatch

use of org.apache.activemq.command.MessageDispatch in project activemq-artemis by apache.

the class NetworkRouteTest method before.

@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);
}
Also used : ActiveMQTopic(org.apache.activemq.command.ActiveMQTopic) ConsumerInfo(org.apache.activemq.command.ConsumerInfo) BrokerId(org.apache.activemq.command.BrokerId) BrokerInfo(org.apache.activemq.command.BrokerInfo) ActiveMQMessage(org.apache.activemq.command.ActiveMQMessage) TransportListener(org.apache.activemq.transport.TransportListener) MessageDispatch(org.apache.activemq.command.MessageDispatch) ConnectionId(org.apache.activemq.command.ConnectionId) RemoveInfo(org.apache.activemq.command.RemoveInfo) ConsumerId(org.apache.activemq.command.ConsumerId) Transport(org.apache.activemq.transport.Transport) BrokerService(org.apache.activemq.broker.BrokerService) SessionId(org.apache.activemq.command.SessionId) Before(org.junit.Before)

Example 17 with MessageDispatch

use of org.apache.activemq.command.MessageDispatch in project activemq-artemis by apache.

the class BrokerTestSupport method countMessagesInQueue.

protected int countMessagesInQueue(StubConnection connection, ConnectionInfo connectionInfo, ActiveMQDestination destination) throws Exception {
    SessionInfo sessionInfo = createSessionInfo(connectionInfo);
    connection.send(sessionInfo);
    ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo, destination);
    consumerInfo.setPrefetchSize(1);
    consumerInfo.setBrowser(true);
    connection.send(consumerInfo);
    ArrayList<Object> skipped = new ArrayList<>();
    // Now get the messages.
    Object m = connection.getDispatchQueue().poll(maxWait, TimeUnit.MILLISECONDS);
    int i = 0;
    while (m != null) {
        if (m instanceof MessageDispatch && ((MessageDispatch) m).getConsumerId().equals(consumerInfo.getConsumerId())) {
            MessageDispatch md = (MessageDispatch) m;
            if (md.getMessage() != null) {
                i++;
                connection.send(createAck(consumerInfo, md.getMessage(), 1, MessageAck.STANDARD_ACK_TYPE));
            } else {
                break;
            }
        } else {
            skipped.add(m);
        }
        m = connection.getDispatchQueue().poll(maxWait, TimeUnit.MILLISECONDS);
    }
    for (Iterator<Object> iter = skipped.iterator(); iter.hasNext(); ) {
        connection.getDispatchQueue().put(iter.next());
    }
    connection.send(closeSessionInfo(sessionInfo));
    return i;
}
Also used : MessageDispatch(org.apache.activemq.command.MessageDispatch) ConsumerInfo(org.apache.activemq.command.ConsumerInfo) ArrayList(java.util.ArrayList) SessionInfo(org.apache.activemq.command.SessionInfo)

Example 18 with MessageDispatch

use of org.apache.activemq.command.MessageDispatch in project activemq-artemis by apache.

the class BrokerTestSupport method receiveMessage.

public Message receiveMessage(StubConnection connection, long timeout) throws InterruptedException {
    while (true) {
        Object o = connection.getDispatchQueue().poll(timeout, TimeUnit.MILLISECONDS);
        if (o == null) {
            return null;
        }
        if (o instanceof MessageDispatch) {
            MessageDispatch dispatch = (MessageDispatch) o;
            if (dispatch.getMessage() == null) {
                return null;
            }
            dispatch.setMessage(dispatch.getMessage().copy());
            dispatch.getMessage().setRedeliveryCounter(dispatch.getRedeliveryCounter());
            return dispatch.getMessage();
        }
    }
}
Also used : MessageDispatch(org.apache.activemq.command.MessageDispatch)

Example 19 with MessageDispatch

use of org.apache.activemq.command.MessageDispatch in project activemq-artemis by apache.

the class MessageDispatchTest method createObject.

@Override
public Object createObject() throws Exception {
    MessageDispatch info = new MessageDispatch();
    populateObject(info);
    return info;
}
Also used : MessageDispatch(org.apache.activemq.command.MessageDispatch)

Example 20 with MessageDispatch

use of org.apache.activemq.command.MessageDispatch in project activemq-artemis by apache.

the class MessageDispatchTest method populateObject.

@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);
}
Also used : MessageDispatch(org.apache.activemq.command.MessageDispatch)

Aggregations

MessageDispatch (org.apache.activemq.command.MessageDispatch)34 ActiveMQMessage (org.apache.activemq.command.ActiveMQMessage)6 ActiveMQDestination (org.apache.activemq.command.ActiveMQDestination)4 ActiveMQSessionGetter (com.navercorp.pinpoint.plugin.activemq.client.field.getter.ActiveMQSessionGetter)3 Transport (org.apache.activemq.transport.Transport)3 IOException (java.io.IOException)2 ActiveMQConnection (org.apache.activemq.ActiveMQConnection)2 ActiveMQSession (org.apache.activemq.ActiveMQSession)2 BrokerService (org.apache.activemq.broker.BrokerService)2 ConsumerInfo (org.apache.activemq.command.ConsumerInfo)2 SocketGetter (com.navercorp.pinpoint.plugin.activemq.client.field.getter.SocketGetter)1 Socket (java.net.Socket)1 SocketAddress (java.net.SocketAddress)1 ArrayList (java.util.ArrayList)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Destination (javax.jms.Destination)1 ActiveMQMessageConsumer (org.apache.activemq.ActiveMQMessageConsumer)1 Broker (org.apache.activemq.broker.Broker)1 BrokerFilter (org.apache.activemq.broker.BrokerFilter)1 BrokerPlugin (org.apache.activemq.broker.BrokerPlugin)1