Search in sources :

Example 1 with StubConnection

use of org.apache.activemq.broker.StubConnection in project activemq-artemis by apache.

the class DemandForwardingBridgeTest method testSendThenAddConsumer.

public void testSendThenAddConsumer() throws Exception {
    // Start a producer on local broker
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ProducerInfo producerInfo = createProducerInfo(sessionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(producerInfo);
    destination = createDestinationInfo(connection1, connectionInfo1, destinationType);
    // Start a consumer on a remote broker
    final StubConnection connection2 = createRemoteConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    // Send the message to the local broker.
    connection1.send(createMessage(producerInfo, destination, deliveryMode));
    // Verify that the message stayed on the local broker.
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    connection1.send(consumerInfo1);
    Message m = receiveMessage(connection1);
    assertNotNull(m);
    // Close consumer to cause the message to rollback.
    connection1.send(consumerInfo1.createRemoveCommand());
    final DestinationStatistics destinationStatistics = broker.getDestination(destination).getDestinationStatistics();
    assertEquals("broker dest stat dispatched", 1, destinationStatistics.getDispatched().getCount());
    assertEquals("broker dest stat dequeues", 0, destinationStatistics.getDequeues().getCount());
    assertEquals("broker dest stat forwards", 0, destinationStatistics.getForwards().getCount());
    // Now create remote consumer that should cause message to move to this
    // remote consumer.
    final ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, destination);
    connection2.request(consumerInfo2);
    // Make sure the message was delivered via the remote.
    assertTrue("message was received", Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            Message msg = receiveMessage(connection2);
            if (msg != null) {
                connection2.request(createAck(consumerInfo2, msg, 1, MessageAck.STANDARD_ACK_TYPE));
                return true;
            }
            return false;
        }
    }));
    assertTrue("broker dest stat forwards", Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            return 1 == destinationStatistics.getForwards().getCount();
        }
    }));
    assertEquals("broker dest stat dequeues", 1, destinationStatistics.getDequeues().getCount());
}
Also used : ProducerInfo(org.apache.activemq.command.ProducerInfo) ConsumerInfo(org.apache.activemq.command.ConsumerInfo) DestinationStatistics(org.apache.activemq.broker.region.DestinationStatistics) Message(org.apache.activemq.command.Message) StubConnection(org.apache.activemq.broker.StubConnection) SessionInfo(org.apache.activemq.command.SessionInfo) ConnectionInfo(org.apache.activemq.command.ConnectionInfo)

Example 2 with StubConnection

use of org.apache.activemq.broker.StubConnection in project activemq-artemis by apache.

the class DemandForwardingBridgeTest method testAddConsumerThenSend.

public void testAddConsumerThenSend() throws Exception {
    // Start a producer on local broker
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ProducerInfo producerInfo = createProducerInfo(sessionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(producerInfo);
    destination = createDestinationInfo(connection1, connectionInfo1, destinationType);
    // Start a consumer on a remote broker
    StubConnection connection2 = createRemoteConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo2, destination);
    connection2.send(consumerInfo);
    // subscriptions.
    try {
        Thread.sleep(1000);
    } catch (InterruptedException ie) {
        ie.printStackTrace();
    }
    // Send the message to the local boker.
    connection1.request(createMessage(producerInfo, destination, deliveryMode));
    // Make sure the message was delivered via the remote.
    receiveMessage(connection2);
}
Also used : ProducerInfo(org.apache.activemq.command.ProducerInfo) ConsumerInfo(org.apache.activemq.command.ConsumerInfo) StubConnection(org.apache.activemq.broker.StubConnection) SessionInfo(org.apache.activemq.command.SessionInfo) ConnectionInfo(org.apache.activemq.command.ConnectionInfo)

Example 3 with StubConnection

use of org.apache.activemq.broker.StubConnection in project activemq-artemis by apache.

the class BrokerNetworkWithStuckMessagesTest method createRemoteConnection.

protected StubConnection createRemoteConnection() throws Exception {
    Transport transport = TransportFactory.connect(remoteConnector.getServer().getConnectURI());
    StubConnection connection = new StubConnection(transport);
    connections.add(connection);
    return connection;
}
Also used : StubConnection(org.apache.activemq.broker.StubConnection) Transport(org.apache.activemq.transport.Transport)

Example 4 with StubConnection

use of org.apache.activemq.broker.StubConnection in project activemq-artemis by apache.

the class BrokerNetworkWithStuckMessagesTest method testBrokerNetworkWithStuckMessages.

