Search in sources :

Example 16 with Message

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

the class BrokerTest method testWildcardConsume.

public void testWildcardConsume() throws Exception {
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ProducerInfo producerInfo1 = createProducerInfo(sessionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(producerInfo1);
    // setup the wildcard consumer.
    ActiveMQDestination compositeDestination = ActiveMQDestination.createDestination("WILD.*.TEST", destinationType);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, compositeDestination);
    consumerInfo1.setPrefetchSize(100);
    connection1.send(consumerInfo1);
    // These two message should NOT match the wild card.
    connection1.send(createMessage(producerInfo1, ActiveMQDestination.createDestination("WILD.CARD", destinationType), deliveryMode));
    connection1.send(createMessage(producerInfo1, ActiveMQDestination.createDestination("WILD.TEST", destinationType), deliveryMode));
    // These two message should match the wild card.
    ActiveMQDestination d1 = ActiveMQDestination.createDestination("WILD.CARD.TEST", destinationType);
    connection1.send(createMessage(producerInfo1, d1, deliveryMode));
    Message m = receiveMessage(connection1);
    assertNotNull(m);
    assertEquals(d1, m.getDestination());
    ActiveMQDestination d2 = ActiveMQDestination.createDestination("WILD.FOO.TEST", destinationType);
    connection1.request(createMessage(producerInfo1, d2, deliveryMode));
    m = receiveMessage(connection1);
    assertNotNull(m);
    assertEquals(d2, m.getDestination());
    assertNoMessagesLeft(connection1);
    connection1.send(closeConnectionInfo(connectionInfo1));
}
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) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination)

Example 17 with Message

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

the class BrokerTest method testConsumerPrefetchAtTwo.

public void testConsumerPrefetchAtTwo() 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(2);
    connection.send(consumerInfo);
    // Send 3 messages to the broker.
    connection.send(createMessage(producerInfo, destination, deliveryMode));
    connection.send(createMessage(producerInfo, destination, deliveryMode));
    connection.send(createMessage(producerInfo, destination, deliveryMode));
    // Make sure only 1 message was delivered.
    Message m = receiveMessage(connection);
    assertNotNull(m);
    m = receiveMessage(connection);
    assertNotNull(m);
    assertNoMessagesLeft(connection);
}
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 18 with Message

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

the class BrokerTest method testQueueBrowseMessages.

public void testQueueBrowseMessages() 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);
    connection.send(createMessage(producerInfo, destination, deliveryMode));
    connection.send(createMessage(producerInfo, destination, deliveryMode));
    connection.send(createMessage(producerInfo, destination, deliveryMode));
    connection.send(createMessage(producerInfo, destination, deliveryMode));
    // Use selector to skip first message.
    ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo, destination);
    consumerInfo.setBrowser(true);
    connection.send(consumerInfo);
    for (int i = 0; i < 4; i++) {
        Message m = receiveMessage(connection);
        assertNotNull(m);
        connection.send(createAck(consumerInfo, m, 1, MessageAck.DELIVERED_ACK_TYPE));
    }
    assertNoMessagesLeft(connection);
}
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 19 with Message

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

the class BrokerTest method testGroupedMessagesDeliveredToOnlyOneConsumer.

public void testGroupedMessagesDeliveredToOnlyOneConsumer() 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.send(consumerInfo1);
    // Send the messages.
    for (int i = 0; i < 4; i++) {
        Message message = createMessage(producerInfo, destination, deliveryMode);
        message.setGroupID("TEST-GROUP");
        message.setGroupSequence(i + 1);
        connection1.request(message);
    }
    // Setup a second connection
    StubConnection connection2 = createConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, destination);
    consumerInfo2.setPrefetchSize(1);
    connection2.send(consumerInfo2);
    // the first 3
    for (int i = 0; i < 3; i++) {
        Message m1 = receiveMessage(connection1);
        assertNotNull("m1 is null for index: " + i, m1);
        connection1.send(createAck(consumerInfo1, m1, 1, MessageAck.STANDARD_ACK_TYPE));
    }
    // Close the first consumer.
    connection1.request(closeConsumerInfo(consumerInfo1));
    // The last messages should now go the the second consumer.
    for (int i = 0; i < 1; i++) {
        Message m1 = receiveMessage(connection2);
        assertNotNull("m1 is null for index: " + i, m1);
        connection2.request(createAck(consumerInfo2, m1, 1, MessageAck.STANDARD_ACK_TYPE));
    }
    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 20 with Message

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

the class BrokerTest method testTransactedAckWithPrefetchOfOne.

public void testTransactedAckWithPrefetchOfOne() throws Exception {
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ProducerInfo producerInfo1 = createProducerInfo(sessionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(producerInfo1);
    destination = createDestinationInfo(connection1, connectionInfo1, destinationType);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    consumerInfo1.setPrefetchSize(1);
    connection1.send(consumerInfo1);
    // Send the messages
    for (int i = 0; i < 4; i++) {
        Message message = createMessage(producerInfo1, destination, deliveryMode);
        connection1.send(message);
    }
    // Now get the messages.
    for (int i = 0; i < 4; i++) {
        // Begin the transaction.
        LocalTransactionId txid = createLocalTransaction(sessionInfo1);
        connection1.send(createBeginTransaction(connectionInfo1, txid));
        Message m1 = receiveMessage(connection1);
        assertNotNull(m1);
        MessageAck ack = createAck(consumerInfo1, m1, 1, MessageAck.STANDARD_ACK_TYPE);
        ack.setTransactionId(txid);
        connection1.send(ack);
        // Commit the transaction.
        connection1.send(createCommitTransaction1Phase(connectionInfo1, txid));
    }
    assertNoMessagesLeft(connection1);
}
Also used : ProducerInfo(org.apache.activemq.command.ProducerInfo) ConsumerInfo(org.apache.activemq.command.ConsumerInfo) Message(org.apache.activemq.command.Message) LocalTransactionId(org.apache.activemq.command.LocalTransactionId) SessionInfo(org.apache.activemq.command.SessionInfo) MessageAck(org.apache.activemq.command.MessageAck) ConnectionInfo(org.apache.activemq.command.ConnectionInfo)

Aggregations

Message (org.apache.activemq.command.Message)102 ConsumerInfo (org.apache.activemq.command.ConsumerInfo)77 ConnectionInfo (org.apache.activemq.command.ConnectionInfo)71 SessionInfo (org.apache.activemq.command.SessionInfo)71 ProducerInfo (org.apache.activemq.command.ProducerInfo)69 ActiveMQDestination (org.apache.activemq.command.ActiveMQDestination)46 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)24 MessageAck (org.apache.activemq.command.MessageAck)15 XATransactionId (org.apache.activemq.command.XATransactionId)15 StubConnection (org.apache.activemq.broker.StubConnection)14 ActiveMQTextMessage (org.apache.activemq.command.ActiveMQTextMessage)13 ActiveMQTopic (org.apache.activemq.command.ActiveMQTopic)11 DataArrayResponse (org.apache.activemq.command.DataArrayResponse)9 TransactionInfo (org.apache.activemq.command.TransactionInfo)9 ActiveMQMessage (org.apache.activemq.command.ActiveMQMessage)8 LocalTransactionId (org.apache.activemq.command.LocalTransactionId)8 Response (org.apache.activemq.command.Response)7 Test (org.junit.Test)6 AtomicLong (java.util.concurrent.atomic.AtomicLong)5 DestinationStatistics (org.apache.activemq.broker.region.DestinationStatistics)5