You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by Shyam Santhanam <ss...@vmware.com> on 2009/10/28 13:40:37 UTC

Cannot receive from Virtual Topic's consumer queue

Hello,

I'm trying to use Virtual Topics for the first time (and I'm relatively new
to ActiveMQ). I've tried to follow the instructions on the virtual
destinations page and also looked at VirtualTopicPubSubTest in activemq-core
unit tests and tried to follow it as closely as I could see.  This is the
test I have:

        TopicConnection connection = createTopicConnection();
        connection.setClientID("TestClientID");
        connection.start();

        TopicSession session = connection.createTopicSession(false,
Session.AUTO_ACKNOWLEDGE);
        Topic topic = session.createTopic("VirtualTopic.TestTopic");

        MessageListener listener = new MessageListener() {
            @Override
            public void onMessage(Message msg) {
                try {
                    log.info("Message received: {0}",
msg.getJMSMessageID());
                } catch (JMSException e) {
                    log.error(e, "Error receiving message");
                }
            }

        };

        QueueConnection queueConnection = createQueueConnection();
        QueueSession qSession = queueConnection.createQueueSession(false,
Session.AUTO_ACKNOWLEDGE);

        Queue queue = new
ActiveMQQueue("Consumer.A.VirtualTopic.TestTopic");
        MessageConsumer consumer = qSession.createConsumer(queue);
        consumer.setMessageListener(listener);

        TopicPublisher publisher = session.createPublisher(topic);
        Message message = session.createMessage();
        publisher.send(message);

This doesn't seem to work though.  The message is never received.  We are
using activemq-core 5.3.0.1-fuse.  Am I missing something as far as the
setup goes?

Note that createTopicConnection() and createQueueConnection() do nothing
special to the connection as far as setup goes, they are straight from an
ActiveMQConnectionFactory which is setup as follows:

<bean class="org.apache.activemq.ActiveMQConnectionFactory">
    <constructor-arg value="vm://localhost"/>
</bean>

(This is just one for unit-test purposes, our actual broker configuration
has more settings).

-- 
View this message in context: http://www.nabble.com/Cannot-receive-from-Virtual-Topic%27s-consumer-queue-tp26093937p26093937.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: Cannot receive from Virtual Topic's consumer queue

Posted by Shyam Santhanam <ss...@vmware.com>.
Sorry, nevermind, it works great now. PEBKAH. I was just not starting the
connection that I created my queue session out of.
-- 
View this message in context: http://www.nabble.com/Cannot-receive-from-Virtual-Topic%27s-consumer-queue-tp26093937p26096429.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: Cannot receive from Virtual Topic's consumer queue

