简体   繁体   English

JMS消息侦听器设计

[英]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? 还是要有两个侦听器进行处理并将其按标题分开?

eg 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 registered(via IOC) handlers and select the one which can handle message. 我可以说一说Handlers(接口)列表,然后遍历已注册的(通过IOC)处理程序,然后选择一个可以处理消息的程序。 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. 我在这里仅以最简单的意义使用重复一词,因为JMS可以在路由消息时支持相当复杂的决策过程。

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. 这样,我可以通过添加新的类来添加新消息,而不必用更多的“ if / else”代码修改现有的侦听器。

This would be an example of the Open/Closed Principle, one of Bob Martin's SOLID recommendations . 这将是Bob Martin的SOLID建议之一“开放/封闭原则”的一个示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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