Search in sources :

Example 91 with ConsumerInfo

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

the class MessageExpirationTest method testMessagesInLongTransactionExpire.

public void testMessagesInLongTransactionExpire() throws Exception {
    // Start a producer and consumer
    StubConnection connection = createConnection();
    ConnectionInfo connectionInfo = createConnectionInfo();
    SessionInfo sessionInfo = createSessionInfo(connectionInfo);
    ProducerInfo producerInfo = createProducerInfo(sessionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    connection.send(producerInfo);
    destination = createDestinationInfo(connection, connectionInfo, destinationType);
    ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo, destination);
    consumerInfo.setPrefetchSize(1000);
    connection.send(consumerInfo);
    // Start the tx..
    LocalTransactionId txid = createLocalTransaction(sessionInfo);
    connection.send(createBeginTransaction(connectionInfo, txid));
    // m1 and m3 should not expire.. but the others should.
    Message m1 = createMessage(producerInfo, destination, deliveryMode);
    m1.setTransactionId(txid);
    connection.send(m1);
    Message m = createMessage(producerInfo, destination, deliveryMode, 1000);
    m.setTransactionId(txid);
    connection.send(m);
    Message m3 = createMessage(producerInfo, destination, deliveryMode);
    m3.setTransactionId(txid);
    connection.send(m3);
    m = createMessage(producerInfo, destination, deliveryMode, 1000);
    m.setTransactionId(txid);
    connection.send(m);
    // Sleep before we commit so that the messages expire on the commit
    // list..
    Thread.sleep(1500);
    connection.send(createCommitTransaction1Phase(connectionInfo, txid));
    m = receiveMessage(connection);
    assertNotNull(m);
    assertEquals(m1.getMessageId(), m.getMessageId());
    connection.send(createAck(consumerInfo, m, 1, MessageAck.STANDARD_ACK_TYPE));
    // 2nd message received should be m3.. it should have expired 2nd
    // message sent.
    m = receiveMessage(connection);
    assertNotNull(m);
    assertEquals(m3.getMessageId(), m.getMessageId());
    connection.send(createAck(consumerInfo, m, 1, MessageAck.STANDARD_ACK_TYPE));
    // And there should be no messages left now..
    assertNoMessagesLeft(connection);
    connection.send(closeConnectionInfo(connectionInfo));
}
Also used : ProducerInfo(org.apache.activemq.command.ProducerInfo) ConsumerInfo(org.apache.activemq.command.ConsumerInfo) LocalTransactionId(org.apache.activemq.command.LocalTransactionId) Message(org.apache.activemq.command.Message) SessionInfo(org.apache.activemq.command.SessionInfo) ConnectionInfo(org.apache.activemq.command.ConnectionInfo)

Example 92 with ConsumerInfo

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

the class MessageExpirationTest method testMessagesWaitingForUsageDecreaseExpire.

