了解Spring SingleConnectionFactory和CachingConnectionFactory的JMS集成测试 [英] Understanding JMS integration testing with Spring SingleConnectionFactory and CachingConnectionFactory

查看:729
本文介绍了了解Spring SingleConnectionFactory和CachingConnectionFactory的JMS集成测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮助您理解以下内容:

Please some help understanding the following:

我在应用程序中使用CachingConnectionFactory,并且在进行jms测试时首先使用它来测试我的jms配置,例如保证交付,回滚/提交等.

I am using CachingConnectionFactory in my app and first used it during my jms tests to test my jms config like guaranteed delivery, rollback/commit, etc..

我正在使用Spring的JmsTemplate进行发送,并在交付过程中使用DefaultMessageListenerContainer.

I am using Spring's JmsTemplate for sending and DefaultMessageListenerContainer during delivery.

  1. 我注意到,当使用几种顺序运行的测试方法时,这是很难/不可能的 示例:在测试方法A中,我在消息侦听器(用户端)中引发异常,从而导致重试. 然后运行测试B,并在方法A中执行另一个测试,但是当我启动此测试时,我仍然从测试A中获得重试消息,我显然不希望这样做. 我在测试之间通过jmx清除了Queue,但仍然收到这些重试:(... 我进行了搜索和调试...我不完全理解为什么这些重试会不断出现,即使我确定清除正确进行了也是如此.也许它已经被缓存在会话中的某个地方了……我不知道.有人知道吗?

  1. I noticed that this is hard/impossible when using several test methods run sequential Example: in test method A I throw exceptions in the Message listener (consumer side) such that retries occur. Then test B is run and in method A I do a different test, but when I start this test I still get retry messages from test A, which I clearly not want. I purge the Queue through jmx between tests, but still receive these retries :(... I searched and debugged... I don't exactly understand why these retries keep comming up, even when I am sure that the purge occur correctly. Maybe it was already cached somewhere in the session... I don't know. Anybody any idea?

我发现我需要在测试期间使用SingleConnectionFactory.通过这种连接工厂,重试消失了,但是我真的不明白为什么.为什么? 我知道它仅使用一个连接(来自Spring ref),并且注意到它在每次发送操作后都会以某种方式删除使用者,但是我真的不理解这些重试会发生什么:(...任何想法? (由于多线程行为,因此很难调试,并且很难在网络上找到关于它的良好信息) 此外,仅使用一个会话高速缓存大小为1的CachingConnectionFactory并不能解决重试问题.

I found out that I needed to use the SingleConnectionFactory during testing. With this connection factory the retries disappear, but I don't really understand why. Why? I understand that it uses only one connection (from the Spring ref), and noticed that it somehow removes the consumer after every send action, but I don't really understand what happen with these retries :(... Any idea? (It's hard to debug because of the multi threading behavior and difficult to find good information about it on the web) Also using CachingConnectionFactory with only one session cache size of 1 didn't solve the retry issue.

谢谢

推荐答案

要解决这个问题并不容易:删除测试之间的消息. 我尝试了很多事情,就像上面提到的那样:停止/启动代理以及用于消耗消息的Spring类DefaultMessageListenerContainer. 直到我将我在DefaultMessageListenerContainer中将缓存级别设置为Consumer以便消费者被缓存之前,这一切似乎都起作用. 为了使redeliveryPolicy起作用,这是必需的. 但是,这似乎使DefaultMessageListenerContainer缓存的所有内容和消息看起来有些混乱.

It's not an easy thing to fix: remove the messages between tests. I tried many thingssss, like mentioned above: stop/start the broker and the class DefaultMessageListenerContainer of Spring that I use to consume my messages. It all seem to work until I turned I set the cache level in DefaultMessageListenerContainer to Consumer such that the consumer is cached. That is required such that the redeliveryPolicy works. However, this messed up everything and messages where cached by DefaultMessageListenerContainer in some way, as it seemed.

最后,我通过简单地消耗测试后的所有消息(只需稍等片刻并消耗掉所有的Ok)来解决该问题,以便下次测试可以开始.

At the end, I solved it by simple consuming all messages after a test (just wait a second and consume all Ok), such that the next test can begin.

这篇关于了解Spring SingleConnectionFactory和CachingConnectionFactory的JMS集成测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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