Posted by Shyam Santhanam <ss...@vmware.com>.
What is your broker configuration (so that I may compare it with mine and see
what I'm missing)?

-- 
View this message in context: http://www.nabble.com/Cannot-receive-from-Virtual-Topic%27s-consumer-queue-tp26093937p26096214.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: Cannot receive from Virtual Topic's consumer queue

Posted by Joe Fernandez <jo...@ttmsolutions.com>.
Nope, that was my bad. Sorry for the confusion. Your code should work. I
tried something similar with ActiveMQ 5.3 and it worked fine for me. Here's
my code, which is using JNDI. 


            MessageListener listener = new MessageListener() {
             @Override
             public void onMessage(Message msg) {
                 if( msg == null)
                    return;
                 TextMessage txtMsg = (TextMessage) msg;
                 try {
                    System.out.println("Listener: message text = " +
                    txtMsg.getText());
                 } catch (Exception e) {
                 e.printStackTrace();
               }
             }
            };
            
            javax.naming.Context ctx = new InitialContext();            
            ConnectionFactory factory = (javax.jms.ConnectionFactory)
            ctx.lookup("localConnectionFactory");

            Connection conn = factory.createConnection();

            Topic myTopic = (Topic) ctx.lookup("BLAST");
            Queue myQueue = (javax.jms.Queue) ctx.lookup("Q.BLAST");
            
            Session topicSession = conn.createSession(false,
Session.AUTO_ACKNOWLEDGE);
            Session queueSession = conn.createSession(false,
Session.AUTO_ACKNOWLEDGE);

            MessageProducer topicSender =
topicSession.createProducer(myTopic);
            MessageConsumer queueConsumer =
queueSession.createConsumer(myQueue);

            queueConsumer.setMessageListener(listener);
            
            conn.start();
            
            TextMessage msg = topicSession.createTextMessage();
            msg.setText("Hello World");
            topicSender.send(msg);     

            // Give the listener some time to get the message
            Thread.sleep(1000);

            // close everything down
            topicSender.close();
            topicSession.close();
            queueSession.close();
            conn.close();            




Shyam Santhanam wrote:
> 
> 
> Joe Fernandez wrote:
>> 
>> If you activate your consumer after the messages have been published to
>> the topic, then the messages will not be forwarded on to the consumer's
>> queue.   
>> 
> 
> Sorry, but I thought I'm sending to the topic after setting up the
> consumer, just as you suggest.  What do you mean by "activate" the
> consumer? I assume this just means connecting to the queue and setting the
> message listener, or is there some other step required?
> 

-- 
View this message in context: http://www.nabble.com/Cannot-receive-from-Virtual-Topic%27s-consumer-queue-tp26093937p26096034.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: Cannot receive from Virtual Topic's consumer queue

Posted by Shyam Santhanam <ss...@vmware.com>.

Joe Fernandez wrote:
> 
> If you activate your consumer after the messages have been published to
> the topic, then the messages will not be forwarded on to the consumer's
> queue.   
> 

Sorry, but I thought I'm sending to the topic after setting up the consumer,
just as you suggest.  What do you mean by "activate" the consumer? I assume
this just means connecting to the queue and setting the message listener, or
is there some other step required?
-- 
View this message in context: http://www.nabble.com/Cannot-receive-from-Virtual-Topic%27s-consumer-queue-tp26093937p26094681.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: Cannot receive from Virtual Topic's consumer queue

Posted by Joe Fernandez <jo...@ttmsolutions.com>.
I forgot to mention that once the consumer queues have been created, the
messages will be forwarded on to the queues, even if the corresponding
consumers are not active. One option is to have the broker create the queues
on start up. 

Joe
http://www.ttmsolutions.com


Joe Fernandez wrote:
> 
> If you activate your consumer after the messages have been published to
> the topic, then the messages will not be forwarded on to the consumer's
> queue.   
> 
> As an alternative, you might want to check out Camel to implement a
> similar messaging pattern. 
> 
> http://camel.apache.org/recipient-list.html
> 
> Joe
> http://www.ttmsolutions.com
> 
> 
>  
> 
> Shyam Santhanam wrote:
>> 
>> Just want to add that I also tried attaching JConsole and looking at the
>> Queue/Topic MBeans. It showed that the consumer queue had 0 dispatch and
>> enqueue count.  The virtual topic had 1 enqueue count, 0 dispatch count.
>> So apparently the message isn't getting relayed from the topic to the
>> queue? 
>> 
>> Not sure if these stats are what I should be monitoring.
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Cannot-receive-from-Virtual-Topic%27s-consumer-queue-tp26093937p26094697.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: Cannot receive from Virtual Topic's consumer queue

Posted by Joe Fernandez <jo...@ttmsolutions.com>.
If you activate your consumer after the messages have been published to the
topic, then the messages will not be forwarded on to the consumer's queue.   

As an alternative, you might want to check out Camel to implement a similar
messaging pattern. 

http://camel.apache.org/recipient-list.html

Joe
http://www.ttmsolutions.com


 

Shyam Santhanam wrote:
> 
> Just want to add that I also tried attaching JConsole and looking at the
> Queue/Topic MBeans. It showed that the consumer queue had 0 dispatch and
> enqueue count.  The virtual topic had 1 enqueue count, 0 dispatch count.
> So apparently the message isn't getting relayed from the topic to the
> queue? 
> 
> Not sure if these stats are what I should be monitoring.
> 

-- 
View this message in context: http://www.nabble.com/Cannot-receive-from-Virtual-Topic%27s-consumer-queue-tp26093937p26094584.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: Cannot receive from Virtual Topic's consumer queue

Posted by Shyam Santhanam <ss...@vmware.com>.
Just want to add that I also tried attaching JConsole and looking at the
Queue/Topic MBeans. It showed that the consumer queue had 0 dispatch and
enqueue count.  The virtual topic had 1 enqueue count, 0 dispatch count. So
apparently the message isn't getting relayed from the topic to the queue? 

Not sure if these stats are what I should be monitoring.
-- 
View this message in context: http://www.nabble.com/Cannot-receive-from-Virtual-Topic%27s-consumer-queue-tp26093937p26094050.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.