@Test(timeout = 120000)
public void testBrokerNetworkWithStuckMessages() throws Exception {
    int sendNumMessages = 10;
    int receiveNumMessages = 5;
    // Create a producer
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ProducerInfo producerInfo = createProducerInfo(sessionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(producerInfo);
    // Create a destination on the local broker
    ActiveMQDestination destinationInfo1 = null;
    // Send a 10 messages to the local broker
    for (int i = 0; i < sendNumMessages; ++i) {
        destinationInfo1 = createDestinationInfo(connection1, connectionInfo1, ActiveMQDestination.QUEUE_TYPE);
        connection1.request(createMessage(producerInfo, destinationInfo1, DeliveryMode.NON_PERSISTENT));
    }
    // Ensure that there are 10 messages on the local broker
    Object[] messages = browseQueueWithJmx(localBroker);
    assertEquals(sendNumMessages, messages.length);
    // Create a synchronous consumer on the remote broker
    StubConnection connection2 = createRemoteConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    ActiveMQDestination destinationInfo2 = createDestinationInfo(connection2, connectionInfo2, ActiveMQDestination.QUEUE_TYPE);
    final ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, destinationInfo2);
    connection2.send(consumerInfo2);
    // Consume 5 of the messages from the remote broker and ack them.
    for (int i = 0; i < receiveNumMessages; ++i) {
        Message message1 = receiveMessage(connection2, 20000);
        assertNotNull(message1);
        LOG.info("on remote, got: " + message1.getMessageId());
        connection2.send(createAck(consumerInfo2, message1, 1, MessageAck.INDIVIDUAL_ACK_TYPE));
        assertTrue("JMSActiveMQBrokerPath property present and correct", ((ActiveMQMessage) message1).getStringProperty(ActiveMQMessage.BROKER_PATH_PROPERTY).contains(localBroker.getBroker().getBrokerId().toString()));
    }
    // Ensure that there are zero messages on the local broker. This tells
    // us that those messages have been prefetched to the remote broker
    // where the demand exists.
    Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            Object[] result = browseQueueWithJmx(localBroker);
            return 0 == result.length;
        }
    });
    messages = browseQueueWithJmx(localBroker);
    assertEquals(0, messages.length);
    // try and pull the messages from remote, should be denied b/c on networkTtl
    LOG.info("creating demand on second remote...");
    StubConnection connection3 = createSecondRemoteConnection();
    ConnectionInfo connectionInfo3 = createConnectionInfo();
    SessionInfo sessionInfo3 = createSessionInfo(connectionInfo3);
    connection3.send(connectionInfo3);
    connection3.send(sessionInfo3);
    ActiveMQDestination destinationInfo3 = createDestinationInfo(connection3, connectionInfo3, ActiveMQDestination.QUEUE_TYPE);
    final ConsumerInfo consumerInfoS3 = createConsumerInfo(sessionInfo3, destinationInfo3);
    connection3.send(consumerInfoS3);
    Message messageExceedingTtl = receiveMessage(connection3, 5000);
    if (messageExceedingTtl != null) {
        LOG.error("got message on Second remote: " + messageExceedingTtl);
        connection3.send(createAck(consumerInfoS3, messageExceedingTtl, 1, MessageAck.INDIVIDUAL_ACK_TYPE));
    }
    LOG.info("Closing consumer on remote");
    // Close the consumer on the remote broker
    connection2.send(consumerInfo2.createRemoveCommand());
    // also close connection etc.. so messages get dropped from the local consumer  q
    connection2.send(connectionInfo2.createRemoveCommand());
    // There should now be 5 messages stuck on the remote broker
    assertTrue("correct stuck message count", Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            Object[] result = browseQueueWithJmx(remoteBroker);
            return 5 == result.length;
        }
    }));
    messages = browseQueueWithJmx(remoteBroker);
    assertEquals(5, messages.length);
    assertTrue("can see broker path property", ((String) ((CompositeData) messages[1]).get("BrokerPath")).contains(localBroker.getBroker().getBrokerId().toString()));
    LOG.info("Messages now stuck on remote");
    // receive again on the origin broker
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destinationInfo1);
    connection1.send(consumerInfo1);
    LOG.info("create local consumer: " + consumerInfo1);
    Message message1 = receiveMessage(connection1, 20000);
    assertNotNull("Expect to get a replay as remote consumer is gone", message1);
    connection1.send(createAck(consumerInfo1, message1, 1, MessageAck.INDIVIDUAL_ACK_TYPE));
    LOG.info("acked one message on origin, waiting for all messages to percolate back");
    Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            Object[] result = browseQueueWithJmx(localBroker);
            return 4 == result.length;
        }
    });
    messages = browseQueueWithJmx(localBroker);
    assertEquals(4, messages.length);
    LOG.info("checking for messages on remote again");
    // messages won't migrate back again till consumer closes
    connection2 = createRemoteConnection();
    connectionInfo2 = createConnectionInfo();
    sessionInfo2 = createSessionInfo(connectionInfo2);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    ConsumerInfo consumerInfo3 = createConsumerInfo(sessionInfo2, destinationInfo2);
    connection2.send(consumerInfo3);
    message1 = receiveMessage(connection2, 20000);
    assertNull("Messages have migrated back: " + message1, message1);
    // Consume the last 4 messages from the local broker and ack them just
    // to clean up the queue.
    int counter = 1;
    for (; counter < receiveNumMessages; counter++) {
        message1 = receiveMessage(connection1);
        LOG.info("local consume of: " + (message1 != null ? message1.getMessageId() : " null"));
        connection1.send(createAck(consumerInfo1, message1, 1, MessageAck.INDIVIDUAL_ACK_TYPE));
    }
    // Ensure that 5 messages were received
    assertEquals(receiveNumMessages, counter);
    // verify all messages consumed
    Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            Object[] result = browseQueueWithJmx(remoteBroker);
            return 0 == result.length;
        }
    });
    messages = browseQueueWithJmx(remoteBroker);
    assertEquals(0, messages.length);
    Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            Object[] result = browseQueueWithJmx(localBroker);
            return 0 == result.length;
        }
    });
    messages = browseQueueWithJmx(localBroker);
    assertEquals(0, messages.length);
    // Close the consumer on the remote broker
    connection2.send(consumerInfo3.createRemoveCommand());
    connection1.stop();
    connection2.stop();
    connection3.stop();
}
Also used : ProducerInfo(org.apache.activemq.command.ProducerInfo) ConsumerInfo(org.apache.activemq.command.ConsumerInfo) ActiveMQMessage(org.apache.activemq.command.ActiveMQMessage) Message(org.apache.activemq.command.Message) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) CompositeData(javax.management.openmbean.CompositeData) SessionInfo(org.apache.activemq.command.SessionInfo) URISyntaxException(java.net.URISyntaxException) MessageNotWriteableException(javax.jms.MessageNotWriteableException) IOException(java.io.IOException) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination) ActiveMQMessage(org.apache.activemq.command.ActiveMQMessage) StubConnection(org.apache.activemq.broker.StubConnection) ConnectionInfo(org.apache.activemq.command.ConnectionInfo) Wait(org.apache.activemq.util.Wait) Test(org.junit.Test)

