public class EventBusby extends Object implements Jooby.Module
EventBus is an open-source library for Java using the publisher/subscriber pattern for loose coupling. EventBus enables central communication to decoupled classes with just a few lines of code – simplifying the code, removing dependencies, and speeding up app development.
{
use(new EventBusby()
.register(new MySubscriber())
);
post("/message", req -> {
EventBus bus = require(EventBus.class);
MessageEvent event = req.body(MessageEvent.class);
bus.post(event);
});
}
EventBus module supports Guice subscribers:
{
use(new EventBusby()
.register(MySubscriber.class)
);
}
Here the MySubscriber class will be provisioned by Guice.
Jooby uses the default EventBus: EventBus.getDefault(), you can provide a custom
EventBus at creation time:
{
use(new EventBusby(() -> {
return EventBus.builder()
.logNoSubscriberMessages(false)
.sendNoSubscriberEvent(false)
.build();
}));
}
That's all! Happy coding!!
| Constructor and Description |
|---|
EventBusby()
Creates a new EventBus using the default EventBus.
|
EventBusby(Function<com.typesafe.config.Config,org.greenrobot.eventbus.EventBus> factory)
Creates a new EventBus using the given factory.
|
EventBusby(Supplier<org.greenrobot.eventbus.EventBus> factory)
Creates a new EventBus using the given factory.
|
| Modifier and Type | Method and Description |
|---|---|
void |
configure(Env env,
com.typesafe.config.Config conf,
com.google.inject.Binder binder) |
EventBusby |
register(Class subscriber)
Register an event subscriber.
|
EventBusby |
register(Object subscriber)
Register an event subscriber.
|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitconfigpublic EventBusby(@Nonnull Function<com.typesafe.config.Config,org.greenrobot.eventbus.EventBus> factory)
factory - EventBus factory.public EventBusby(@Nonnull Supplier<org.greenrobot.eventbus.EventBus> factory)
factory - EventBus factory.public EventBusby()
public EventBusby register(@Nonnull Object subscriber)
subscriber - Event subscriber.public EventBusby register(@Nonnull Class subscriber)
subscriber - Event subscriber.public void configure(Env env, com.typesafe.config.Config conf, com.google.inject.Binder binder)
configure in interface Jooby.ModuleCopyright © 2019. All rights reserved.