ActiveMQ Artemis 主题监听器无法使用 Spring @JmsListener 接收消息

问题描述 投票:0回答:1

我有一个使用配置创建的主题

@Bean
public ActiveMQTopic sampleTopic(){
    return new org.apache.activemq.artemis.jms.client.ActiveMQTopic("topic1");
}

监听器配置是这样的:

@Bean   
public JmsListenerContainerFactory<DefaultMessageListenerContainer> topicJmsListenerContainerFactory(ConnectionFactory connectionFactory) {
    DefaultJmsListenerContainerFactory returnValue = new DefaultJmsListenerContainerFactory();
    returnValue.setConnectionFactory(connectionFactory);
    returnValue.setSubscriptionShared(true);
    returnValue.setSubscriptionDurable(true);
    returnValue.setPubSubDomain(Boolean.TRUE);
    return returnValue;
}

我正在向该主题发送消息。发件人看起来像这样:

jmsTemplate.convertAndSend(sampleTopic, jsonMessage, m -> {
    m.setStringProperty("typ", "new");
    m.setStringProperty("sender", "abc");

    return m;
});

效果很好。我可以在 Artemis 控制台中看到该消息。

我是这样配置监听器的。

public class TopicReceiver {
    @JmsListener(destination = "topic1",
                 containerFactory = "topicJmsListenerContainerFactory",
                 subscription = "sub _new",
                 selector = "type = 'new' and sender = 'abc'")
    @Transactional
    public void onMessageKundeAbholauftragNew(String payload) {
        System.out.println(payload);
    }
}

但是监听器中没有接收到消息。有人可以帮忙吗?我还需要配置什么吗?

此外,我注意到消息出现在 Anycast-> topic1 下。多播下的“新”订阅表示消息为零。所以我想不知何故该消息没有路由到订阅?还是别的什么?

spring-jms activemq-artemis
1个回答
0
投票

您正在发送带有属性

typ
且值为
new
的消息,但您的选择器正在寻找
type

此外,您的

subscription
@JmsListener
参数是
sub _new
。这几乎肯定不应该有空格,而应该是
sub_new

© www.soinside.com 2019 - 2024. All rights reserved.