Example 5 with StubConnection

use of org.apache.activemq.broker.StubConnection in project activemq-artemis by apache.

the class ProxyTestSupport method createRemoteProxyConnection.

protected StubConnection createRemoteProxyConnection() throws Exception {
    Transport transport = TransportFactory.connect(remoteProxyConnector.getServer().getConnectURI());
    StubConnection connection = new StubConnection(transport);
    connections.add(connection);
    return connection;
}
Also used : StubConnection(org.apache.activemq.broker.StubConnection) Transport(org.apache.activemq.transport.Transport)

Aggregations

StubConnection (org.apache.activemq.broker.StubConnection)39 ConnectionInfo (org.apache.activemq.command.ConnectionInfo)18 SessionInfo (org.apache.activemq.command.SessionInfo)18 ConsumerInfo (org.apache.activemq.command.ConsumerInfo)17 Transport (org.apache.activemq.transport.Transport)16 ProducerInfo (org.apache.activemq.command.ProducerInfo)14 Message (org.apache.activemq.command.Message)13 URI (java.net.URI)9 ActiveMQDestination (org.apache.activemq.command.ActiveMQDestination)8 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)6 RemoveInfo (org.apache.activemq.command.RemoveInfo)5 MockTransport (org.apache.activemq.transport.mock.MockTransport)4 Test (org.junit.Test)4 IOException (java.io.IOException)3 OpenwireArtemisBaseTest (org.apache.activemq.broker.artemiswrapper.OpenwireArtemisBaseTest)3 ActiveMQMessage (org.apache.activemq.command.ActiveMQMessage)3 FailoverTransport (org.apache.activemq.transport.failover.FailoverTransport)2 URISyntaxException (java.net.URISyntaxException)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 MessageNotWriteableException (javax.jms.MessageNotWriteableException)1