简体   繁体   English

Java事件处理程序命名约定

[英]Java Event Handler Naming Convention

I have been struggling with this and cannot come up with a good convention to name event handlers. 我一直在努力解决这个问题,并且无法提出一个很好的约定来命名事件处理程序。 I have a project (spring integration) which has a inbound channel adaptor listening to various types of events. 我有一个项目(spring集成),它有一个入站通道适配器,可以监听各种类型的事件。 Events received are passed to a Router which then publishes it to a channel (a different channel for each type of event). 收到的事件将传递给路由器,然后路由器将其发布到一个频道(每种类型事件的不同频道)。 We have a service activator listening to these channels which then consumes these events. 我们有一个服务激活器监听这些通道然后消耗这些事件。

This is the naming convention we have now... For example, an event ORDER_CREATED is published to a channel named 'order-created-channel'. 这是我们现在的命名约定...例如,事件ORDER_CREATED被发布到名为'order-created-channel'的通道。 On the other end of the channel we have a service activator named OrderCreatedEventHandler. 在通道的另一端,我们有一个名为OrderCreatedEventHandler的服务激活器。 The OrderCreatedEventHandler sends a notification to the buyer for who the order is created. OrderCreatedEventHandler向买方发送通知,告知订单的创建者。 So the Event Handlers are named based on the type of event they are consuming/handling and not the activity they perform. 因此,事件处理程序根据它们正在使用/处理的事件类型而不是它们执行的活动来命名。 But now I have a problem... I want to change the 'order-created-channel' to a publish subscribe channel and I want 2 service activators listening on it. 但现在我有一个问题...我想将'订单创建频道'更改为发布订阅频道,我想要2个服务激活器监听它。 One of the service activators should send a notification to the buyer and the other one should create an invoice for that order. 其中一个服务激活器应该向买方发送通知,另一个应该为该订单创建发票。

So it got me thinking... Should I not have those service activators end with the word 'EventHandlers'? 所以它让我思考......我不应该让那些服务激活器以“EventHandlers”这个词结束吗? Should I name them on the activity they are performing? 我应该为他们正在进行的活动命名吗? Is there any convention for naming channels and beans that handle events? 是否存在命名处理事件的通道和bean的约定?

There's no general convention for naming; 命名没有一般惯例; it's up to your organization. 这取决于你的组织。

My only general recommendation is to give endpoints an id (rather than omitting and letting the framework name the endpoint). 我唯一的一般建议是给端点一个id (而不是省略并让框架命名端点)。 Beyond that, it's up to you. 除此之外,还取决于你。

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

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