public void testMessagesWaitingForUsageDecreaseExpire() throws Exception {
    // Start a producer
    final StubConnection connection = createConnection();
    ConnectionInfo connectionInfo = createConnectionInfo();
    SessionInfo sessionInfo = createSessionInfo(connectionInfo);
    final ProducerInfo producerInfo = createProducerInfo(sessionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    connection.send(producerInfo);
    // Start a consumer..
    final StubConnection connection2 = createConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    destination = createDestinationInfo(connection2, connectionInfo2, destinationType);
    ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, destination);
    consumerInfo2.setPrefetchSize(1);
    connection2.request(consumerInfo2);
    // Reduce the limit so that only 1 message can flow through the broker
    // at a time.
    broker.getSystemUsage().getMemoryUsage().setLimit(1);
    final Message m1 = createMessage(producerInfo, destination, deliveryMode);
    final Message m2 = createMessage(producerInfo, destination, deliveryMode, 1000);
    final Message m3 = createMessage(producerInfo, destination, deliveryMode);
    final Message m4 = createMessage(producerInfo, destination, deliveryMode, 1000);
    // Produce in an async thread since the producer will be getting blocked
    // by the usage manager..
    new Thread() {

        @Override
        public void run() {
            // m1 and m3 should not expire.. but the others should.
            try {
                connection.send(m1);
                connection.send(m2);
                connection.send(m3);
                connection.send(m4);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }.start();
    // Make sure only 1 message was delivered due to prefetch == 1
    Message m = receiveMessage(connection2);
    assertNotNull(m);
    assertEquals(m1.getMessageId(), m.getMessageId());
    assertNoMessagesLeft(connection);
    // Sleep before we ack so that the messages expire on the usage manager
    Thread.sleep(1500);
    connection2.send(createAck(consumerInfo2, m, 1, MessageAck.STANDARD_ACK_TYPE));
    // 2nd message received should be m3.. it should have expired 2nd
    // message sent.
    m = receiveMessage(connection2);
    assertNotNull(m);
    assertEquals(m3.getMessageId(), m.getMessageId());
    // Sleep before we ack so that the messages expire on the usage manager
    Thread.sleep(1500);
    connection2.send(createAck(consumerInfo2, m, 1, MessageAck.STANDARD_ACK_TYPE));
    // And there should be no messages left now..
    assertNoMessagesLeft(connection2);
    connection.send(closeConnectionInfo(connectionInfo));
    connection.send(closeConnectionInfo(connectionInfo2));
}
Also used : ProducerInfo(org.apache.activemq.command.ProducerInfo) ConsumerInfo(org.apache.activemq.command.ConsumerInfo) Message(org.apache.activemq.command.Message) SessionInfo(org.apache.activemq.command.SessionInfo) ConnectionInfo(org.apache.activemq.command.ConnectionInfo)

Example 93 with ConsumerInfo

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

the class RecoveryBrokerTest method testQueueNonPersistentMessagesLostOnRestart.

public void testQueueNonPersistentMessagesLostOnRestart() throws Exception {
    ActiveMQDestination destination = new ActiveMQQueue("TEST");
    // Setup the producer and send the message.
    StubConnection connection = createConnection();
    ConnectionInfo connectionInfo = createConnectionInfo();
    SessionInfo sessionInfo = createSessionInfo(connectionInfo);
    ProducerInfo producerInfo = createProducerInfo(sessionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    connection.send(producerInfo);
    Message message = createMessage(producerInfo, destination);
    message.setPersistent(false);
    connection.send(message);
    // restart the broker.
    restartBroker();
    // Setup the consumer and receive the message.
    connection = createConnection();
    connectionInfo = createConnectionInfo();
    sessionInfo = createSessionInfo(connectionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo, destination);
    connection.send(consumerInfo);
    // Message should have been dropped due to broker restart.
    assertNoMessagesLeft(connection);
}
Also used : ProducerInfo(org.apache.activemq.command.ProducerInfo) ConsumerInfo(org.apache.activemq.command.ConsumerInfo) Message(org.apache.activemq.command.Message) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) SessionInfo(org.apache.activemq.command.SessionInfo) ConnectionInfo(org.apache.activemq.command.ConnectionInfo) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination)

Example 94 with ConsumerInfo

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

the class RecoveryBrokerTest method XtestWildCardSubscriptionPreservedOnRestart.

/**
 * Used to verify that after a broker restart durable subscriptions that use
 * wild cards are still wild card subscription after broker restart.
 *
 * @throws Exception
 */
// need to revist!!!
public void XtestWildCardSubscriptionPreservedOnRestart() throws Exception {
    ActiveMQDestination dest1 = new ActiveMQTopic("TEST.A");
    ActiveMQDestination dest2 = new ActiveMQTopic("TEST.B");
    ActiveMQDestination dest3 = new ActiveMQTopic("TEST.C");
    ActiveMQDestination wildDest = new ActiveMQTopic("TEST.>");
    ArrayList<MessageId> sentBeforeRestart = new ArrayList<>();
    ArrayList<MessageId> sentBeforeCreateConsumer = new ArrayList<>();
    ArrayList<MessageId> sentAfterCreateConsumer = new ArrayList<>();
    // Setup a first connection
    {
        StubConnection connection1 = createConnection();
        ConnectionInfo connectionInfo1 = createConnectionInfo();
        connectionInfo1.setClientId("A");
        SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
        ProducerInfo producerInfo1 = createProducerInfo(sessionInfo1);
        connection1.send(connectionInfo1);
        connection1.send(sessionInfo1);
        connection1.send(producerInfo1);
        // Create the durable subscription.
        ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, wildDest);
        consumerInfo1.setSubscriptionName("test");
        consumerInfo1.setPrefetchSize(100);
        connection1.send(consumerInfo1);
        // Close the subscription.
        connection1.send(closeConsumerInfo(consumerInfo1));
        // Send the messages
        for (int i = 0; i < 4; i++) {
            Message m = createMessage(producerInfo1, dest1, DeliveryMode.PERSISTENT);
            connection1.send(m);
            sentBeforeRestart.add(m.getMessageId());
        }
        connection1.request(closeConnectionInfo(connectionInfo1));
        connection1.stop();
    }
    // Restart the broker.
    restartBroker();
    // Get a connection to the new broker.
    {
        StubConnection connection2 = createConnection();
        ConnectionInfo connectionInfo2 = createConnectionInfo();
        connectionInfo2.setClientId("A");
        SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
        connection2.send(connectionInfo2);
        connection2.send(sessionInfo2);
        ProducerInfo producerInfo2 = createProducerInfo(sessionInfo2);
        connection2.send(producerInfo2);
        // Send messages before the durable subscription is re-activated.
        for (int i = 0; i < 4; i++) {
            Message m = createMessage(producerInfo2, dest2, DeliveryMode.PERSISTENT);
            connection2.send(m);
            sentBeforeCreateConsumer.add(m.getMessageId());
        }
        // Re-open the subscription.
        ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, wildDest);
        consumerInfo2.setSubscriptionName("test");
        consumerInfo2.setPrefetchSize(100);
        connection2.send(consumerInfo2);
        // Send messages after the subscription is activated.
        for (int i = 0; i < 4; i++) {
            Message m = createMessage(producerInfo2, dest3, DeliveryMode.PERSISTENT);
            connection2.send(m);
            sentAfterCreateConsumer.add(m.getMessageId());
        }
        // We should get the recovered messages...
        for (int i = 0; i < 4; i++) {
            Message m2 = receiveMessage(connection2);
            assertNotNull("Recovered message missing: " + i, m2);
            assertEquals(sentBeforeRestart.get(i), m2.getMessageId());
        }
        // reactivated.
        for (int i = 0; i < 4; i++) {
            Message m2 = receiveMessage(connection2);
            assertNotNull("Before activated message missing: " + i, m2);
            assertEquals(sentBeforeCreateConsumer.get(i), m2.getMessageId());
        }
        // reactivated.
        for (int i = 0; i < 4; i++) {
            Message m2 = receiveMessage(connection2);
            assertNotNull("After activated message missing: " + i, m2);
            assertEquals("" + i, sentAfterCreateConsumer.get(i), m2.getMessageId());
        }
        assertNoMessagesLeft(connection2);
    }
}
Also used : ActiveMQTopic(org.apache.activemq.command.ActiveMQTopic) ProducerInfo(org.apache.activemq.command.ProducerInfo) ConsumerInfo(org.apache.activemq.command.ConsumerInfo) Message(org.apache.activemq.command.Message) ArrayList(java.util.ArrayList) SessionInfo(org.apache.activemq.command.SessionInfo) ConnectionInfo(org.apache.activemq.command.ConnectionInfo) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination) MessageId(org.apache.activemq.command.MessageId)

