Search in sources :

Example 46 with SessionInfo

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

the class AdvisoryBrokerTest method testConnectionAdvisories.

public void testConnectionAdvisories() throws Exception {
    ActiveMQDestination destination = AdvisorySupport.getConnectionAdvisoryTopic();
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    consumerInfo1.setPrefetchSize(100);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(consumerInfo1);
    // We should get an advisory of our own connection.
    Message m1 = receiveMessage(connection1);
    assertNotNull(m1);
    assertNotNull(m1.getDataStructure());
    assertEquals(((ConnectionInfo) m1.getDataStructure()).getConnectionId(), connectionInfo1.getConnectionId());
    // Setup a second connection
    StubConnection connection2 = createConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    connection2.send(connectionInfo2);
    // We should get an advisory of the second connection.
    m1 = receiveMessage(connection1);
    assertNotNull(m1);
    assertNotNull(m1.getDataStructure());
    assertEquals(((ConnectionInfo) m1.getDataStructure()).getConnectionId(), connectionInfo2.getConnectionId());
    // Close the second connection.
    connection2.send(closeConnectionInfo(connectionInfo2));
    connection2.stop();
    // We should get an advisory of the second connection closing
    m1 = receiveMessage(connection1);
    assertNotNull(m1);
    assertNotNull(m1.getDataStructure());
    RemoveInfo r = (RemoveInfo) m1.getDataStructure();
    assertEquals(r.getObjectId(), connectionInfo2.getConnectionId());
    assertNoMessagesLeft(connection1);
}
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) SessionInfo(org.apache.activemq.command.SessionInfo) ConnectionInfo(org.apache.activemq.command.ConnectionInfo) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination)

Example 47 with SessionInfo

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

the class AdvisoryBrokerTest method testConsumerAdvisories.

public void testConsumerAdvisories() 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);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    consumerInfo1.setPrefetchSize(100);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(consumerInfo1);
    // We should not see and advisory for the advisory consumer.
    assertNoMessagesLeft(connection1);
    // Setup a second consumer.
    StubConnection connection2 = createConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, queue);
    consumerInfo1.setPrefetchSize(100);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    connection2.send(consumerInfo2);
    // We should get an advisory of the new consumer.
    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 48 with SessionInfo

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

the class AdvisoryBrokerTest method testProducerAdvisories.

public void testProducerAdvisories() 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);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    consumerInfo1.setPrefetchSize(100);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(consumerInfo1);
    assertNoMessagesLeft(connection1);
    // 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);
    // We should get an advisory of the new producer.
    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 : ConsumerInfo(org.apache.activemq.command.ConsumerInfo) ProducerInfo(org.apache.activemq.command.ProducerInfo) 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 49 with SessionInfo

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

the class RecoverExpiredMessagesTest method consumeExpected.

private void consumeExpected() throws Exception {
    // Setup the consumer and receive the message.
    StubConnection connection = createConnection();
    ConnectionInfo connectionInfo = createConnectionInfo();
    SessionInfo sessionInfo = createSessionInfo(connectionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo, destination);
    connection.send(consumerInfo);
    Message m = receiveMessage(connection);
    assertNotNull("Should have received message " + expected.get(0) + " by now!", m);
    assertEquals(expected.get(0), m.getMessageId().toString());
    MessageAck ack = createAck(consumerInfo, m, 1, MessageAck.STANDARD_ACK_TYPE);
    connection.send(ack);
    assertNoMessagesLeft(connection);
    connection.request(closeConnectionInfo(connectionInfo));
}
Also used : ConsumerInfo(org.apache.activemq.command.ConsumerInfo) Message(org.apache.activemq.command.Message) StubConnection(org.apache.activemq.broker.StubConnection) SessionInfo(org.apache.activemq.command.SessionInfo) MessageAck(org.apache.activemq.command.MessageAck) ConnectionInfo(org.apache.activemq.command.ConnectionInfo)

Example 50 with SessionInfo

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

the class ForwardingBridgeTest method testForwardMessageCompressed.

public void testForwardMessageCompressed() throws Exception {
    bridge.setUseCompression(true);
    // Start a producer on local broker
    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);
    // Start a consumer on a remote broker
    StubConnection connection2 = createRemoteConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo2, destination);
    connection2.send(consumerInfo);
    Thread.sleep(1000);
    // Give forwarding bridge a chance to finish setting up
    try {
        Thread.sleep(1000);
    } catch (InterruptedException ie) {
        ie.printStackTrace();
    }
    // Send the message to the local boker.
    connection1.send(createMessage(producerInfo, destination, deliveryMode));
    // Make sure the message was delivered via the remote.
    Message m = receiveMessage(connection2);
    assertNotNull(m);
    // Make sure its compressed now
    ActiveMQMessage message = (ActiveMQMessage) m;
    assertTrue(message.isCompressed());
}
Also used : ProducerInfo(org.apache.activemq.command.ProducerInfo) ConsumerInfo(org.apache.activemq.command.ConsumerInfo) Message(org.apache.activemq.command.Message) ActiveMQMessage(org.apache.activemq.command.ActiveMQMessage) StubConnection(org.apache.activemq.broker.StubConnection) SessionInfo(org.apache.activemq.command.SessionInfo) ConnectionInfo(org.apache.activemq.command.ConnectionInfo) ActiveMQMessage(org.apache.activemq.command.ActiveMQMessage)

Aggregations

SessionInfo (org.apache.activemq.command.SessionInfo)96 ConnectionInfo (org.apache.activemq.command.ConnectionInfo)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 XATransactionId (org.apache.activemq.command.XATransactionId)15 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 RemoveInfo (org.apache.activemq.command.RemoveInfo)5 Response (org.apache.activemq.command.Response)4 TransactionId (org.apache.activemq.command.TransactionId)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 OpenwireArtemisBaseTest (org.apache.activemq.broker.artemiswrapper.OpenwireArtemisBaseTest)3