users@jms-spec.java.net

[jms-spec users] [jsr343-experts] Re: Clarification about JMSContext and setClientID

From: Nigel Deakin <nigel.deakin_at_oracle.com>
Date: Tue, 25 Jun 2013 10:07:41 +0100

Clebert,

On 24/06/2013 20:36, Clebert Suconic wrote:
> say you created a JMSContext, and used setClientID....
> JMSContext ctx = ...
> ctx.setClientID("someID");
>
> Say, if later we call
> JMSContext ctx2 = ctx.createJMSContext();

Note that this method has one parameter, a sessionMode.
http://docs.oracle.com/javaee/7/api/javax/jms/JMSContext.html#createContext%28int%29

>
> What would be the expected value of ctx2.getClientID() ?

The javadocs for JMSContext#createContext(int sessionMode) say that this "creates a new |JMSContext| with the specified
session mode using the same connection as this |JMSContext| and creating a new session. "

Since the two JMSContext objects will use the same underlying connection, they have the same clientID, same exception
listener and same connection metadata.

> I'm assuming there will be some connection reused by the JMSContext and ctx.createJMSContext() would reuse the
> internal connection as we talked earlier. I'm just double checking if this is everybody's expectations...?

That's certainly my intention. The reason for this method is to allow you to create a second session on the same
connection. The main reason for doing this is to allow you to send or receive messages using more than one thread at a
time (but still using the same connection).

The above applies only to Java SE and the Java EE application client. Applications running in the Java EE web or EJB
container are not allowed to create more than one session per connection.This restriction dates from Java EE 6 and
probably earlier: see Java EE 6 section EE 6.7.

For this reason, JMSContext#createContext(int sessionMode) is required to throw a JMSRuntimeException if called in the
Java EE web or EJB containers. This is also why there isn't a no-parameter version of this method.

Nigel

>
> Clebert