开发者

JMS message listener design

What is better design

Is it better to have one listener and separate processing in this listener for two types of emssages.

Or to have two listeners for processing and separate it by header's?

e.g. for different type of class. or interfaces.

-----edit

Instead of using selectors. I can have let's say list of Handlers(interface) and just iterate through r开发者_JAVA百科egistered(via IOC) handlers and select the one which can handle message. It's separated as well but differently,what do you think is better?


Use multiple listeners.

Why would you want to write code that duplicates the existing capabilities of the technology you are already using. I use the word duplication here in only its simplest sense since JMS can support fairly complex decision making process in routing of your messages.

Other considerations are the ability to distribute the workload based on the selectors for each listeners. With multiple listeners you can configure the number of threads by message type and easily change that value as necessary. Of course you could do this yourself as well, but why would you?


I would prefer the object-oriented approach, with a separate listener for each message. That way I could add a new message by adding a new class class rather than having to modify the existing listener with more "if/else" code.

This would be an example of the Open/Closed Principle, one of Bob Martin's SOLID recommendations.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