问题
When we design the application how to select Topic/Queue type implementation.
I am aware of,
a) If more than one consumer use the message then use Topic
b) If only one consumer then use Queue
Please provide any more points need to be considered?
For example, concurrency, message persistence, load balancing, anything else?
Thanks.
Rw
回答1:
That's not entirely true about if only one Consumer use a Queue.
We have a Java EE app where we rate insurance quotes. We have a RatingIn queue and a RatingOut queue. All our clients write to the RatingIn Queue and read from the RatingOut Queue. And we have probably near 300+ clients.
The trick with multiple clients accessing the same Queue to read from is using the correlationID in the message headers. Make it unique to the client and they only pick up their unique message. What we do is set this correlationID in the client to the message bound for RatingIn. Then the server picks up the property and writes to the message that it writes back to RatingOut. This preserves unique messages for unique clients, but without the need for 300+ queues (which would quickly become unmanageable at our company given our number of app server admins).
I think it has more to do with the publication method. If you wish to publish a message meant for only one Consumer, use a Queue. If you wish to publish a message meant for multiple Consumers, but without generating a ton of messages (and you may also not know how many Consumers you have to publish for), then use a Topic.
来源:https://stackoverflow.com/questions/9529220/how-to-select-topic-vs-queue