Search in sources :

Example 71 with ConnectionInfo

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

the class AdvisoryBrokerTest method testProducerAdvisoriesReplayed.

public void testProducerAdvisoriesReplayed() throws Exception {
    ActiveMQDestination queue = new ActiveMQQueue("test");
    ActiveMQDestination destination = AdvisorySupport.getProducerAdvisoryTopic(queue);
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    // Setup a producer.
    StubConnection connection2 = createConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    ProducerInfo producerInfo2 = createProducerInfo(sessionInfo2);
    producerInfo2.setDestination(queue);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    connection2.send(producerInfo2);
    // Create the advisory consumer.. it should see the previous producer
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    consumerInfo1.setPrefetchSize(100);
    connection1.send(consumerInfo1);
    Message m1 = receiveMessage(connection1);
    assertNotNull(m1);
    assertNotNull(m1.getDataStructure());
    assertEquals(((ProducerInfo) m1.getDataStructure()).getProducerId(), producerInfo2.getProducerId());
    // Close the second connection.
    connection2.request(closeConnectionInfo(connectionInfo2));
    connection2.stop();
    // We should get an advisory of the producer closing
    m1 = receiveMessage(connection1);
    assertNotNull(m1);
    assertNotNull(m1.getDataStructure());
    RemoveInfo r = (RemoveInfo) m1.getDataStructure();
    assertEquals(r.getObjectId(), producerInfo2.getProducerId());
    assertNoMessagesLeft(connection2);
}
Also used : ProducerInfo(org.apache.activemq.command.ProducerInfo) ConsumerInfo(org.apache.activemq.command.ConsumerInfo) Message(org.apache.activemq.command.Message) RemoveInfo(org.apache.activemq.command.RemoveInfo) StubConnection(org.apache.activemq.broker.StubConnection) 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 72 with ConnectionInfo

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

the class AdvisoryBrokerTest method testConsumerAdvisoriesReplayed.

public void testConsumerAdvisoriesReplayed() throws Exception {
    ActiveMQDestination queue = new ActiveMQQueue("test");
    ActiveMQDestination destination = AdvisorySupport.getConsumerAdvisoryTopic(queue);
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    // Setup a second consumer.
    StubConnection connection2 = createConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, queue);
    consumerInfo2.setPrefetchSize(100);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    connection2.send(consumerInfo2);
    // We should get an advisory of the previous consumer.
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    consumerInfo1.setPrefetchSize(100);
    connection1.send(consumerInfo1);
    Message m1 = receiveMessage(connection1);
    assertNotNull(m1);
    assertNotNull(m1.getDataStructure());
    assertEquals(((ConsumerInfo) m1.getDataStructure()).getConsumerId(), consumerInfo2.getConsumerId());
    // Close the second connection.
    connection2.request(closeConnectionInfo(connectionInfo2));
    connection2.stop();
    // We should get an advisory of the consumer closing
    m1 = receiveMessage(connection1);
    assertNotNull(m1);
    assertNotNull(m1.getDataStructure());
    RemoveInfo r = (RemoveInfo) m1.getDataStructure();
    assertEquals(r.getObjectId(), consumerInfo2.getConsumerId());
    assertNoMessagesLeft(connection2);
}
Also used : ConsumerInfo(org.apache.activemq.command.ConsumerInfo) Message(org.apache.activemq.command.Message) RemoveInfo(org.apache.activemq.command.RemoveInfo) StubConnection(org.apache.activemq.broker.StubConnection) 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 73 with ConnectionInfo

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

the class BrokerTest method testAddConsumerThenSend.

public void testAddConsumerThenSend() 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);
    connection.send(consumerInfo);
    connection.send(createMessage(producerInfo, destination, deliveryMode));
    // Make sure the message was delivered.
    Message m = receiveMessage(connection);
    assertNotNull(m);
}
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 74 with ConnectionInfo

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

the class BrokerTest method testTopicRetroactiveConsumerSeeMessagesBeforeCreation.

// https://issues.apache.org/jira/browse/ARTEMIS-402
public void testTopicRetroactiveConsumerSeeMessagesBeforeCreation() throws Exception {
    ActiveMQDestination destination = new ActiveMQTopic("TEST");
    // 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);
    // Send the messages
    Message m = createMessage(producerInfo1, destination, deliveryMode);
    connection1.send(m);
    // Create the durable subscription.
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    if (durableConsumer) {
        consumerInfo1.setSubscriptionName("test");
    }
    consumerInfo1.setPrefetchSize(100);
    consumerInfo1.setRetroactive(true);
    connection1.send(consumerInfo1);
    connection1.send(createMessage(producerInfo1, destination, deliveryMode));
    connection1.request(createMessage(producerInfo1, destination, deliveryMode));
    // the behavior is VERY dependent on the recovery policy used.
    // But the default broker settings try to make it as consistent as
    // possible
    // Subscription should see all messages sent.
    Message m2 = receiveMessage(connection1);
    assertNotNull(m2);
    assertEquals(m.getMessageId(), m2.getMessageId());
    for (int i = 0; i < 2; i++) {
        m2 = receiveMessage(connection1);
        assertNotNull(m2);
    }
    assertNoMessagesLeft(connection1);
}
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 75 with ConnectionInfo

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

the class BrokerTest method testConsumerCloseCausesRedelivery.

public void testConsumerCloseCausesRedelivery() 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);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    consumerInfo1.setPrefetchSize(100);
    connection1.request(consumerInfo1);
    // 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));
    // Receive the messages.
    for (int i = 0; i < 4; i++) {
        Message m1 = receiveMessage(connection1);
        assertNotNull("m1 is null for index: " + i, m1);
        assertFalse(m1.isRedelivered());
    }
    // Close the consumer without acking.. this should cause re-delivery of
    // the messages.
    connection1.send(consumerInfo1.createRemoveCommand());
    // Create another consumer that should get the messages again.
    ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo1, destination);
    consumerInfo2.setPrefetchSize(100);
    connection1.request(consumerInfo2);
    // Receive the messages.
    for (int i = 0; i < 4; i++) {
        Message m1 = receiveMessage(connection1);
        assertNotNull("m1 is null for index: " + i, m1);
        assertTrue(m1.isRedelivered());
    }
    assertNoMessagesLeft(connection1);
}
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