Constructor
new module:ct-core /event /Event Hub()
Methods
are Subscriber Errors Caught()
Determine whether errors in any of the event subscribers will be caught and logged by the event hub, or allowed to bubble up.
Catching and logging errors is typically preferable in production environments, whereas failing fast and letting
the exception bubble to the top is preferable for developer environments. The module:ct-core/event/EventHub#setAreSubscriberErrorsCaught
method can be used to configure this as appropriate for the environment.
get Proxy(sInterface, sEvent Group, proxy Interface) → {Object}
Return a proxy for the given event interface that will forward all method invocations to all subscribers on that interface.
The following example shows how a proxy for generating FI specific trade messages might be created:
var oFiTradingProxy = require("service!caplin.event-service").getProxy("pkg.Logger", "trading.fi");
Parameters:
Name | Type | Description |
---|---|---|
sInterface |
String | The event interface for which a proxy is being requested. |
sEventGroup |
String | A group classification of the type of event messages that will be sent, so that subscribers that want to can limit the events they will receive. |
proxyInterface |
function | The event interface for which a proxy is being requested. |
Returns:
A proxy object that implements the requested interface, but forwards all event invocation to the relevant subscribers.
- Type
- Object
set Are Subscriber Errors Caught(bAre Subscriber Errors Caught)
Set whether errors in any of the event subscribers will be caught and logged by the event hub, or allowed to bubble up.
Parameters:
Name | Type | Description |
---|---|---|
bAreSubscriberErrorsCaught |
Boolean | Whether errors will be caught or will bubble. |
subscribe(sInterface, sEvent Group Matcher, oImplementor, proxy Interfaceopt)
Create a subscription for a given event interface.
The following example shows how a trade message only logger might be subscribed for relevant logging events:
require("service!caplin.event-service").subscribe("pkg.Logger", "trading.*", oTradingLogger);
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
sInterface |
String | The event interface being subscribed to, and which the implementing component implements. |
|
sEventGroupMatcher |
String | A wild-card matcher specifying the subset of events the subscriber wishes to be notified of. |
|
oImplementor |
Object | A reference to the object receiving the subscription. |
|
proxyInterface |
function |
<optional> |
The event interface for which a proxy is being requested - optional. |
unsubscribe(sInterface, sEvent Group Matcher, oImplementor)
Cancel an existing event interface subscription.
The following example shows how a trade message only logger might be unsubscribed from receiving further events:
require("service!caplin.event-service").unsubscribe("pkg.Logger", "trading.*", oTradingLogger);
Parameters:
Name | Type | Description |
---|---|---|
sInterface |
String | The event interface the subscription was for. |
sEventGroupMatcher |
String | A wild-card matcher specifying the subset of events the subscriber wanted to be notified of. |
oImplementor |
Object | A reference to the subscribing object. |