users@jms-spec.java.net

[jms-spec users] [jsr343-experts] Re: Re: Clarification on JMSContext::createConsumer

From: Clebert Suconic <clebert.suconic_at_gmail.com>
Date: Mon, 9 Dec 2013 09:28:59 -0500

Correction...

I would fix it on caching the consumer on the same context...


on this case...


Object consumer1 = context1.createConsumer(queue1);
Object consuemr2 = context1.createConsumer(queue1);


On this case, consumer1 == consumer2



I don't see any point about the implementation returning the same consumer,
so it's not clear what should happen when I do:


consumer1.setMessageListener(...)

and consumer2.setMessageListener(...);



Keep in mind we are talking about the same context here!


On Mon, Dec 9, 2013 at 9:21 AM, John D. Ament <john.d.ament_at_gmail.com>wrote:

> Interesting, looking at 15.9.2 of the spec
>
> public void receiveMessagesNew() throws NamingException {
>
> InitialContext namingContext = getInitialContext();
> ConnectionFactory connectionFactory = (ConnectionFactory)
> namingContext.lookup("jms/connectionFactory");
> Queue dataQueue = (Queue) namingContext.lookup("jms/dataQueue");
> try (JMSContext context1 =
> connectionFactory.createContext(AUTO_ACKNOWLEDGE);
> JMSContext context2 =
> context1.createContext(AUTO_ACKNOWLEDGE);){
> JMSConsumer consumer1 = context1.createConsumer(dataQueue);
> MyListener messageListener1 = new MyListener("One");
> consumer1.setMessageListener(messageListener1);
>
> JMSConsumer consumer2 = context2.createConsumer(dataQueue);
> MyListener messageListener2 = new MyListener("Two");
> consumer2.setMessageListener(messageListener2);
>
> // wait for messages to be received
> // details omitted
> }
> }
>
> I guess my question is why exactly is your impl failing here? What
> does it have to do with reusing consumers? When you do Object
> comparisons in OpenMQ are they returning the same instance here?
>
> On Mon, Dec 9, 2013 at 9:10 AM, Clebert Suconic
> <clebert.suconic_at_gmail.com> wrote:
> > The following code here would work on the reference implementation...
> >
> >
> > Message msg1 = context.createConsumer(queue1).receive(5000);
> > Message msg2 = context.createConsumer(queue1).receive(5000);
> >
> >
> >
> > and I just tried on my implementation and it doesn't work of course...
> as I
> > create one consumer per call. Things like read-ahead would make it cache
> on
> > the client...
> >
> >
> > to make it always work, I would have to create a cache for
> createConsumer,
> > but however, there's a complication on setMessageListener:
> >
> >
> > JMSConsumer consumer1 = context.createConsumer(queue1);
> > consumer1.setMessageListener(listener1);
> > JMSConsumer consumer2 = context.createConsumer(queue1);
> > consumer2.setMessageListener(listener2);
> >
> >
> >
> > If I make a cache, the second call would return the same consumer and
> hence
> > the setMessageListener on listener2 wouldn't work. I could of course
> clear
> > my cache on the implementation once setMessageListener is used....
> However
> > it's a bit weird since I won't have access to close the consumer any
> longer.
> >
> >
> >
> > this goes related to a previous discussion on receiving messages
> nonymously
> > such as:
> >
> >
> > context.createConsumer(queue1).receive(TIMEOUT);
> >
> >
> >
> >
> > Any thoughts?
> >
> >
>



-- 
Clebert Suconic
http://community.jboss.org/people/clebert.suconic@jboss.com
http://clebertsuconic.blogspot.com