Unicorn Adapter is a node library to help subscribe to events in the event processing platform Unicorn.
npm install unicorn-adapter
to install the package
const UnicornAdapter = require('unicorn-adapter');
let unicornAdapter = new UnicornAdapter("Your Unicorn Url", "Your callback Url", options);
Available options:
maxTries
- Number of retries
let uuid;
unicornAdapter.subscribeToEvent('EventType').then(subscriptionId => {
uuid = subscriptionUuid;
console.log(`Subscription UUID: ${ subscriptionId }`);
});
unicornAdapter.unsubscribeFromEvent(uuid);
const exampleEventType = 'exampleEventType';
const exampleEvent = {
key1: 'value1',
key2: 'value2'
};
// Sent event to Unicorn
unicornAdapter.generateEvent(exampleEvent, exampleEventType).then(eventId => {
console.log(`EventId: ${ eventId }`);
});
// Adds TimeStamp and DO_state to event before sending event to Unicorn
unicornAdapter.generateChimeraEvent(exampleEvent, exampleEventType, 'state1').then(eventId => {
console.log(`EventId: ${ eventId }`);
});
- Initialize a new UnicornAdapter instance.
- Requires the Unicorn url, a callback url and an options object. Currently the only supported option is
maxTries
, which determines how often creating a notification rule should be retried before giving up.
- Subscribes to a Unicorn event of event type
eventName
. attributes
is an array of attribute names which are included in the notification payload.filters
allow to better filter events using theesper-language
package.callbackUrl
is optional and overwrites the callback url set on initialisation.- returns a Promise resolving to the UUID of the notification rule created in Unicorn
- Deletes the notification rule with the given UUID in Unicorn
- returns empty Promise, which resolves after successful deletion or rejects otherwise
- generates event in Unicorn
event
is a JSON object that should match the structure defined by the event type definition- automatically converts event to XML, that's understandable by Unicorn
eventType
is the event type of the event, which is needed by UnicorndataObjectState
is only helpful when working with Chimera. It is just a shortcut for setting theDO_state
attribute of an event
- Marius Lichtblau - mlichtblau - lichtblau.io - @lichtblau