消费客户端关闭后,ActiveMQ Artemis 队列被删除 [英] ActiveMQ Artemis queue deleted after shutdown of consuming client

查看:40
本文介绍了消费客户端关闭后,ActiveMQ Artemis 队列被删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 JMS 和 ActiveMQ Artemis 的新手,我遇到了以下问题.我通常将来自应用程序生产者的消息放入 requests 队列中:

I am newbie on JMS and ActiveMQ Artemis, and I have the following problem. I put a message in a requests queue normally from an application producer:

从其他应用程序消费者那里之后,我尝试使用该消息.这样做没有问题.

After that from other application consumer I tried to consume that message. That works without problems.

但是当我关闭应用程序使用者时,request 队列被无故删除.

But when I shutdown the application consumer the request queue was deleted for no reason.

我的应用程序使用者是使用 Spring Boot 构建的,如下所示:

My application consumer was build with Spring Boot as follows:

@SpringBootApplication
public class ProcessorClaimsApplication {

    public static void main(String[] args) {
        SpringApplication.run(ProcessorClaimsApplication.class, args);
    }

}

@EnableJms
@Configuration
public class ProcessorClaimsConfig {
    private static final Logger LOGGER = LoggerFactory.getLogger(ProcessorClaimsConfig.class);
    private static final String ORDER_ID = "orderId";
    private static final String APPROVED = "approved";
    private static final String APPROVERS = "approvers";
    private static final String APPOVER_INFO_SEPARATOR = ":";
    private static final String APPROVERS_SEPARATOR = ";";

    @Autowired
    private AS2Service as2Service;

    @Autowired
    private EnsuranceService ensuranceService;

    ...

    @Transactional
    @JmsListener(destination = "requests", selector = "JMSType = 'PAYMENTORDERAPPROVALRESPONSE'")
    public void processZMessageResponse(MapMessage message) {
        try {
            LOGGER.debug("Incoming message found JMSCorrelationID {}, orderId {}", message.getJMSCorrelationID(),
                    message.getStringProperty(ORDER_ID));
            boolean approved = (Boolean) message.getObject(APPROVED);
            String approvers = (String) message.getObject(APPROVERS);
            LOGGER.debug("Sending resolution to Ensurance");
            ensuranceService.sendResolution(Long.valueOf(message.getJMSCorrelationID()),
                    message.getStringProperty(ORDER_ID), approved, approvers);
        } catch (Exception e) {
            LOGGER.error("The is an error processing the message: {}" + e.getMessage());
            e.printStackTrace();
        }
    }
}

顺便说一句,当应用程序生产者将消息发送到 ActiveMQ Artemis 时,原始 requests 队列被创建,这是通过 JMSTemplate 完成的,如下所示:

BTW, the original requests queue was created when the application producer sent the message to ActiveMQ Artemis and this was done with JMSTemplate as follow:

public void pushResolution(String jmsCorrelationID, final String paymentOrderId, 
        final String paymentOrderNumber, final String paymentOrderType, Map<String, Object> data) {
        this.jmsTemplate.send(requestsQueue, new MessageCreator() {

            @Override
            public Message createMessage(Session session) throws JMSException {
                MapMessage message = session.createMapMessage();
                for (String key : data.keySet()) {
                    message.setObject(key, data.get(key));
                }
                message.setJMSCorrelationID(jmsCorrelationID);
                message.setJMSType(MessageTypeEnum.PAYMENTORDERAPPROVALRESPONSE.name());
                message.setStringProperty("orderId", paymentOrderId);
                message.setStringProperty("orderNumber", paymentOrderNumber);
                message.setStringProperty("orderType", paymentOrderType);
                return message;
            }
            
        });

        LOGGER.debug("Pushed Payment Order Response in Queue successfully.");
    }

如果我关闭应用程序生产者,requests 队列不会被删除.仅当我使用 @JMSListener 关闭应用程序使用者时,才会删除队列.

If I shutdown the application producer the requests queue is not deleted. The queue is only deleted when I shutdown the application consumer using @JMSListener.

请帮帮我.也许我错过了一些理解或参数?

Please help me. Maybe I miss some understanding or parameter?

推荐答案

您所观察到的是意料之中的,因为这是 ActiveMQ Artemis 的默认行为.地址和队列会自动创建和删除.地址和队列是为了响应客户端发送消息或客户端创建消费者而创建的.一旦队列中没有更多消息并且最后一个消费者断开连接,队列将被删除,因为它不再需要.当没有更多队列绑定到一个地址时,它也会被删除.如有必要,将重新创建这些资源.

What you're observing is expected as this is the default behavior of ActiveMQ Artemis. Addresses and queues are automatically created and deleted. Addresses and queues are created in response to a client sending a message or a client creating a consumer. Once there are no more messages in the queue and the last consumer disconnects the queue is removed as it's no longer needed. When there are no more queues bound to an address then it is removed as well. These resources will be re-created again if necessary.

您可以使用以下地址设置来控制此行为:

You can control this behavior with the following address settings:

  • 自动创建队列
  • 自动删除队列
  • 自动创建地址
  • 自动删除地址

您可以使用以下地址设置微调行为:

You can fine tune the behavior with the following address settings:

  • 自动删除队列延迟
  • 自动删除队列消息计数
  • 自动删除地址延迟

参见 文档 了解更多详情.

See the documentation for more details.

这篇关于消费客户端关闭后,ActiveMQ Artemis 队列被删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