当应用程序中有多个@JmsListener 时会发生什么? (在并发方面)

What happens when there are more than one @JmsListener in an application? (in terms of concurrency)

我正在尝试使用 JMS 使用来自三个 IBM MQ 队列的消息。

因此,我的 spring 启动应用程序中有三个 @JmsListener。

我对此有疑问,如果所有消费者都可以从各自的队列中消费,他们将如何表现。

提前致谢:)

在 JmsListener 注释上,您可以设置并发行为:

concurrency

public abstract String concurrency

The concurrency limits for the listener, if any. Overrides the value defined by the container factory used to create the listener container. The concurrency limits can be a "lower-upper" String — for example, "5-10" — or a simple upper limit String — for example, "10", in which case the lower limit will be 1.

Note that the underlying container may or may not support all features. For instance, it may not be able to scale, in which case only the upper limit is used.

来源:https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/jms/annotation/JmsListener.html#concurrency--

每个侦听器都在自己的线程中运行。

您可以通过打印收到的消息轻松地对此进行测试。这将输出它运行的线程。例如:

2020-06-06 11:26:54.339  INFO 23404 --- [enerContainer-1] c.e.d.ShippingService                    : Hello World!

线程名称是[enerContainer-1]

请阅读有关 Spring 和 JMS https://docs.spring.io/spring/docs/current/spring-framework-reference/integration.html#jms-receiving

的更多文档