Search in sources :

Example 76 with ConnectionInfo

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

the class BrokerTest method testExclusiveQueueDeliversToOnlyOneConsumer.

public void testExclusiveQueueDeliversToOnlyOneConsumer() 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);
    consumerInfo1.setExclusive(true);
    connection1.send(consumerInfo1);
    // Send a message.. this should make consumer 1 the exclusive owner.
    connection1.request(createMessage(producerInfo, destination, deliveryMode));
    // Setup a second connection
    StubConnection connection2 = createConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, destination);
    consumerInfo2.setPrefetchSize(1);
    consumerInfo2.setExclusive(true);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    connection2.request(consumerInfo2);
    // Second message should go to consumer 1 even though consumer 2 is
    // ready
    // for dispatch.
    connection1.send(createMessage(producerInfo, destination, deliveryMode));
    connection1.send(createMessage(producerInfo, destination, deliveryMode));
    // Acknowledge the first 2 messages
    for (int i = 0; i < 2; i++) {
        Message m1 = receiveMessage(connection1);
        assertNotNull(m1);
        connection1.send(createAck(consumerInfo1, m1, 1, MessageAck.STANDARD_ACK_TYPE));
    }
    // Close the first consumer.
    connection1.send(closeConsumerInfo(consumerInfo1));
    // The last two messages should now go the the second consumer.
    connection1.send(createMessage(producerInfo, destination, deliveryMode));
    for (int i = 0; i < 2; i++) {
        Message m1 = receiveMessage(connection2);
        assertNotNull(m1);
        connection2.send(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 77 with ConnectionInfo

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

the class BrokerTest method testCompositeConsume.

public void testCompositeConsume() 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 composite consumer.
    ActiveMQDestination compositeDestination = ActiveMQDestination.createDestination("A,B", destinationType);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, compositeDestination);
    consumerInfo1.setRetroactive(true);
    consumerInfo1.setPrefetchSize(100);
    connection1.send(consumerInfo1);
    // Publish to the two destinations
    ActiveMQDestination destinationA = ActiveMQDestination.createDestination("A", destinationType);
    ActiveMQDestination destinationB = ActiveMQDestination.createDestination("B", destinationType);
    // Send a message to each destination .
    connection1.send(createMessage(producerInfo1, destinationA, deliveryMode));
    connection1.send(createMessage(producerInfo1, destinationB, deliveryMode));
    // The consumer should get both messages.
    for (int i = 0; i < 2; i++) {
        Message m1 = receiveMessage(connection1);
        assertNotNull(m1);
    }
    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 78 with ConnectionInfo

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

the class BrokerTest method testQueueTransactedAck.

public void testQueueTransactedAck() 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(100);
    connection1.send(consumerInfo1);
    // Send the messages
    for (int i = 0; i < 4; i++) {
        Message message = createMessage(producerInfo1, destination, deliveryMode);
        connection1.send(message);
    }
    // Begin the transaction.
    LocalTransactionId txid = createLocalTransaction(sessionInfo1);
    connection1.send(createBeginTransaction(connectionInfo1, txid));
    // Acknowledge the first 2 messages.
    for (int i = 0; i < 2; i++) {
        Message m1 = receiveMessage(connection1);
        assertNotNull("m1 is null for index: " + i, m1);
        MessageAck ack = createAck(consumerInfo1, m1, 1, MessageAck.STANDARD_ACK_TYPE);
        ack.setTransactionId(txid);
        connection1.request(ack);
    }
    // Commit the transaction.
    connection1.send(createCommitTransaction1Phase(connectionInfo1, txid));
    // due to async tx operations, we need some time for message count to go down
    Thread.sleep(1000);
    ArtemisBrokerWrapper wrapper = (ArtemisBrokerWrapper) broker.getBroker();
    long messageCount = wrapper.getAMQueueMessageCount(destination);
    // The queue should now only have the remaining 2 messages
    assertEquals(2, messageCount);
}
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) ArtemisBrokerWrapper(org.apache.activemq.broker.artemiswrapper.ArtemisBrokerWrapper)

