Alina Danila
Alina Danila

Reputation: 1683

Spring DefaultMessageListenerContainer - session caching

In the application that I am working on I use a Spring JMS DefaultMessageListenerContainer and a JMS consumer that is a SessionAwareMessageListener. There is also an XA transactionManager, shared between JMS and JDBC. As JMS provider I use WebLogic.

What I have noticed is that each time the consumer receives a message, the JMS Session is completely different than the ones used for the previous messages:

    public void onMessage(Message message, Session session) throws JMSException {
                System.out.println("Session " + session);
    }

the output:

Session weblogic.jms.client.WLSessionImpl@17703c5b
Session weblogic.jms.client.WLSessionImpl@6b3390f
Session weblogic.jms.client.WLSessionImpl@2142f096
Session weblogic.jms.client.WLSessionImpl@19824dc
Session weblogic.jms.client.WLSessionImpl@7bf5b63b
Session weblogic.jms.client.WLSessionImpl@250d81

It seems that the JMS sessions are automatically managed by the DefaultMesageListenerContainer and they are not cached - which makes me worry about performance.

In the context of a JMS consumer using XA transactions, would it be a good idea to use some level of caching, CACHE_SESSION for example?

listenerContainer.setCacheLevel(DefaultMessageListenerContainer.CACHE_SESSION);

(If required, I can provide more code snippets, as JMS configuration is java based).

Upvotes: 0

Views: 1292

Answers (1)

Gary Russell
Gary Russell

Reputation: 174494

See the javadocs for that setter:

 * <p>Default is {@link #CACHE_NONE} if an external transaction manager has been specified
 * (to reobtain all resources freshly within the scope of the external transaction),
 * and {@link #CACHE_CONSUMER} otherwise (operating with local JMS resources).

 * <p>Some Java EE servers only register their JMS resources with an ongoing XA
 * transaction in case of a freshly obtained JMS {@code Connection} and {@code Session},
 * which is why this listener container by default does not cache any of those.
 * However, depending on the rules of your server with respect to the caching
 * of transactional resources, consider switching this setting to at least
 * {@link #CACHE_CONNECTION} or {@link #CACHE_SESSION} even in conjunction with an
 * external transaction manager.

So you need to determine whether WebLogic supports such a configuration.

Upvotes: 0

Related Questions