Member-only story
Publish & Consume Custome Events in Spring Boot
The main focus of event-driven programming is events. An event is an excellent tool for separating a consumer-recognized activity from a producer-triggered action. The model containing the concept of event-driven programming is also known as an asynchronous model. Using this approach you have the luxury to decouple different components of your application, which means instead of calling a method from another component you can just publish an event that the other component is consuming.
Getting Start
To start you will need to create your Event class which will be the medium of exchange between the publisher and consumer in your application. In order to create your custom event class you will need to extend ApplicationEvent
class if you are using the Spring version older than 4.2.
public class StudentLogEvent extends ApplicationEvent {
private String name;
public StudentLogEvent(Object source, String name) {
super(source);
this.name = name;
}
public String getName() {
return name;
}
}
To make it work by extending ApplicationEvent
you need to have the proper…