Example 95 with ConsumerInfo

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

the class XARecoveryBrokerTest method testQueuePersistentCommittedMessagesNotLostOnRestart.

public void testQueuePersistentCommittedMessagesNotLostOnRestart() throws Exception {
    ActiveMQDestination destination = createDestination();
    // Setup the producer and send the message.
    StubConnection connection = createConnection();
    ConnectionInfo connectionInfo = createConnectionInfo();
    SessionInfo sessionInfo = createSessionInfo(connectionInfo);
    ProducerInfo producerInfo = createProducerInfo(sessionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    connection.send(producerInfo);
    // Begin the transaction.
    XATransactionId txid = createXATransaction(sessionInfo);
    connection.send(createBeginTransaction(connectionInfo, txid));
    for (int i = 0; i < 4; i++) {
        Message message = createMessage(producerInfo, destination);
        message.setPersistent(true);
        message.setTransactionId(txid);
        connection.send(message);
    }
    // Commit
    connection.send(createCommitTransaction1Phase(connectionInfo, txid));
    connection.request(closeConnectionInfo(connectionInfo));
    // restart the broker.
    restartBroker();
    // Setup the consumer and receive the message.
    connection = createConnection();
    connectionInfo = createConnectionInfo();
    sessionInfo = createSessionInfo(connectionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo, destination);
    connection.send(consumerInfo);
    for (int i = 0; i < expectedMessageCount(4, destination); i++) {
        Message m = receiveMessage(connection);
        assertNotNull(m);
    }
    assertNoMessagesLeft(connection);
}
Also used : ProducerInfo(org.apache.activemq.command.ProducerInfo) XATransactionId(org.apache.activemq.command.XATransactionId) ConsumerInfo(org.apache.activemq.command.ConsumerInfo) Message(org.apache.activemq.command.Message) SessionInfo(org.apache.activemq.command.SessionInfo) ConnectionInfo(org.apache.activemq.command.ConnectionInfo) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination)

Aggregations

ConsumerInfo (org.apache.activemq.command.ConsumerInfo)115 Message (org.apache.activemq.command.Message)77 ConnectionInfo (org.apache.activemq.command.ConnectionInfo)76 SessionInfo (org.apache.activemq.command.SessionInfo)76 ProducerInfo (org.apache.activemq.command.ProducerInfo)72 ActiveMQDestination (org.apache.activemq.command.ActiveMQDestination)45 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)25 StubConnection (org.apache.activemq.broker.StubConnection)17 MessageAck (org.apache.activemq.command.MessageAck)17 XATransactionId (org.apache.activemq.command.XATransactionId)15 ActiveMQTopic (org.apache.activemq.command.ActiveMQTopic)12 Test (org.junit.Test)12 DataArrayResponse (org.apache.activemq.command.DataArrayResponse)9 TransactionInfo (org.apache.activemq.command.TransactionInfo)9 ActiveMQTextMessage (org.apache.activemq.command.ActiveMQTextMessage)8 LocalTransactionId (org.apache.activemq.command.LocalTransactionId)8 RemoveInfo (org.apache.activemq.command.RemoveInfo)8 DestinationStatistics (org.apache.activemq.broker.region.DestinationStatistics)7 Response (org.apache.activemq.command.Response)7 MessageReference (org.apache.activemq.broker.region.MessageReference)6