Guava EventBus Spring
In last two tutorial you saw how to get started with Google Guava EventBus. In this I will show you how to integrate Guava EventBus with Spring framework. If you are seriously looking to integrate Guava EventBus to your project then I will suggest read my next Guava EventBus Spring advanced integration tutorial. Let’s get started and see first how to integrate EventBus with Spring.
- Create maven project name: EventBusSpringIntegration as below shown complete project structure:
As above you see we have main class which loads application context and two subscriber including DeadEventProcessor class where you can catch any unprocessed event.
- DeadEventProcessor.java: This class has been written to find if any event which got posted not have any subscriber. You could put debug point to see any event not processed caught here as I have included one event for testing:
SendPostThourghClass.java: This is sample class just to show how you could use classes to post event otherwise you could post any object as event:
- spring-context.xml: Main context file where you define all your configuration:
- MainApplication.java: Main class to test our application:
- That’s it. To validate run MainApplication.java as java application you will see below output:
- For more information please visit Google Guava EventBus official site here
Download Project: EventBusSpringIntegration