我使用JMS API有一个Spring Boot Microservice来消费ActiveMQ队列的消息。
我当前的问题是微服务经常失去其作为消费者的订阅。我想创建一种逻辑,以不断检查消费者的状态并在丢失时应用重试策略。
是否有任何方法可以确认订阅状态为消费者或访问每个队列的消费者数量?
值得注意的是,微服务是消费者而不是生产者。
I have a Spring Boot microservice using the JMS API to consume messages from an ActiveMQ queue.
My current issue is that the microservice often loses its subscription as consumer. I'd like to create a logic to constantly check the status of the consumer and apply a retry strategy when lost.
Is there any way to confirm the status of a subscription as a consumer or to access the number of consumers per queue?
It's worth noting that the microservice serves as consumer and not a producer.
发布评论
评论(1)
如果您同时消费消息(例如,
javax.jms.messageconsumer.receive()
),连接存在问题,则应抛出异常。当抛出例外时,您可以适当地实施重试策略。如果您是异步消费的消息(即使用 )然后,您应该设置 exceptionListener 在
javax.jms.connection
捕获任何例外,并适当实施您的重试策略。If you're consuming the message synchronously (e.g. via
javax.jms.MessageConsumer.receive()
) and there is a problem with the connection then an exception should be thrown. When an exception is thrown you can implement your retry strategy as appropriate.If you are consuming messages asynchronously (i.e. using a
MessageListener
) then you should set anExceptionListener
on thejavax.jms.Connection
to catch any exception and implement your retry strategy as appropriate.