【问题标题】:ActiveMQ with Spring Boot. Messages persistance is not working带有 Spring Boot 的 ActiveMQ。消息持久性不起作用
【发布时间】:2015-11-13 20:30:24
【问题描述】:

我想在 Spring Boot 应用程序中使用 ActiveMQ 作为嵌入式服务器。为了设置 ActiveMQ,我使用了以下教程:Spring Boot. Messaging with JMS. 我的应用程序将成为代理和消费者。有多个线程创建这样的消息:

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

我有另一个类,方法如下:

@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();
    }

在测试期间,我可以看到消息被生成和使用。 如您所见,message.acknowledge() 已被评论。所以我希望在重新运行我的应用程序后重新发送消息。然而它不会发生。

【问题讨论】:

    标签: java spring-boot activemq jmstemplate


    【解决方案1】:

    消息确认由容器自动处理,并在 onMessage() 成功执行后执行,(在您的情况下为receive()),

    所以即使你评论 message.acknowledge(); ,容器自己也会发送确认

    您可以查看以下链接以获取更多参考

    希望这会有所帮助!

    祝你好运!

    【讨论】:

    • @Loco 这回答了你的问题吗?
    猜你喜欢
    • 2015-08-22
    • 2019-01-27
    • 2016-02-02
    • 2017-06-11
    • 2019-04-02
    • 2016-01-27
    • 1970-01-01
    • 2014-01-17
    • 2018-09-07
    相关资源
    最近更新 更多