use of org.apache.activemq.artemis.jms.client.ActiveMQDestination in project activemq-artemis by apache.
the class LVQTest method testLastValueQueueTopicConsumerUsingAddressQueueParameters.
@Test
public void testLastValueQueueTopicConsumerUsingAddressQueueParameters() throws Exception {
ActiveMQConnectionFactory fact = (ActiveMQConnectionFactory) getCF();
// Set the consumer window size to 0 to not buffer any messages client side.
fact.setConsumerWindowSize(0);
Connection connection = fact.createConnection();
try {
Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
Topic topic = session.createTopic("topic?last-value=true");
assertEquals("topic", topic.getTopicName());
ActiveMQDestination a = (ActiveMQDestination) topic;
assertTrue(a.getQueueAttributes().getLastValue());
MessageProducer producer = session.createProducer(topic);
MessageConsumer consumer1 = session.createConsumer(topic);
MessageConsumer consumer2 = session.createConsumer(topic);
connection.start();
for (int j = 0; j < 100; j++) {
TextMessage message = session.createTextMessage();
message.setText("Message" + j);
message.setStringProperty(Message.HDR_LAST_VALUE_NAME.toString(), "key");
producer.send(message);
}
// Last message only should go to the consumer.
TextMessage tm = (TextMessage) consumer1.receive(10000);
assertNotNull(tm);
assertEquals("Message99", tm.getText());
// Last message only should go to the other consumer as well.
TextMessage tm2 = (TextMessage) consumer2.receive(10000);
assertNotNull(tm2);
assertEquals("Message99", tm2.getText());
} finally {
connection.close();
}
}
Aggregations