简体   繁体   English

带有Spring Boot的ActiveMQ。 邮件持久性不起作用

[英]ActiveMQ with Spring Boot. Messages persistance is not working

I want to use ActiveMQ within Spring Boot app as embedded server. 我想在Spring Boot应用程序中使用ActiveMQ作为嵌入式服务器。 To setup ActiveMQ I used following tutorial: Spring Boot. 要设置ActiveMQ,我使用了以下教程: Spring Boot。 Messaging with JMS. 使用JMS进行消息传递。 My app will be the broker and the consumer. 我的应用将是经纪人和消费者。 There are multiple threads creating messages like this: 有多个线程创建如下消息:

@Autowired
private JmsTemplate jmsTemplate;
.......
MessageCreator messageCreator = session -> session.createObjectMessage(transactionNotificationData);
                        jmsTemplate.setSessionAcknowledgeMode(Session.CLIENT_ACKNOWLEDGE);
                        jmsTemplate.send(QUEUE, messageCreator);

I have another class with following method: 我有另一个使用以下方法的类:

@JmsListener(destination = QUEUE)
public void receive(Message message) throws IOException {
    brokerService.getPersistenceAdapter();
    try {
        if (message instanceof ObjectMessage) {
            ObjectMessage objMessage = (ObjectMessage) message;
            NotificationData notification = (NotificationData) objMessage.getObject();
            LOG.info("Received <" + notification.notification + ">");
            ...... do some stuff ........
//            message.acknowledge();
        }
    } catch (JMSException e) {
        e.printStackTrace();
    }

During the tests I can see the messages are produced and consumed. 在测试期间,我可以看到消息的产生和使用。 As you can see message.acknowledge() is commented. 如您所见, message.acknowledge()已注释。 So I expect the message will be redelivered after rerun of my app. 因此,我希望在重新运行我的应用程序后重新发送邮件。 However it doesn't happen. 但是这不会发生。

Message Acknowledgement is automatically handled by the container and it executes after the onMessage() is successfully executed,(receive() in your case), 消息确认由容器自动处理,并在成功执行onMessage()后执行(在您的情况下为receive()),

so even when you comment message.acknowledge(); 因此,即使您评论message.acknowledge(); , container on its own sends the acknowledgement ,容器自行发送确认

you can have a look at following link for more reference 您可以查看以下链接以获取更多参考

Hope this helps! 希望这可以帮助!

Good luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM