我在非持久订阅服务器上的循环中调用JMSTemplate.receive(),如果我向该主题发送许多消息,则某些消息将在接收方丢失。丢失的消息会在返回JMSTemplate.receive()之后但在下一次调用JMSTemplate.receive()之前发生。
这是预期的行为吗?还是我出了什么问题?
我使用以下代码:
@Bean
public ConnectionFactory jmsConnectionFactory() {
try {
ConnectionFactory target = (ConnectionFactory) jndiTemplate().lookup("cn=mqtest-cf");
CachingConnectionFactory factory = new CachingConnectionFactory(target);
factory.setClientId("testClientId");
return factory;
} catch (NamingException e) {
throw new RuntimeException("Failed to lookup connection factory", e);
}
}
@Bean
public JmsTemplate jmsTopicTemplate() {
JmsTemplate t = new JmsTemplate(jmsConnectionFactory());
t.setDestinationResolver(destinationResolver());
t.setReceiveTimeout(5000);
t.setDefaultDestinationName(DEST_TOPIC);
t.setPubSubDomain(true);
return t;
}
for(int i=0; i<1000; i++) {
String msg = (String) jmsTopicTemplate.receiveAndConvert();
System.out.println(msg);
}