Please advise me what pattern to use in following case:
I have a Java/Spring Boot application. There is a component with @KafkaListener method which receives Kafka Messages on CRUD of various subject notifications, grouped in a bigger logical groups/types/topics (e.g. topic “humans” notify on “students”, “teachers”, topic “devices” on “computers”, “phones”, etc – there is a type
field in each message).
On receiving Kafka messages, I need to notify other (possible multiple) Spring @Component-s, i.e. Java classes that CRUD message was received, and they have to process it on their own business logic requirements.
As an options may be:
-
Spring ApplicationEvent sub-classes, containing all necessary data (DTO) which will be published (broadcast) and all interested components will subscribe to that events and will process messages if interested.
-
Declare special interfaces with methods like
onSomeSpecificMessage(specificMessage)
and all interested component will implement those interfaces, but publisher will inject lists of those interfaces and will notify each o them one by one (e.g. interfacesList.forEach(msg -> onMsg..(msg)) – Is it Observer pattern? -
Your Option?
2