Skip to content

Latest commit

 

History

History

chapter-5-spring-eventbus

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

chapter-5-spring-eventbus project

This project illustrates how Spring Boot allows developers to consume and produce synchronous events by default.

To publish events, Spring Boot needs to create an event publisher for sending the event messages to listeners by injecting the ApplicationEventPublisher as well as using the publishEvent() API. Spring developers also need to create custom events that should extend ApplicationEvent. The custom events in Spring are synchronous by default so Spring developers need to create an ApplicationEventMulticaster in the configuration for handling asynchronous events or add an @Async annotation to the listener.

Running the application

You can run your Spring boot application:

./mvnw spring-boot:run

Then, you should see the published custom event:

Publishing custom event......
Received Spring Event: A test event message

Packaging and running the application

The application can be packaged using:

./mvnw package

It produces the chapter-5-spring-eventbus-0.0.1-SNAPSHOT.jar file in the target/ directory.

The application is now runnable using java -jar target/chapter-5-spring-eventbus-0.0.1-SNAPSHOT.jar.

Reference Documentation

For further reference, please consider the following sections:

Guides

The following guides illustrate how to use some features concretely: