Search in sources :

Example 21 with ProducerInfo

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

the class BrokerTest method testQueueBrowserWith2ConsumersBrowseFirst.

/*
    * change the order of the above test
    */
public void testQueueBrowserWith2ConsumersBrowseFirst() throws Exception {
    ActiveMQDestination destination = new ActiveMQQueue("TEST");
    deliveryMode = DeliveryMode.NON_PERSISTENT;
    // Setup a second connection with a queue browser.
    StubConnection connection2 = createConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, destination);
    consumerInfo2.setPrefetchSize(10);
    consumerInfo2.setBrowser(true);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    connection2.request(consumerInfo2);
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ProducerInfo producerInfo = createProducerInfo(sessionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(producerInfo);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    consumerInfo1.setPrefetchSize(10);
    connection1.request(consumerInfo1);
    // Send the messages
    connection1.send(createMessage(producerInfo, destination, deliveryMode));
    connection1.send(createMessage(producerInfo, destination, deliveryMode));
    connection1.send(createMessage(producerInfo, destination, deliveryMode));
    // as the messages are sent async - need to synchronize the last
    // one to ensure they arrive in the order we want
    connection1.request(createMessage(producerInfo, destination, deliveryMode));
    List<Message> messages = new ArrayList<>();
    for (int i = 0; i < 4; i++) {
        Message m1 = receiveMessage(connection1);
        assertNotNull("m1 is null for index: " + i, m1);
        messages.add(m1);
    }
    // no messages present in queue browser as there were no messages when it
    // was created
    assertNoMessagesLeft(connection1);
    assertNoMessagesLeft(connection2);
}
Also used : ConsumerInfo(org.apache.activemq.command.ConsumerInfo) ProducerInfo(org.apache.activemq.command.ProducerInfo) Message(org.apache.activemq.command.Message) ArrayList(java.util.ArrayList) 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 22 with ProducerInfo

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

the class BrokerTest method testQueueOnlyOnceDeliveryWith2Consumers.

public void testQueueOnlyOnceDeliveryWith2Consumers() throws Exception {
    ActiveMQDestination destination = new ActiveMQQueue("TEST");
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ProducerInfo producerInfo = createProducerInfo(sessionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(producerInfo);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    consumerInfo1.setPrefetchSize(1);
    connection1.request(consumerInfo1);
    // Setup a second connection
    StubConnection connection2 = createConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, destination);
    consumerInfo2.setPrefetchSize(1);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    connection2.request(consumerInfo2);
    // Send the messages
    connection1.send(createMessage(producerInfo, destination, deliveryMode));
    connection1.send(createMessage(producerInfo, destination, deliveryMode));
    connection1.send(createMessage(producerInfo, destination, deliveryMode));
    connection1.request(createMessage(producerInfo, destination, deliveryMode));
    for (int i = 0; i < 2; i++) {
        Message m1 = receiveMessage(connection1);
        Message m2 = receiveMessage(connection2);
        assertNotNull("m1 is null for index: " + i, m1);
        assertNotNull("m2 is null for index: " + i, m2);
        assertNotSame(m1.getMessageId(), m2.getMessageId());
        connection1.send(createAck(consumerInfo1, m1, 1, MessageAck.STANDARD_ACK_TYPE));
        connection2.send(createAck(consumerInfo2, m2, 1, MessageAck.STANDARD_ACK_TYPE));
    }
    assertNoMessagesLeft(connection1);
    assertNoMessagesLeft(connection2);
}
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 23 with ProducerInfo

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

the class BrokerTest method testQueueAckRemovesMessage.

public void testQueueAckRemovesMessage() 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);
    Message message1 = createMessage(producerInfo, destination, deliveryMode);
    Message message2 = createMessage(producerInfo, destination, deliveryMode);
    connection.send(message1);
    connection.send(message2);
    // Make sure the message was delivered.
    ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo, destination);
    connection.request(consumerInfo);
    Message m = receiveMessage(connection);
    assertNotNull(m);
    assertEquals(m.getMessageId(), message1.getMessageId());
    ArtemisBrokerWrapper wrapper = (ArtemisBrokerWrapper) broker.getBroker();
    long messageCount = wrapper.getAMQueueMessageCount(destination);
    assertTrue(messageCount == 2);
    connection.send(createAck(consumerInfo, m, 1, MessageAck.DELIVERED_ACK_TYPE));
    messageCount = wrapper.getAMQueueMessageCount(destination);
    assertTrue(messageCount == 2);
    connection.send(createAck(consumerInfo, m, 1, MessageAck.STANDARD_ACK_TYPE));
    // give some time for broker to count down
    Thread.sleep(2000);
    messageCount = wrapper.getAMQueueMessageCount(destination);
    assertTrue(messageCount == 1);
}
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) ArtemisBrokerWrapper(org.apache.activemq.broker.artemiswrapper.ArtemisBrokerWrapper)

