3

我已经创建了带有 2 个节点的 Artemis 集群并成功连接到我的 Spring-boot 应用程序(github链接),实现基于clustered-static-discovery

现在我正在用它测试持久订阅有一些奇怪的行为我产生了 5 条消息并且只消耗了 3 条

   @Bean
    public MessageListenerContainer listenerContainer1(@Qualifier("connectionFactory") ConnectionFactory connectionFactory, Consumer consumer, SimpleMessageConverter messageConverter, @Qualifier("topic") Topic topic) {
        DefaultMessageListenerContainer defaultMessageListenerContainer =
                new DefaultMessageListenerContainer();


    @Bean("connectionFactory")
    public ConnectionFactory activeMQJMSConnectionFactory(@Qualifier("amqTransportConfiguration") TransportConfiguration transportConfiguration) throws JMSException {
        ActiveMQJMSConnectionFactory activeMQJMSConnectionFactory =
                new ActiveMQJMSConnectionFactory( false, transportConfiguration);
        activeMQJMSConnectionFactory.setPassword("admin");
        activeMQJMSConnectionFactory.setUser("admin");
        activeMQJMSConnectionFactory.setClientID("admin");
        return activeMQJMSConnectionFactory;
    }
defaultMessageListenerContainer.setConnectionFactory(connectionFactory);
    defaultMessageListenerContainer.setDestination(topic);
    defaultMessageListenerContainer.setMessageListener(consumer);
    defaultMessageListenerContainer.setSessionAcknowledgeMode(1);
    defaultMessageListenerContainer.setSubscriptionName("mySub");
    defaultMessageListenerContainer.setSubscriptionDurable(true);
    defaultMessageListenerContainer.setMessageConverter(messageConverter);
    return defaultMessageListenerContainer;
}

这是整个配置

我已经通过http://localhost:816i/hawtio/ wrb UI for artemis 发现生产者只收到 5 个消息中的 5 个

(消息负载平衡-> 严格)

我在这里做错了什么?

4

2 回答 2

4

The problem was in Artemis dependency, existing used dependency somehow unable to handle PubSab connection with the cluster, I have not found any error logs for the missing message. I have changed dependency

<dependency>
        <groupId>org.apache.activemq</groupId>
        <artifactId>artemis-jms-client-all</artifactId>
        <version>2.2.0</version>
    </dependency>

Now it's working.

于 2017-12-15T19:16:29.893 回答
0

Looks like the problem is about the code. Two different durable subscriptions share the same durable subscription name. I was able to pass your test after using unique subscription name for each MessageListenerContainer instance:

//listener container (1)
defaultMessageListenerContainer.setDurableSubscriptionName("sub1");

/* --- */

//listener container (2)
defaultMessageListenerContainer.setDurableSubscriptionName("sub2");
于 2017-12-14T10:53:02.473 回答