问题描述
我有一个DefaultMessageListenerContainer,其配置如下:
I have a DefaultMessageListenerContainer configured as follows:
DefaultMessageListenerContainer container = new DefaultMessageListenerContainer();
container.setConcurrentConsumers(4);
container.setConnectionFactory(connectionFactory);
container.setDestinationName(String.format("Consumer.%s.VirtualTopic.%s", group, topic));
container.setSessionAcknowledgeMode(Session.CLIENT_ACKNOWLEDGE);
container.setSessionTransacted(true);
container.setMessageListener(new DelegatingMessageListener(listener, messageMapper, event));
container.start();
消息容器从不接收消息,并且永远不会调用我的消息侦听器.如果我只是将DefaultMessageListenerContainer切换为SimpleMessageListenerContainer,则其他所有操作均保持不变-但在失去连接后,SimpleMessageListenerContainer无法恢复
The message container never receives messages, and my message listener is never invoked. Leaving all else the same, if I just switch DefaultMessageListenerContainer to SimpleMessageListenerContainer, it works - but SimpleMessageListenerContainer doesn't recover after a connection loss
日志中没有错误,几乎没有任何相关消息.有人有任何理由为什么会发生这种情况?
There are no errors in the logs, and hardly any relevant messages. Does anyone have any reasons for why this may be happening?
推荐答案
在Java中构造容器时(在Spring应用程序上下文之外),您需要在start()
之前调用afterPropertiesSet()
.
When constructing the container in Java (outside a Spring application context), you need to invoke afterPropertiesSet()
before start()
.
上下文自动为Spring Bean完成.
The context does that automatically for Spring beans.
这篇关于DefaultMessageListenerContainer不接收消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!