Example 79 with ConnectionInfo

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

the class BrokerTest method testTopicNoLocal.

// https://issues.apache.org/jira/browse/ARTEMIS-402
public void testTopicNoLocal() throws Exception {
    ActiveMQDestination destination = new ActiveMQTopic("TEST");
    // 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);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    consumerInfo1.setRetroactive(true);
    consumerInfo1.setPrefetchSize(100);
    consumerInfo1.setNoLocal(true);
    connection1.send(consumerInfo1);
    // Setup a second connection
    StubConnection connection2 = createConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    ProducerInfo producerInfo2 = createProducerInfo(sessionInfo2);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    connection2.send(producerInfo2);
    ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, destination);
    consumerInfo2.setRetroactive(true);
    consumerInfo2.setPrefetchSize(100);
    consumerInfo2.setNoLocal(true);
    connection2.send(consumerInfo2);
    // Send the messages
    connection1.send(createMessage(producerInfo1, destination, deliveryMode));
    connection1.send(createMessage(producerInfo1, destination, deliveryMode));
    connection1.send(createMessage(producerInfo1, destination, deliveryMode));
    connection1.send(createMessage(producerInfo1, destination, deliveryMode));
    // The 2nd connection should get the messages.
    for (int i = 0; i < 4; i++) {
        Message m1 = receiveMessage(connection2);
        assertNotNull(m1);
    }
    // Send a message with the 2nd connection
    Message message = createMessage(producerInfo2, destination, deliveryMode);
    connection2.send(message);
    // The first connection should not see the initial 4 local messages sent
    // but should
    // see the messages from connection 2.
    Message m = receiveMessage(connection1);
    assertNotNull(m);
    assertEquals(message.getMessageId(), m.getMessageId());
    assertNoMessagesLeft(connection1);
    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 80 with ConnectionInfo

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

the class BrokerTest method testSelectorSkipsMessages.

public void testSelectorSkipsMessages() 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.setSelector("JMSType='last'");
    connection.send(consumerInfo);
    Message message1 = createMessage(producerInfo, destination, deliveryMode);
    message1.setType("first");
    Message message2 = createMessage(producerInfo, destination, deliveryMode);
    message2.setType("last");
    connection.send(message1);
    connection.send(message2);
    // Use selector to skip first message.
    Message m = receiveMessage(connection);
    assertNotNull(m);
    assertEquals(m.getMessageId(), message2.getMessageId());
    connection.send(createAck(consumerInfo, m, 1, MessageAck.STANDARD_ACK_TYPE));
    connection.send(closeConsumerInfo(consumerInfo));
    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)

Aggregations

ConnectionInfo (org.apache.activemq.command.ConnectionInfo)110 SessionInfo (org.apache.activemq.command.SessionInfo)77 ConsumerInfo (org.apache.activemq.command.ConsumerInfo)76 ProducerInfo (org.apache.activemq.command.ProducerInfo)72 Message (org.apache.activemq.command.Message)71 ActiveMQDestination (org.apache.activemq.command.ActiveMQDestination)44 StubConnection (org.apache.activemq.broker.StubConnection)18 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)18 MessageAck (org.apache.activemq.command.MessageAck)15 XATransactionId (org.apache.activemq.command.XATransactionId)15 ActiveMQTopic (org.apache.activemq.command.ActiveMQTopic)12 DataArrayResponse (org.apache.activemq.command.DataArrayResponse)10 TransactionInfo (org.apache.activemq.command.TransactionInfo)9 LocalTransactionId (org.apache.activemq.command.LocalTransactionId)8 ConnectionId (org.apache.activemq.command.ConnectionId)6 RemoveInfo (org.apache.activemq.command.RemoveInfo)6 IOException (java.io.IOException)5 Response (org.apache.activemq.command.Response)5 Test (org.junit.Test)5 ConnectionContext (org.apache.activemq.broker.ConnectionContext)4