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.

Reply via email to