@Singleton
public abstract class EventBinder
extends java.lang.Object
Binds incoming CDI events to queues and outgoing CDI events to exchanges of a broker.
Inherit from this class and override its bindEvents() method to create bindings.
Queue example:
protected void bindEvents() {
bind(MyEventOne.class).toQueue("myQueueOne");
bind(MyEventTwo.class).toQueue("myQueueTwo").autoAck();
}
Exchange example:
protected void bindEvents() {
bind(MyEvent.class).toExchange("myExchange").withRoutingKey("myRoutingKey")
.withPublisherTransactions();
}
To initialize the event bindings, inject the instance of this class and call initialize().
In a web application, you would normally do this in a context listener on application startup
after your CDI framework was initialized.
| Modifier and Type | Class and Description |
|---|---|
class |
EventBinder.EventBindingBuilder |
class |
EventBinder.ExchangeBinding
Configures and stores the binding between an event class and an exchange.
|
class |
EventBinder.QueueBinding
Configures and stores the binding between and event class and a queue.
|
| Constructor and Description |
|---|
EventBinder() |
| Modifier and Type | Method and Description |
|---|---|
EventBinder.EventBindingBuilder |
bind(java.lang.Class<?> event)
Starting point for binding an event.
|
protected abstract void |
bindEvents()
Extend
EventBinder and implement this method to create the event bindings for your
application. |
void |
initialize()
Initializes the event binder and effectively enables all bindings created in
bindEvents(). |
protected abstract void bindEvents()
Extend EventBinder and implement this method to create the event bindings for your
application.
Binder example:
public class MyEventBinder extends EventBinder {
@Override
protected void bindEvents() {
bind(MyEvent.class).toExchange("my.exchange").withRoutingKey("my.routing.Key");
}
}
public void initialize()
throws java.io.IOException
Initializes the event binder and effectively enables all bindings created in
bindEvents().
Inject your event binder implementation at the beginning of your application's lifecycle and call this method. In web applications, a good place for this is a ServletContextListener.
After this method was successfully called, consumers are registered at the target broker for every queue binding. Also, for every exchange binding messages are going to be published to the target broker.
java.io.IOException - if the initialization failed due to a broker related issuepublic EventBinder.EventBindingBuilder bind(java.lang.Class<?> event)
Starting point for binding an event.
Binding fired events to be published to an exchange:
bind(MyEvent.class).toExchange("my.exchange");
Binding consuming from a queue to fire an event:
bind(MyEvent.class).toQueue("my.queue");
event - The event