简体   繁体   中英

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. 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'. On the other end of the channel we have a service activator named OrderCreatedEventHandler. The OrderCreatedEventHandler sends a notification to the buyer for who the order is created. 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. 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'? Should I name them on the activity they are performing? Is there any convention for naming channels and beans that handle events?

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). Beyond that, it's up to you.

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