3 Replies Latest reply on Aug 3, 2009 8:17 PM by mickknutson_mickknutson

    Are Virtual Consumers Durable?

    gmotts_gary.motts

      Hi,

       

      I've read an ActiveMQ article describing why not to use traditional JMS durable subscriptions at http://activemq.apache.org/virtual-destinations.html. In place of durable subscribers it suggests to use Virtual Topics and a Virtual Consumer Queue. I'm testing this using Camel 1.5.4. and have implemented a route from a Virtual Topic to a Virtual Consumer as:

       

      from("activemq:topic:VirtualTopic.topic").to("activemq:Consumer.example.VirtualTopic.topic");

       

      With the following added to the activemq.xml configuration file:

       

      <broker xmlns="http://activemq.apache.org/schema/core">

       

       

                  

       

      So my question is does this virtual consumer provide durability? For this route definition, will the topic hold the subscription until the consumer is connected? In preliminary tests I cannot confirm this, on the ActiveMQ Administration console the above example does not show the consumer as a "durable subscriber", which is probablly correct?

       

      Seeking anyone's advice or experience with this subject.

       

      Thanks.

       

      -Gary

        • 1. Re: Are Virtual Consumers Durable?
          gseben

          Hi Gary,

           

          In the case of Virtual Topics the consumers are not durable subscribers. When a consumer is created for a Virtual Topic, it has to consume messages from a queue that is associated with that virtual destination. For example, in your case Consumer.example.VirtualTopic.topic, should be the queue from where your consumers will receive messages sent to VirtualTopic.topic. Message durability is then guaranteed by the queue.

           

          This snippet of code from one of the Junit tests in the source might help you see how it all fits together:

           

              public void testVirtualTopicCreation() throws Exception {
                  if (connection == null) {
                      connection = createConnection();
                  }
                  connection.start();
          
                  ConsumerBean messageList = new ConsumerBean();
                  messageList.setVerbose(true);
                  
                  String queueAName = getVirtualTopicConsumerName();
                  // create consumer 'cluster'
                  ActiveMQQueue queue1 = new ActiveMQQueue(queueAName);
                  ActiveMQQueue queue2 = new ActiveMQQueue(queueAName);
          
                  Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
                  MessageConsumer c1 = session.createConsumer(queue1);
                  MessageConsumer c2 = session.createConsumer(queue2);
          
                  c1.setMessageListener(messageList);
                  c2.setMessageListener(messageList);
          
                  // create topic producer
                  MessageProducer producer = session.createProducer(new ActiveMQTopic(getVirtualTopicName()));
                  assertNotNull(producer);
          
                  int total = 10;
                  for (int i = 0; i < total; i++) {
                      producer.send(session.createTextMessage("message: " + i));
                  }
                  
                  messageList.assertMessagesArrived(total);
              }
          
          
              protected String getVirtualTopicName() {
                  return "VirtualTopic.TEST";
              }
          
          
              protected String getVirtualTopicConsumerName() {
                  return "Consumer.A.VirtualTopic.TEST";
              }
          

           

          -Giovani

          • 2. Re: Are Virtual Consumers Durable?
            gmotts_gary.motts

            So if I understand correctly, message delivery between the virtual topic and the virtual consumer is "guarenteed", i.e. "durable" when the consumer is made available and the queue session is establilshed to the topic.  When a message is published to the Virtual Topic and the consumer is "offline", it will retain the message until the consumer connection is re-established.

            • 3. Re: Are Virtual Consumers Durable?
              mickknutson_mickknutson

              Can you help me to understand how to use Camel and an embedded AMQ to test this?