简体   繁体   中英

How distinguish different JMS text messages from the same queue?

I have an AMQ queue I'm connecting to. The publisher is sending JMS TextMessage. The messages are of different types: foo-updated, bar-updated, baz-updated etc, all on the single queue.

The payload/message body is JSON for all types, and their schemas have significant overlap (but no direct type information).

The publishing team said "search the string/text of the message for foo, and if it's there, it's a foo-updated message".

That sounds wrong.

There may be header information in the JMS message I can use (I'm exploring that), but assuming I can influence (but not necessarily change anything), what's the best way to handle this ?

使用JMS消息选择器请参阅: 消息选择器

If you have influence over using JMS topics, you should use that. Just like REST URLs you could use topics to indicate resources and actions on those: foo/create, foo/update, bar/update Then the JMS Broker can help you to efficiently route different messages to difference consumers. Eg one consumer subscribing to foo/* another to */update

If you are stuck with a queue, the publisher should add additional information as header properties, for example type=foo and action=update. Then your consumer can specify JMS selectors like "action = 'update'" to receive only some of the messages.

Otherwise you are actually stuck with looking into the content :-(

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM