Class: EventHub

Constructor

Construct EventHub instance with API credentials.

method(serverUrl, apiUser, apiKey[, options.applicationId])
Arguments:
  • serverUrl (String) – Server URL
  • apiUser (String) – API user
  • apiKey (String) – API key
  • options.applicationId (String) – Application identifier, added to event source.

Function: connect

Connect to the event server.

connect()

Function: isConnected

Return true if connected to event server.

isConnected()
Return Boolean:Return true if connected to event server.

Function: publish

Publish event and return promise resolved with event id when event has been sent.

If onReply is specified, it will be invoked when any replies are received.

If timeout is non-zero, the promise will be rejected if the event is not sent before the timeout is reached. Should be specified as seconds and will default to 10.

publish(event[, options.onReply][, options.timeout])
Arguments:
  • event (Event) – Event instance to publish
  • options.onReply (function) – Function to be invoked when a reply is received.
  • options.timeout (Number) – Timeout in seconds
Return Promise:

Function: publishAndWaitForReply

Publish event and wait for a single reply.

Returns promise resolved with reply event if received within timeout.

publishAndWaitForReply(event[, options.timeout])
Arguments:
  • event (Event) – Event instance to publish
  • options.timeout (Number) – Timeout in seconds [30]
Return Promise:

Promise resolved with reply event.

Function: subscribe

Register to subscription events.

subscribe(subscription, callback[, metadata])
Arguments:
  • subscription (String) – Expression to subscribe on. Currently, only “topic=value” expressions are supported.
  • callback (function) – Function to be called when an event matching the subscription is returned.
  • metadata (Object) – Optional information about subscriber.
Return String:

Subscriber ID.

Function: publishReply

Publish reply event.

publishReply(sourceEvent, data[, source])
Arguments:
  • sourceEvent (Object) – Source event payload
  • data (Object) – Response event data
  • source (Object) – Response event source information