DefaultJmsListenerContainerFactory与DefaultMessageListenerContainer [英] DefaultJmsListenerContainerFactory vs DefaultMessageListenerContainer
问题描述
与DefaultMessageListenerContainer
相比,使用DefaultJmsListenerContainerFactory
有什么优势?
What are the advantages of using DefaultJmsListenerContainerFactory
over DefaultMessageListenerContainer
?
-
如果我直接配置DMLC,则可以通过调用
isRunning()
来获取检查状态的句柄.我也确实有启动和停止DMLC的功能
If i configure DMLC directly , i do get a handle to check the status by calling
isRunning()
. Also i do get a facility to start and stop the DMLC
但是,根据新的春季规格,如果我配置DefaultJmsListenerContainerFactory
,则无法获得DMLC的处理,因此无法执行上述任何操作.
However, per new spring specs, if i configure DefaultJmsListenerContainerFactory
, i do not get handle of DMLC, so i am unable to do any of above operations.
因此,从上述限制来看,有人可以解释为什么应该在DMLC上使用DefaultJmsListenerContainerFactory
So looking at above limitation, can somebody explain why one should use DefaultJmsListenerContainerFactory
over DMLC
此外,如果我使用DefaultJmsListenerContainerFactory
,可以实现上述功能吗?
Also, if i use DefaultJmsListenerContainerFactory
, what are the ways to achive above functionality?
推荐答案
引入工厂是为了支持为@JmsListener
带注释的POJO方法创建侦听器容器.
The factory was introduced to support the creation of listener containers for @JmsListener
annotated POJO methods.
如果不使用该机制,则可以继续直接定义DLMC.
If you are not using that mechanism, you can continue to define your DLMC directly.
编辑
使用@JmsListener
时,容器本身未注册为Bean,但可通过注册表Bean获得;您可以获得对该容器的引用,以便可以启动/停止等.
When using @JmsListener
, the containers are not registered as beans themselves, but are available using the registry bean; you can get a reference to the container so you can start/stop etc.
请参见JmsListenerEndpointRegistry的"nofollow> javadocs ,以了解如何通过id或全部来获取对容器的引用.
See the javadocs for the JmsListenerEndpointRegistry
for how to get references to the containers either individually by id, or all.
EDIT2
我不确定您在评论3中的意思;注册表包含所有容器,无论使用哪个容器工厂创建容器...
I am not sure what you mean in comment 3; the registry has all containers, regardless of which container factory was used to create the container...
@JmsListener(id="foo", destination="foo", containerFactory="one")
public void listen1(String payload) {
System.out.println(payload + "foo");
}
@JmsListener(id="bar", destination="bar", containerFactory="two")
public void listen2(String payload) {
System.out.println(payload + "bar");
}
如果使用configureListenerContainers()
以编程方式创建端点,则必须为它们提供容器而不是容器工厂.
If you are using configureListenerContainers()
to programmatically create endpoints, you have to provide them with containers not container factories.
这篇关于DefaultJmsListenerContainerFactory与DefaultMessageListenerContainer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!