Spring DefaultMessageListenerContainer-会话缓存

Spring DefaultMessageListenerContainer-会话缓存,spring,jms,spring-jms,xa,Spring,Jms,Spring Jms,Xa,在我正在开发的应用程序中,我使用了一个SpringJMS和一个JMS使用者,后者是一个。还有一个XA transactionManager,在JMS和JDBC之间共享。作为JMS提供者,我使用WebLogic 我注意到,每次消费者接收到消息时,JMS会话都与之前消息中使用的会话完全不同: public void onMessage(Message message, Session session) throws JMSException { System.

在我正在开发的应用程序中,我使用了一个SpringJMS和一个JMS使用者,后者是一个。还有一个XA transactionManager,在JMS和JDBC之间共享。作为JMS提供者,我使用WebLogic

我注意到,每次消费者接收到消息时,JMS会话都与之前消息中使用的会话完全不同:

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

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
似乎JMS会话是由DefaultMesageListenerContainer自动管理的,它们没有被缓存——这让我担心性能

在使用XA事务的JMS使用者的上下文中,使用某种级别的缓存(例如缓存会话)是一个好主意吗

listenerContainer.setCacheLevel(DefaultMessageListenerContainer.CACHE_SESSION);

如果需要,我可以提供更多的代码片段,因为JMS配置是基于java的。

请参阅该setter的javadocs:

 * <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.
因此,您需要确定WebLogic是否支持这种配置