eneter.messaging.nodes.broker
Interface IDuplexBrokerClient

All Superinterfaces:
IAttachableDuplexOutputChannel

public interface IDuplexBrokerClient
extends IAttachableDuplexOutputChannel

Publishes and subscribes messages in the broker. The broker client is the component which interacts with the broker. It allows to publish messages via the broker and to subscribe for desired messages in the broker.

The following example shows how to subscribe a message in the broker:

 // Create the broker client.
 IDuplexBrokerFactory aBrokerFactory = new DuplexBrokerFactory();
 IDuplexBrokerClient aBrokerClient = aBrokerFactory.createBrokerClient();
 
 // Register handler to process subscribed messages from the broker.
 aBrokerClient.brokerMessageReceived().subscribe(myMessageHandler);
 
 // Attach output channel and be able to communicate with the broker.
 // E.g. if the broker communicates via TCP. 
 IMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory();
 IDuplexOutputChannel anOutputChannel = aMessaging.createDuplexOutputChannel("tcp://127.0.0.1:9843/");
 aBrokerClient.attachDuplexOutputChannel(anOutputChannel);
 
 // Now when the connection with the broker is establish so we can subscribe for
 // messages in the broker.
 // After this call whenever somebody sends the message type 'MyMessageType' into the broker
 // the broker will forward it to this broker client and the message handler
 // myMessageHandler will be called.
 aBrokerClient.subscribe("MyMessageType");
  
 
 

The following example shows how to publish a message via the broker:
 // Create the broker client.
 IDuplexBrokerFactory aBrokerFactory = new DuplexBrokerFactory();
 IDuplexBrokerClient aBrokerClient = aBrokerFactory.createBrokerClient();
 
 // Attach output channel and be able to communicate with the broker.
 // E.g. if the broker communicates via TCP. 
 IMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory();
 IDuplexOutputChannel anOutputChannel = aMessaging.createDuplexOutputChannel("tcp://127.0.0.1:9843/");
 aBrokerClient.attachDuplexOutputChannel(anOutputChannel);
 
 // Now when the connection with the broker is establish so we can publish the message.
 // Note: the broker will receive the message and will forward it to everybody who is subscribed for MyMessageType.
 aBrokerClient.sendMessage("MyMessageType", "Hello world.");
  
 
 


Method Summary
 Event<BrokerMessageReceivedEventArgs> brokerMessageReceived()
          Event raised when a subscribed message type is received from the broker.
 Event<DuplexChannelEventArgs> connectionClosed()
          Event raised when the connection with the service was closed.
 Event<DuplexChannelEventArgs> connectionOpened()
          Event raised when the connection with the service was open.
 void sendMessage(java.lang.String messageType, java.lang.Object serializedMessage)
          Publishes the message via the broker.
 void subscribe(java.lang.String messageType)
          Subscribes for the message type.
 void subscribe(java.lang.String[] messageType)
          Subscribes for list of message types.
 void unsubscribe()
          Unsubscribe all messages.
 void unsubscribe(java.lang.String messageType)
          Unsubscribes from the specified message type.
 void unsubscribe(java.lang.String[] messageTypes)
          Unsubscribes from specified message types.
 
Methods inherited from interface eneter.messaging.infrastructure.attachable.IAttachableDuplexOutputChannel
attachDuplexOutputChannel, detachDuplexOutputChannel, getAttachedDuplexOutputChannel, isDuplexOutputChannelAttached
 

Method Detail

connectionOpened

Event<DuplexChannelEventArgs> connectionOpened()
Event raised when the connection with the service was open.

Returns:

connectionClosed

Event<DuplexChannelEventArgs> connectionClosed()
Event raised when the connection with the service was closed.

Returns:

brokerMessageReceived

Event<BrokerMessageReceivedEventArgs> brokerMessageReceived()
Event raised when a subscribed message type is received from the broker.

Returns:

sendMessage

void sendMessage(java.lang.String messageType,
                 java.lang.Object serializedMessage)
                 throws java.lang.Exception
Publishes the message via the broker.

Parameters:
messageType - event identifier
serializedMessage - message content.
Throws:
java.lang.Exception

subscribe

void subscribe(java.lang.String messageType)
               throws java.lang.Exception
Subscribes for the message type. If you can call this method multiple times to subscribe for multiple events.

Parameters:
messageType - identifies the type of the message which shall be subscribed.
Throws:
java.lang.Exception

subscribe

void subscribe(java.lang.String[] messageType)
               throws java.lang.Exception
Subscribes for list of message types.

Parameters:
messageType - list of message types which shall be subscribed.
Throws:
java.lang.Exception

unsubscribe

void unsubscribe(java.lang.String messageType)
                 throws java.lang.Exception
Unsubscribes from the specified message type.

Parameters:
messageType - message type the client does not want to receive anymore.
Throws:
java.lang.Exception

unsubscribe

void unsubscribe(java.lang.String[] messageTypes)
                 throws java.lang.Exception
Unsubscribes from specified message types.

Parameters:
messageTypes - list of message types the client does not want to receive anymore.
Throws:
java.lang.Exception

unsubscribe

void unsubscribe()
                 throws java.lang.Exception
Unsubscribe all messages.

Throws:
java.lang.Exception