问题描述
我注意到我的Spring Boot JMS使用者正在成功使用消息,但是在Web控制台中,我看到使用者和生产者的入队和出队保持不变。可能是由于发送ACK引起的。
有人可以帮我弄清楚这个错误吗?我看到了几个建议使用Session.AUTO_ACKNowLEDGE ..我没有运气就尝试了同样的方法。
任何帮助将不胜感激。
JMS配置
@Configuration
public class ActiveMQConfiguration {
@Value("${activemq.broker-url}")
private String brokerUrl;
@Value("${activemq.topic}")
private String topic;
@Bean
public Topic activeMQ() {
return new ActiveMQTopic(topic);
}
@Bean
public ActiveMQConnectionFactory activeMQConnectionFactory() {
ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory();
activeMQConnectionFactory.setbrokerURL(brokerUrl);
return activeMQConnectionFactory;
}
@Bean
public jmstemplate jsmTemplate() {
jmstemplate jmstemplate = new jmstemplate(activeMQConnectionFactory());
jmstemplate.setDefaultDestinationName(topic);
return jmstemplate;
}
@Bean
public DefaultJmsListenerContainerFactory jmsListenerContainerFactory(
ActiveMQConnectionFactory connectionFactory) {
DefaultJmsListenerContainerFactory jmsListenerContainerFactory = new DefaultJmsListenerContainerFactory();
jmsListenerContainerFactory.setConcurrency("2");
// To set the ackNowledgement of the message when message is received
jmsListenerContainerFactory.setSessionAckNowledgeMode(Session.AUTO_ACKNowLEDGE);
jmsListenerContainerFactory.setSessionTransacted(true);
jmsListenerContainerFactory.setPubSubDomain(false);
jmsListenerContainerFactory.setConnectionFactory(connectionFactory);
return jmsListenerContainerFactory;
}
}
消费者
@Component
public class ActiveMQListener {
Gson gson = new Gson();
@JmsListener(destination = "TEST.TOPIC1")
public void consume(String message,@Header("messageType") String messageType) {
if(GreetingType.OFFLINE.equals(GreetingType.valueOf(messageType))) {
System.out.println("Hello World Offline");
}
if(GreetingType.WEB.equals(GreetingType.valueOf(messageType))) {
System.out.println("Hello World WEB");
}
if(GreetingType.MOBILE.equals(GreetingType.valueOf(messageType))) {
System.out.println("Hello World MOBILE");
}
System.out.println(gson.fromJson(message,Greeting.class));
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)