Search in sources :

Example 21 with ActiveMQDestination

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();
    }
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) MessageConsumer(javax.jms.MessageConsumer) Connection(javax.jms.Connection) MessageProducer(javax.jms.MessageProducer) Topic(javax.jms.Topic) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) ActiveMQDestination(org.apache.activemq.artemis.jms.client.ActiveMQDestination) Test(org.junit.Test)

Aggregations

ActiveMQDestination (org.apache.activemq.artemis.jms.client.ActiveMQDestination)21 Test (org.junit.Test)14 Connection (javax.jms.Connection)6 MessageConsumer (javax.jms.MessageConsumer)4 Session (javax.jms.Session)4 Reference (javax.naming.Reference)4 MessageProducer (javax.jms.MessageProducer)3 Queue (javax.jms.Queue)3 TextMessage (javax.jms.TextMessage)3 Topic (javax.jms.Topic)3 ObjectFactory (javax.naming.spi.ObjectFactory)3 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)3 Queue (org.apache.activemq.artemis.core.server.Queue)3 ActiveMQConnectionFactory (org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory)3 Destination (javax.jms.Destination)2 JMSException (javax.jms.JMSException)2 Referenceable (javax.naming.Referenceable)2 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)2 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)2 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)2