public interface IDuplexBrokerClient extends IAttachableDuplexOutputChannel
// 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");
// 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.");
Modifier and Type | Method and Description |
---|---|
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.
|
attachDuplexOutputChannel, detachDuplexOutputChannel, getAttachedDuplexOutputChannel, isDuplexOutputChannelAttached
Event<DuplexChannelEventArgs> connectionOpened()
Event<DuplexChannelEventArgs> connectionClosed()
Event<BrokerMessageReceivedEventArgs> brokerMessageReceived()
void sendMessage(java.lang.String messageType, java.lang.Object serializedMessage) throws java.lang.Exception
messageType
- event identifierserializedMessage
- message content.java.lang.Exception
void subscribe(java.lang.String messageType) throws java.lang.Exception
messageType
- identifies the type of the message which shall be subscribed.java.lang.Exception
void subscribe(java.lang.String[] messageType) throws java.lang.Exception
messageType
- list of message types which shall be subscribed.java.lang.Exception
void unsubscribe(java.lang.String messageType) throws java.lang.Exception
messageType
- message type the client does not want to receive anymore.java.lang.Exception
void unsubscribe(java.lang.String[] messageTypes) throws java.lang.Exception
messageTypes
- list of message types the client does not want to receive anymore.java.lang.Exception
void unsubscribe() throws java.lang.Exception
java.lang.Exception