gpt4 book ai didi

java - 使用 Spring JMS 的 Azure 多次接收相同的消息,并将消息移至 DLQ

转载 作者:行者123 更新时间:2023-12-02 07:28:58 24 4
gpt4 key购买 nike

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

例如,如果我的队列中有 500 条消息,则覆盖 MessageListener.onMessage() 的 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>

请帮忙。

最佳答案

您正在使用旧版 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>

关于java - 使用 Spring JMS 的 Azure 多次接收相同的消息,并将消息移至 DLQ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42867546/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com