Search in sources :

Example 86 with ConsumerInfo

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

the class BrokerTest method testTopicDurableSubscriptionCanBeRestored.

public void testTopicDurableSubscriptionCanBeRestored() throws Exception {
    ActiveMQDestination destination = new ActiveMQTopic("TEST");
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    connectionInfo1.setClientId("clientid1");
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ProducerInfo producerInfo1 = createProducerInfo(sessionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(producerInfo1);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    consumerInfo1.setPrefetchSize(100);
    consumerInfo1.setSubscriptionName("test");
    connection1.send(consumerInfo1);
    // Send the messages
    connection1.send(createMessage(producerInfo1, destination, DeliveryMode.PERSISTENT));
    connection1.send(createMessage(producerInfo1, destination, DeliveryMode.PERSISTENT));
    connection1.send(createMessage(producerInfo1, destination, DeliveryMode.PERSISTENT));
    connection1.request(createMessage(producerInfo1, destination, DeliveryMode.PERSISTENT));
    // Get the messages
    Message m = null;
    for (int i = 0; i < 2; i++) {
        m = receiveMessage(connection1);
        assertNotNull(m);
    }
    // Ack the last message.
    connection1.send(createAck(consumerInfo1, m, 2, MessageAck.STANDARD_ACK_TYPE));
    // Close the connection.
    connection1.request(closeConnectionInfo(connectionInfo1));
    connection1.stop();
    // Setup a second connection
    StubConnection connection2 = createConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    connectionInfo2.setClientId("clientid1");
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, destination);
    consumerInfo2.setPrefetchSize(100);
    consumerInfo2.setSubscriptionName("test");
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    connection2.send(consumerInfo2);
    // Get the rest of the messages
    for (int i = 0; i < 2; i++) {
        Message m1 = receiveMessage(connection2);
        assertNotNull("m1 is null for index: " + i, m1);
    }
    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) SessionInfo(org.apache.activemq.command.SessionInfo) ConnectionInfo(org.apache.activemq.command.ConnectionInfo) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination)

Example 87 with ConsumerInfo

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

the class ConcurrentConnectSimulationTest method testConcurrentConnection.

/*
    * simulate failover and retry of connection before broker has killed connection
    * which appears as a concurrent connect request to the broker
    * see: https://issues.apache.org/activemq/browse/AMQ-2241
    */
public void testConcurrentConnection() throws Exception {
    StubConnection connection1 = createConnection();
    StubConnection connection2 = createConnection();
    // reuse same connection info
    ConnectionInfo connectionInfo = createConnectionInfo();
    connection1.request(connectionInfo);
    connection2.request(connectionInfo);
    // second one should win out, verify using consumer on default session (watchAdvisories)
    ConsumerId consumerId = new ConsumerId(new SessionId(connectionInfo.getConnectionId(), -1), 1);
    ConsumerInfo consumerInfo = new ConsumerInfo(consumerId);
    consumerInfo.setDestination(AdvisorySupport.TEMP_DESTINATION_COMPOSITE_ADVISORY_TOPIC);
    connection2.request(consumerInfo);
}
Also used : ConsumerInfo(org.apache.activemq.command.ConsumerInfo) ConsumerId(org.apache.activemq.command.ConsumerId) ConnectionInfo(org.apache.activemq.command.ConnectionInfo) SessionId(org.apache.activemq.command.SessionId)

Example 88 with ConsumerInfo

use of org.apache.activemq.command.ConsumerInfo 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 89 with ConsumerInfo

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

the class DoubleSubscriptionTest method testDoubleSubscription.

public void testDoubleSubscription() throws Exception {
    // Start a normal consumer on the remote broker
    StubConnection connection1 = createRemoteConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.request(consumerInfo1);
    // Start a normal producer on a remote broker
    StubConnection connection2 = createRemoteConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    ProducerInfo producerInfo2 = createProducerInfo(sessionInfo2);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    connection2.request(producerInfo2);
    // Send a message to make sure the basics are working
    connection2.request(createMessage(producerInfo2, destination, DeliveryMode.PERSISTENT));
    Message m1 = receiveMessage(connection1);
    assertNotNull(m1);
    assertNoMessagesLeft(connection1);
    connection1.send(createAck(consumerInfo1, m1, 1, MessageAck.STANDARD_ACK_TYPE));
    // Send a message to sit on the broker while we mess with it
    connection2.request(createMessage(producerInfo2, destination, DeliveryMode.PERSISTENT));
    // Now we're going to resend the same consumer commands again and see if
    // the broker
    // can handle it.
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.request(consumerInfo1);
    // After this there should be 2 messages on the broker...
    connection2.request(createMessage(producerInfo2, destination, DeliveryMode.PERSISTENT));
    // ... let's start a fresh consumer...
    connection1.stop();
    StubConnection connection3 = createRemoteConnection();
    ConnectionInfo connectionInfo3 = createConnectionInfo();
    SessionInfo sessionInfo3 = createSessionInfo(connectionInfo3);
    ConsumerInfo consumerInfo3 = createConsumerInfo(sessionInfo3, destination);
    connection3.send(connectionInfo3);
    connection3.send(sessionInfo3);
    connection3.request(consumerInfo3);
    // ... and then grab the 2 that should be there.
    assertNotNull(receiveMessage(connection3));
    assertNotNull(receiveMessage(connection3));
    assertNoMessagesLeft(connection3);
}
Also used : ConsumerInfo(org.apache.activemq.command.ConsumerInfo) ProducerInfo(org.apache.activemq.command.ProducerInfo) Message(org.apache.activemq.command.Message) SessionInfo(org.apache.activemq.command.SessionInfo) ConnectionInfo(org.apache.activemq.command.ConnectionInfo)

Example 90 with ConsumerInfo

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

the class MessageExpirationTest method testMessagesInSubscriptionPendingListExpire.

public void testMessagesInSubscriptionPendingListExpire() 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(1);
    connection.send(consumerInfo);
    // m1 and m3 should not expire.. but the others should.
    Message m1 = createMessage(producerInfo, destination, deliveryMode);
    connection.send(m1);
    connection.send(createMessage(producerInfo, destination, deliveryMode, 1000));
    Message m3 = createMessage(producerInfo, destination, deliveryMode);
    connection.send(m3);
    connection.send(createMessage(producerInfo, destination, deliveryMode, 1000));
    // Make sure only 1 message was delivered due to prefetch == 1
    Message m = receiveMessage(connection);
    assertNotNull(m);
    assertEquals(m1.getMessageId(), m.getMessageId());
    assertNoMessagesLeft(connection);
    // Sleep before we ack so that the messages expire on the pending list..
    Thread.sleep(1500);
    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) Message(org.apache.activemq.command.Message) SessionInfo(org.apache.activemq.command.SessionInfo) ConnectionInfo(org.apache.activemq.command.ConnectionInfo)

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