What is the use of processingGroup?

What is the use of processingGroup annotation?

One possible use case might involve specifying the order in which event handlers are processed. Assume you have the following code example.

The first class could be annotated with:

@Component
@ProcessingGroup(value = "some-unique-name")
@Order(1)
public class FirstHandlers{

   @EventHandler
   private void doSomething(SomeEvent event){
      ...
   }

}

The second class could be annotated at class level with:

@Component
@ProcessingGroup(value = "some-unique-name")
@Order(100)
public class SecondHandlers{

   @EventHandler
   private void doSomethingElse(SomeOtherEvent event){
      ...
   }

}

Doing so ensures event handlers in the FirstHandlers class are always called before the ones in the SecondHandlers class.

Surely there are some other use case as well. You could also check the documentation for more details.

2 Likes

From the reference docs:

So the processing group “provides non-functional configuration”. From my perspective the main thing here would be:

  • creating specific processing groups for specific event handlers (overriding the default of one processing group per package)
  • setting whether the processing group is a subscribing event processor or a tracking event processor.

In practice there is only one value you can give to the annotation (the name of the group):

image

And you need to configure it either using properties or through configuration in Java.

You can see usage of it in my example app:

This is all in addition to the points raise in the excellent answer from @KDW

1 Like

Not sure about other ‘messaging’ type plugins but it’s also vital for consuming kafka messages that are not auto-routed. When you create a subscriber, it needs to be registered with the event processor where the processor name is specified. In addition to this (and not specifically documented) is that you then need to register the processor against a processor group name, e.g.

// ... kafka subscriber set-up ommitted 
eventProcessingConfigurer.registerTrackingEventProcessor("processorName", configuration -> kafkaSubscriber);
eventProcessingConfigurer.assignProcessingGroup("myKafkaEventGroup", "processorName");
// ...

You can then create an event handler that processes incoming kafka events:-

@Component
@ProcessingGroup(value = "myKafkaEventGroup")
public class MyKafkaEventHandler {

   @EventHandler
   private void on(KafakEvent event){
      ...
   }

}

Without registering the subscriber against a processor/group and then annotating your event handler the events are simply dropped, at least from my experimenting anyway.