【问题标题】:Azure with Spring JMS receives same messages are received multiple times and messages are moved into DLQ带有 Spring JMS 的 Azure 接收多次接收相同的消息并将消息移动到 DLQ
【发布时间】:2017-08-09 14:28:12
【问题描述】:

我正在使用 qpid amqp-1-0-client 和相关 jars 创建消费者以连接到 Azure 服务总线。我能够连接到 Azure 队列并接收消息,但问题是我从队列中多次收到相同的消息,尽管我在处理消息之前确认了它。而且大多数时候我的消息都被移到了 DLQ 中。

例如,如果我有 500 条消息在队列中,我的 onMessage() 方法会覆盖 MessageListener.onMessage() 被执行超过 500 次。将近 200 条消息被推送到 DLQ。我正在从队列中读取消息并将其存储在数据库中。这些数字并不总是相同的。为了在数据库中读取和存储消息,我的应用程序需要 600 毫秒。 PFB 我的代码,其中包含用于连接到 Azure 的配置

@Configuration
public class AzureConfiguration {
@Bean
public ConnectionFactory jmsConnectionFactory() {
    CachingConnectionFactory cachingConnectionFactory = null;
    try {
        ConnectionFactoryImpl a = ConnectionFactoryImpl.createFromURL(url);
        a.setMaxPrefetch(0);
        a.setSyncPublish(true);
        cachingConnectionFactory = new CachingConnectionFactory(a);
        cachingConnectionFactory.setReconnectOnException(true);
        cachingConnectionFactory.setClientId(applicationName);
        exceptionListener.setCachedConnFactory(cachingConnectionFactory);
    } catch (MalformedURLException e) {
    }
    return cachingConnectionFactory;
}
@Bean
public MessageListenerContainer getContainer() {
    DefaultMessageListenerContainer container = new DefaultMessageListenerContainer();
    container.setConnectionFactory(jmsConnectionFactory());
    container.setDestinationName(queueName);
    container.setMessageListener(messageConsumer);
    container.setConcurrency(concurrency);
    exceptionListener.setContainer(container);
    container.setExceptionListener(exceptionListener);
    container.setAutoStartup(true);
    container.setSessionAcknowledgeMode(2);
    return container;
}

}

和我的依赖: <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jms</artifactId> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> <version>3.5</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.apache.geronimo.specs</groupId> <artifactId>geronimo-jms_1.1_spec</artifactId> <version>1.1.1</version> </dependency> <dependency> <groupId>org.apache.qpid</groupId> <artifactId>qpid-amqp-1-0-client</artifactId> <version>0.30</version> </dependency> <dependency> <groupId>org.apache.qpid</groupId> <artifactId>qpid-amqp-1-0-client-jms</artifactId> <version>0.30</version> </dependency> <dependency> <groupId>org.apache.qpid</groupId> <artifactId>qpid-amqp-1-0-common</artifactId> <version>0.30</version> </dependency>

请帮忙。

【问题讨论】:

    标签: java azure azureservicebus azure-servicebus-queues qpid


    【解决方案1】:

    您使用的是旧版 AMQP 1.0 JMS 客户端,该客户端不受支持且未实现当前的 AMQP JMS 映射规范。它不起作用并不令人惊讶。你应该有更好的运气使用更新的,现在只支持来自 Qpid 的 AMQP JMS 客户端,你可以得到here

    <dependency>
      <groupId>org.apache.qpid</groupId>
      <artifactId>qpid-jms-client</artifactId>
      <version>0.21.0</version>
    </dependency>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-01-01
      • 2011-12-12
      • 2010-10-30
      • 1970-01-01
      • 2014-01-29
      • 2012-01-19
      • 2011-10-09
      • 2015-08-16
      相关资源
      最近更新 更多