我使用qpid amqp-1-0-client和相关的jar创建消费者以连接到Azure服务总线。我能够连接到Azure队列并接收消息,但问题是我从队列中多次收到相同的消息,尽管我在处理消息之前已经确认了它。此外,大多数时候我的消息都会被移到DLQ中。
例如,如果队列中有500条消息,则覆盖MessageListener.onMessage()的onMessage()方法执行的次数超过500次。并且差不多有200条消息被推入DLQ。我正在从队列中读取消息并将其存储在数据库中。这些数字总是不一样。为了在DB中读取和存储消息,我的应用程序需要600ms。 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>
请帮忙。
答案 0 :(得分:0)
您正在使用不受支持的旧版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>