public interface MessageBus
_____________________ / (Context B) \ _________ _________ _________ | | | | | | | Client | <----> | Server | <----> | Client | |________| |________| |________| \_____________________/ (Context A)The diagram shows two clients federated within the messaging topology. The contexts indicate the scope by which direct communication is possible. In order to facilitate client-to-client communication, users must implement relay services in the server manually. Services always live on the bus with which they a registered. When a new registration occurs, the service becomes generally available across the entire context. This is accomplished by notifying the proximate bus-- in real-time--that a subscription has been created with a
BusCommand.RemoteSubscribe
command containing the subject that has just become routable. Likewise, when a subject is unsubscribed, an
BusCommand.RemoteUnsubscribe
is sent.
Creating a service subscription is straight-forward:
busInstance.subscribe("ServiceName",
new MessageCallback() {
public void callback(CommandMessage message) {
// do something.
}
}
);
The API for creating services is heterogeneous in both client and server code. The only semantic difference involves
obtaining an instance of the MessageBus which is done using the
ErraiBus.get()
method in client code,
and by default, is provided by the container using dependency injection in the server code. For example:
Modifier and Type | Method and Description |
---|---|
void |
addSubscribeListener(SubscribeListener listener)
Registers a subscription listener, which is fired whenever a new subscription is created.
|
void |
addUnsubscribeListener(UnsubscribeListener listener)
Registers an un-subscribe listener, which is fired whenever a subscription is cancelled.
|
void |
attachMonitor(BusMonitor monitor)
Attach a monitor to the bus.
|
boolean |
isSubscribed(String subject)
Returns true if there the specified subject has one or more listeners registered.
|
void |
send(Message message)
Transmits a message.
|
void |
send(Message message,
boolean fireListeners)
Transmits a message and may optionally supress message listeners from firing.
|
void |
sendGlobal(Message message)
Transmits the message to all directly-peered buses (global in relation to this bus only).
|
Subscription |
subscribe(String subject,
MessageCallback receiver)
Subscribe a listener to the specified subject.
|
Subscription |
subscribeLocal(String subject,
MessageCallback receiver)
Subscribe a listern locally, but do not advertise or make available the service to remote buses.
|
void |
unsubscribeAll(String subject)
Unsubscribe all listeners registered for the specified subject.
|
void sendGlobal(Message message)
message
- - The message to be sent.void send(Message message)
message
- void send(Message message, boolean fireListeners)
message
- fireListeners
- Subscription subscribe(String subject, MessageCallback receiver)
subject
- receiver
- Subscription subscribeLocal(String subject, MessageCallback receiver)
subject
- receiver
- void unsubscribeAll(String subject)
boolean isSubscribed(String subject)
subject
- void addSubscribeListener(SubscribeListener listener)
listener
- void addUnsubscribeListener(UnsubscribeListener listener)
listener
- void attachMonitor(BusMonitor monitor)
monitor
- Copyright © 2013-2015 JBoss, a division of Red Hat. All Rights Reserved.