You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by Andrew M <an...@oc384.net> on 2008/03/24 19:56:30 UTC

setting a MessageListener on a consumer?

I'm using the method below to create a Topic and Consumer and register my
MessageListener.  I'm worried that with a retroactive consumer I'm missing
messages between the .createConsumer() method and when the MessageListener
is actually registered with the MessageConsumer.  Shouldn't there be some
way to set the listener before firing up the consumer?

 

public void subscribe(String destName, MessageListener l) throws
JMSException {

        char c = destName.contains("?")?'&':'?';

        destName = destName + c + "consumer.retroactive=true";

        System.out.println("ActiveMqClient subscribe " + destName); 

        MessageConsumer mc = session.createConsumer(
session.createTopic(destName) );

        mc.setMessageListener(l);

    }

 

Thanks,

Andrew

 

 


Re: setting a MessageListener on a consumer?

Posted by James Strachan <ja...@gmail.com>.
On 24/03/2008, Andrew M <an...@oc384.net> wrote:
> I'm using the method below to create a Topic and Consumer and register my
>  MessageListener.  I'm worried that with a retroactive consumer I'm missing
>  messages between the .createConsumer() method and when the MessageListener
>  is actually registered with the MessageConsumer.  Shouldn't there be some
>  way to set the listener before firing up the consumer?
>
>
>
>  public void subscribe(String destName, MessageListener l) throws
>  JMSException {
>
>         char c = destName.contains("?")?'&':'?';
>
>         destName = destName + c + "consumer.retroactive=true";
>
>         System.out.println("ActiveMqClient subscribe " + destName);
>
>         MessageConsumer mc = session.createConsumer(
>  session.createTopic(destName) );
>
>         mc.setMessageListener(l);
>
>     }

Thats the JMS spec for you :)

You can create the consumer, then start the connection when everything
is all setup to commence delivery.

Though the ActiveMQ implementation should buffer up messages inside
the consumer until either its setMessageListener() method is called,
or a receive*() method is invoked.

-- 
James
-------
http://macstrac.blogspot.com/

Open Source Integration
http://open.iona.com