Skip to content
Advertisement

ActiveMQ Artemis queue deleted after shutdown of consuming client

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: put message

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

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

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

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.");
    }

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?

Advertisement

Answer

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:

  • auto-create-queues
  • auto-delete-queues
  • auto-create-addresses
  • auto-delete-addresses

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

  • auto-delete-queues-delay
  • auto-delete-queues-message-count
  • auto-delete-addresses-delay

See the documentation for more details.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement