SimpleMessageListenerContainer

SimpleMessageListenerContainer

本文介绍了Spring AMQP 中 SimpleMessageListenerContainer 和 DirectMessageListenerContainer 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Spring AMQP 中的 SimpleMessageListenerContainerDirectMessageListenerContainer 有什么区别?我检查了他们的两个文档页面,SimpleMessageListenerContainer 几乎没有关于内部工作的解释,而 DirectMessageListenerContainer 有以下解释:

What's the difference between SimpleMessageListenerContainer and DirectMessageListenerContainer in Spring AMQP? I checked both of their documentation pages, SimpleMessageListenerContainer has almost no explanation on inner workings, and DirectMessageListenerContainer has the following explanation:

我真的不明白这些是什么意思.它表示侦听器容器直接在兔子客户端消费者线程上调用侦听器.如果是这样,那么SimpleMessageListenerContainer 是如何调用的?

I don't really understand what these mean. It says listener container that invokes the listener directly on the rabbit client consumer thread. If so, then how does SimpleMessageListenerContainer do the invocation?

我写了一个小应用,使用了DirectMessageListenerContainer,只是为了看看有什么不同,我切换到了SimpleMessageListenerContainer,但据我所知在RabbitMQ上没有什么区别边.从 Java 方面来看,区别在于方法(SimpleMessageListenerContainer 提供了更多)和日志(DirectMessageListenerContainer 记录了更多内容)

I wrote a small application and used DirectMessageListenerContainer and just to see the difference, I switched to SimpleMessageListenerContainer, but as far as I can see there was no difference on RabbitMQ side. From Java side the difference was in methods (SimpleMessageListenerContainer provides more) and logs (DirectMessageListenerContainer logged more stuff)

我想知道使用每一种的场景.

I would like to know the scenarios to use each one of those.

推荐答案

SMLC 为每个消费者(并发)都有一个专用线程,它轮询内部队列.当客户端线程上的消费者收到一条新消息时,它被放入内部队列,消费者线程将其取出并调用侦听器.这是客户端的早期版本提供多线程所必需的.使用较新的客户端没有问题,因此我们可以直接调用侦听器(因此得名).

The SMLC has a dedicated thread for each consumer (concurrency) which polls an internal queue. When a new message arrives for a consumer on the client thread, it is put in the internal queue and the consumer thread picks it up and invokes the listener. This was required with early versions of the client to provide multi-threading. With the newer client that is not a problem so we can invoke the listener directly (hence the name).

除了 txSize 之外,还有其他一些区别.

There are a few other differences aside from txSize.

请参阅选择容器.

这篇关于Spring AMQP 中 SimpleMessageListenerContainer 和 DirectMessageListenerContainer 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-06 06:26