Example 24 with ProducerInfo

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

the class BrokerTest method testConsumerPrefetchAndStandardAck.

public void testConsumerPrefetchAndStandardAck() throws Exception {
    destinationType = (byte) 1;
    // 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);
    // Send 3 messages to the broker.
    connection.send(createMessage(producerInfo, destination, deliveryMode));
    connection.send(createMessage(producerInfo, destination, deliveryMode));
    connection.request(createMessage(producerInfo, destination, deliveryMode));
    // Make sure only 1 message was delivered.
    Message m1 = receiveMessage(connection);
    assertNotNull(m1);
    assertNoMessagesLeft(connection);
    // Acknowledge the first message. This should cause the next message to
    // get dispatched.
    connection.send(createAck(consumerInfo, m1, 1, MessageAck.STANDARD_ACK_TYPE));
    Message m2 = receiveMessage(connection);
    assertNotNull(m2);
    connection.send(createAck(consumerInfo, m2, 1, MessageAck.STANDARD_ACK_TYPE));
    Message m3 = receiveMessage(connection);
    assertNotNull(m3);
    connection.send(createAck(consumerInfo, m3, 1, MessageAck.STANDARD_ACK_TYPE));
    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)

Example 25 with ProducerInfo

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

the class BrokerTest method testQueueDispatchedAreRedeliveredOnConsumerClose.

public void testQueueDispatchedAreRedeliveredOnConsumerClose() throws Exception {
    // Setup a first connection
    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);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    consumerInfo1.setPrefetchSize(100);
    connection1.send(consumerInfo1);
    // Send the messages
    connection1.send(createMessage(producerInfo, destination, deliveryMode));
    connection1.send(createMessage(producerInfo, destination, deliveryMode));
    connection1.send(createMessage(producerInfo, destination, deliveryMode));
    connection1.send(createMessage(producerInfo, destination, deliveryMode));
    // Get the messages
    for (int i = 0; i < 4; i++) {
        Message m1 = receiveMessage(connection1);
        assertNotNull(m1);
        assertFalse(m1.isRedelivered());
    }
    // Close the consumer without sending any ACKS.
    connection1.send(closeConsumerInfo(consumerInfo1));
    // Drain any in flight messages..
    while (connection1.getDispatchQueue().poll(0, TimeUnit.MILLISECONDS) != null) {
    }
    // Add the second consumer
    ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo1, destination);
    consumerInfo2.setPrefetchSize(100);
    connection1.send(consumerInfo2);
    // Make sure the messages were re delivered to the 2nd consumer.
    for (int i = 0; i < 4; i++) {
        Message m1 = receiveMessage(connection1);
        assertNotNull(m1);
        assertTrue(m1.isRedelivered());
    }
}
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

ProducerInfo (org.apache.activemq.command.ProducerInfo)95 ConnectionInfo (org.apache.activemq.command.ConnectionInfo)72 ConsumerInfo (org.apache.activemq.command.ConsumerInfo)72 SessionInfo (org.apache.activemq.command.SessionInfo)72 Message (org.apache.activemq.command.Message)69 ActiveMQDestination (org.apache.activemq.command.ActiveMQDestination)42 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)18 XATransactionId (org.apache.activemq.command.XATransactionId)15 StubConnection (org.apache.activemq.broker.StubConnection)14 MessageAck (org.apache.activemq.command.MessageAck)14 ActiveMQTopic (org.apache.activemq.command.ActiveMQTopic)11 DataArrayResponse (org.apache.activemq.command.DataArrayResponse)9 TransactionInfo (org.apache.activemq.command.TransactionInfo)9 LocalTransactionId (org.apache.activemq.command.LocalTransactionId)8 Response (org.apache.activemq.command.Response)5 Test (org.junit.Test)5 IOException (java.io.IOException)4 ActiveMQMessage (org.apache.activemq.command.ActiveMQMessage)4 ActiveMQTextMessage (org.apache.activemq.command.ActiveMQTextMessage)4 TransactionId (org.apache.activemq.command.TransactionId)4