users@jms-spec.java.net

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

From: John D. Ament <john.d.ament_at_gmail.com>
Date: Mon, 9 Dec 2013 09:21:09 -0500

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?
>
>