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);
}
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);
}
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);
}
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));
}
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());
}
Aggregations