Search in sources :

Example 81 with ConnectionInfo

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

the class BrokerTest method testConnectionCloseCascades.

public void testConnectionCloseCascades() 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);
    consumerInfo1.setNoLocal(true);
    connection1.request(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);
    // Send the messages
    connection2.send(createMessage(producerInfo2, destination, deliveryMode));
    connection2.send(createMessage(producerInfo2, destination, deliveryMode));
    connection2.send(createMessage(producerInfo2, destination, deliveryMode));
    connection2.send(createMessage(producerInfo2, destination, deliveryMode));
    for (int i = 0; i < 4; i++) {
        Message m1 = receiveMessage(connection1);
        assertNotNull(m1);
        connection1.send(createAck(consumerInfo1, m1, 1, MessageAck.STANDARD_ACK_TYPE));
    }
    // give the async ack a chance to perculate and validate all are currently consumed
    Message msg = receiveMessage(connection1, MAX_NULL_WAIT);
    assertNull("all messages were received " + msg, msg);
    // Close the connection, this should in turn close the consumer.
    connection1.request(closeConnectionInfo(connectionInfo1));
    // Send another message, connection1 should not get the message.
    connection2.request(createMessage(producerInfo2, destination, deliveryMode));
    assertNull("no message received", receiveMessage(connection1, MAX_NULL_WAIT));
}
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 82 with ConnectionInfo

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

the class BrokerTest method testConsumerClose.

public void testConsumerClose() 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);
    consumerInfo1.setNoLocal(true);
    connection1.request(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);
    // Send the messages
    connection2.send(createMessage(producerInfo2, destination, deliveryMode));
    connection2.send(createMessage(producerInfo2, destination, deliveryMode));
    connection2.send(createMessage(producerInfo2, destination, deliveryMode));
    connection2.send(createMessage(producerInfo2, destination, deliveryMode));
    for (int i = 0; i < 4; i++) {
        Message m1 = receiveMessage(connection1);
        assertNotNull(m1);
        connection1.send(createAck(consumerInfo1, m1, 1, MessageAck.STANDARD_ACK_TYPE));
    }
    // give the async ack a chance to perculate and validate all are currently consumed
    // use receive rather than poll as broker info is sent async and may still need to be dequeued
    Message result = receiveMessage(connection1, MAX_NULL_WAIT);
    assertNull("no more messages " + result, result);
    // Close the consumer.
    connection1.request(closeConsumerInfo(consumerInfo1));
    // Send another message, connection1 should not get the message.
    connection2.request(createMessage(producerInfo2, destination, deliveryMode));
    result = receiveMessage(connection1, MAX_NULL_WAIT);
    assertNull("no message received after close " + result, result);
}
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 83 with ConnectionInfo

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

the class BrokerTest method testTopicDispatchIsBroadcast.

// https://issues.apache.org/jira/browse/ARTEMIS-402
public void testTopicDispatchIsBroadcast() 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);
    connection1.send(consumerInfo1);
    // Setup a second connection
    StubConnection connection2 = createConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, destination);
    consumerInfo2.setRetroactive(true);
    consumerInfo2.setPrefetchSize(100);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    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));
    // Get the messages
    for (int i = 0; i < 4; i++) {
        Message m1 = receiveMessage(connection1);
        assertNotNull(m1);
        m1 = receiveMessage(connection2);
        assertNotNull(m1);
    }
}
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 84 with ConnectionInfo

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

use of org.apache.activemq.command.ConnectionInfo 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)

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