Guava EventBus integration

Example of guicey-eventbus extension usage.

Example source code

The eventbus extension is used for:

  • automatic listeners registration
  • binding eventbus instance in guice context (for publication)
  • printing available listeners to console


An additional dependency is required:

implementation 'ru.vyarus.guicey:guicey-eventbus:5.1.0-2'


guicey-eventbus version could be managed with BOM

Register eventbus bundle:

      .bundles(new EventBusBundle())


Events are simple POJOs. Create event classes with properties you need (or without everything):

public class FooEvent {
    private String something;

    public FooEvent(String something) {
        this.something = something;

    public void getSomething() {
        return something;

Use event hierarchies, if appropriate:

public abstract class BaseEvent {}

public class FooEvent extends BaseEvent {}

public class BarEvent extends BaseEvent {}

For simplicity, properties are omitted.


Inject the eventbus instance to enable publication:

@Inject EventBus eventbus;

public void someAction() {
    ... FooEvent());


Listener methods must be annotated with @Subscribe and contain only one parameter of the target event type:

public void onFooEvent(FooEvent event) {}

// listen for all events of type (FooEvent, BarEvent)
public void onMultipleEvents(BaseEvent event) {}


Listener methods will only be registered for "known" guice beans. That means any extension or manually declared guice bean (using module) or bean created with guice AOT (because it's declared as dependency for other bean) will be searched for listener methods.

See a complete example