Class: MessageBusOutputChannel

MessageBusOutputChannel

new MessageBusOutputChannel(serviceId, responseReceiverIdopt, messageBusOutputChannel, serializeropt)

Output channel which provides the connection via the message bus.
It uses the underlying messageBusOutputChannel to open connection to the message bus and then it asks the message bus to open the connection with a specified service.
Parameters:
Name Type Attributes Default Description
serviceId String id which specifies the address of the service within the message bus.
responseReceiverId String <optional>
null uniquely represents the connection with the service behind the message bus. The id is not sent to the service but is itendend for the client to recognize the connection. If null then responsereceiverId is generated automatically.
messageBusOutputChannel WebSocketDuplexOutputChannel | AuthenticatedDuplexOutputChannel underlaying output channel which connects the message bus.
serializer serializer <optional>
null serializer responsible to serialize/deserialize the communication with the message bus. If null then the default MessageBusCustomSerializer is used.
Source:
Example
// Create websocket output channel for the communication with the message bus.
// ws://127.0.0.1:8045/Clients/ is the address where the message listens to requests from clients.
var anUnderlyingMessageBusOutputChannel = new WebSocketDuplexOutputChannel("ws://127.0.0.1:8045/Clients/", null);

// Create message bus output channel which will ensure communication with the specified service behind the message bus.
// The service which is requested from the message bus is called CalculatorService.
var aMessageBusOutputChannel = new MessageBusOutputChannel("CalculatorService", null, anUnderlyingMessageBusOutputChannel);

// Create MultiTypedMessageSender.
var aSender = new MultiTypedMessageSender();

// Register message handler
aSender.registerResponseMessageReceiver(onMyMessageTypeResponseReceived, "MyMessageType");

// When 'Open Connection' button is pressed.
function onOpenConnection() {
    // Attach output channel and be able to send messages and receive responses to/from the service behind the message bus.
    aSender.attachDuplexOutputChannel(aMessageBusOutputChannel);
}

// When 'Close Connection' button is pressed.
function onCloseConnection() {
    // Detach output channel and stop listening to responses.
    aSender.detachDuplexOutputChannel();
}

Methods

closeConnection()

Closes connection with the duplex input channel.
Source:

getChannelId() → {String}

Returns the channel id. It represents the service address.
Source:
Returns:
Type
String

getResponseReceiverId() → {String}

Returns the response receiver id. It uniquely represents this client at the service.
Source:
Returns:
Type
String

isConnected() → {Boolean}

Returns true if the connection with the duplex input channel is open.
Source:
Returns:
Type
Boolean

onConnectionClosed(duplexChannelEventArgs)

The event is invoked when the connection with the duplex input channel was closed.
Parameters:
Name Type Description
duplexChannelEventArgs DuplexChannelEventArgs
Source:
Example
// Set your handler to receive close connection notification.
aSender.onConnectionClosed = yourOnConnectionClosed;

onConnectionOpened(duplexChannelEventArgs)

The event is invoked when the connection with the duplex input channel was opened.
Parameters:
Name Type Description
duplexChannelEventArgs DuplexChannelEventArgs
Source:
Example
// Set your handler to receive open connection notification. 
aSender.onConnectionOpened = yourOnConnectionOpened;

onResponseMessageReceived(duplexChannelMessageEventArgs)

The event is invoked when a response message was received.
Parameters:
Name Type Description
duplexChannelMessageEventArgs DuplexChannelMessageEventArgs
Source:

openConnection()

Opens connection with the duplex input channel.
The opening the connection contains the request to the message bus to get connected to the specified service.
Source:
Throws:
Throws error if connection could not be open.

sendMessage(message)

Sends the message to the duplex input channel.
Parameters:
Name Type Description
message String | ArrayBuffer message to be sent
Source:
Throws:
Throws error if sending fails.