What's the standard wisdom and considerations for dividing up a message queue?
Assuming relatively small number of messages (< 1000/day), does it make sense to combine multiple message types into a single queue and have consumers use selectors to filter them? Or, should a single queue only handle a single message type?
A couple of possible considerations I can think of:
- At least in my li开发者_运维百科mited knowledge of ActiveMQ, it looks like Read/Write security is per queue. So message types that need different Read/Write permissions would need different queues.
- Message Selectors would seem to need a standard header value (MessageType: AbcMessage) to filter on
- An explosion of queues (> 10, > 100, > 1000?) seems to impact performance more than an explosion of messages
- A single message type per queue would seem to be easier to write client code for. Just process each message on the queue. If you want a different message type, subscribe to a different queue.
- ???
Any given MQ system should be able to handle many millions of messages in any given queue, I would not be concerned at all at voume.
I prefer queues that have distinct real-world meaning rather than worrying about selectors. I know there are real reasons to use selectors or to consume and re-queue, but I prefer to make the queues distinct and not worry about selection.
Since this wasn't really addressed and you asked about it in your question (and it was something I was searching for when I found this), I thought I could chime in on how I am able to filter messages on a single, heterogeneous queue by type.
If you look here, you will find a user-defined property is available on all messages called JMSType
. This is a String
and is empty by default. When you are sending messages, have your producer set this to an agreed upon value, such as map
or text
for example, and then, in your consumer, use a particular message selector depending on what kind of message you want to receive. Using the same examples, it would be JMSType = 'map'
or JMSType = 'text'
.
I was able to use this technique successfully with a Java producer and a C++ consumer using the ActiveMQ-CPP library.
精彩评论