带有JMS 2.0的Spring 4 CachingConnectionFactory无法正确地缓存生产者 [英] Spring 4 CachingConnectionFactory with JMS 2.0 doesn't properly cache Producers

查看:559
本文介绍了带有JMS 2.0的Spring 4 CachingConnectionFactory无法正确地缓存生产者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们刚刚升级到Spring 4和JMS 2.0.我们使用CachingConnectionFactoryJmsTemplate来发布消息,并注意到在发布到目标位置时,第一次尝试有效,然后再尝试发布到相同的目的地会导致以下异常:

We just upgraded to Spring 4 and JMS 2.0. We are using a CachingConnectionFactory and a JmsTemplate to publish messages and noticed that when publishing to a destination, the first attempt works and then further attempts to publish to the same destination cause the following exception:

原因:javax.jms.IllegalStateException:生产者已关闭

Caused by: javax.jms.IllegalStateException: The producer is closed

所有内容在Spring 3.2和JMS 1.1上都运行良好,因此我做了一些挖掘工作以查看问题所在,并且看来问题出在CachedMessageProducer类中.通常,此类在MessageProducer接口中重新实现所有方法.具体来说,有一种close()方法可以重新实现,该方法将在使用JmsTemplate发送消息后重新设置属性,但使生产者保持活动状态(因为它是缓存工厂).

Everything worked fine with Spring 3.2 and JMS 1.1 so I did some digging to see what the problem was and it seems the issue is in the CachedMessageProducer class. Normally this class re-implements all of the methods in the MessageProducer interface. Specifically there is a close() method that is re-implemented and will only reset properties but keep the producer alive (since it is a caching factory) after a message is sent using the JmsTemplate.

但是,Spring 4中有一个名为getProxyIfNecessary的新方法,该方法确定是否正在使用JMS 2.0,并且在检测到JMS 2.0时会创建一个Jms2MessageProducerInvocationHandler代理.此代理的invoke方法将所有调用委派给原始MessageProducer对象,并且似乎绕过CachedMessageProducer中的方法调用.最终结果是在原始MessageProducer对象上调用了close方法(我们不希望这样做,因为它应该被缓存).这意味着将来的发布尝试都会使生产者已经关闭.

However, there is a new method in Spring 4 called getProxyIfNecessary that determines whether or not JMS 2.0 is being used and when it detects JMS 2.0 it creates a Jms2MessageProducerInvocationHandler proxy. The invoke method of this proxy is delegating all calls to the original MessageProducer object, and seems to be bypassing method calls in the CachedMessageProducer. The end result is that the close method gets called on the original MessageProducer object (which we don't want since it should be cached). This means that future attempts to publish give the exception that the producer has been closed.

其他人以前有这个问题吗?我不确定是否做错了什么,或者这是Spring的新JMS 2.0支持中的错误.

Has anyone else had this issue before? I'm not sure if I'm doing something wrong or if this is a bug with the new JMS 2.0 support in Spring.

推荐答案

就像您发现自己一样,这确实是一个错误,并且在即将发布的4.0.64.1.RC1中已解决.谢谢!

Like you found out yourself, this is indeed a bug and this is resolved in the upcoming 4.0.6 and 4.1.RC1. Thanks!

这篇关于带有JMS 2.0的Spring 4 CachingConnectionFactory无法正确地缓存生产者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