Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
422 views
in Technique[技术] by (71.8m points)

activemq - How to handle situation when JMS queue becomes full?

I have created a queue. The producer publishes to JMS queue continuously. However, it takes consumers some time to process the message, and the queue gets full after some time.

How can this situation be handled both at producers side (which is a Java application) and on the JMS broker?

question from:https://stackoverflow.com/questions/65894536/how-to-handle-situation-when-jms-queue-becomes-full

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This is a classic problem in messaging.

Message production can exceed message consumption for a time, but consumption must catch back up eventually and the sooner the better in most cases. During this time the broker will act as a buffer to store the messages, but traditional message brokers like ActiveMQ are not designed to store large amounts of data (e.g. like a database). They are designed for large amounts of data to flow through with a relatively small amount of data stored in memory and on disk.

The bottom line is that if the queue becomes "full" then you either have to slow (or potentially stop) message production until consumers can catch up and clear space in the queue or you need to speed up consumers (e.g. by increasing the number of consumers). Producing and consuming are two sides of an equation that needs to stay balanced more or less.

For what it's worth, many protocols (e.g. AMQP) and client implementations provide automatic flow control to slow down (or stop) producers when necessary. Check your broker's documentation for configuration details.

If you find your use-case doesn't allow you to do either of these things then you probably shouldn't be using a message broker and should change to something like a database that is designed to just store data.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...