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. attributesis an array of attribute names which are included in the notification payload.filtersallow to better filter events using theesper-languagepackage.callbackUrlis 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
eventis a JSON object that should match the structure defined by the event type definition- automatically converts event to XML, that's understandable by Unicorn
eventTypeis the event type of the event, which is needed by UnicorndataObjectStateis only helpful when working with Chimera. It is just a shortcut for setting theDO_stateattribute of an event
- Marius Lichtblau - mlichtblau - lichtblau.io - @lichtblau