The event system is a global service object named eventSystem that is available to application developers in the Itential Platform environment. The eventSystem allows a service to publish information to the Itential Platform environment that other services can react to.
The event system has three main methods:
To define an event that you want your service to publish, add a topics section to the pronghorn.json of your application. For example:
The example above defines two topics that can be emitted as events: launch and bananas. The launch object contains a JSON schema that defines what its event payload should look like. The rocket property is required for the event’s payload — if it is not present, the event will not be processed. If an event does not match the defined schema, it is rejected.
The bananas event has no requirement for its payload structure. You can publish as many events as you like:
Events are automatically namespaced using the model name of the application (for example, @itential/app-workflow_engine). This allows developers to have events with the same name across different applications — for example, the event name rocket could exist in both @itential/app-workflow_engine and @itential/app-configuration_manager.
When an application connects to Itential Platform, it automatically sends all of its defined event topics. Itential Platform adds the event topics to the global list it maintains and then broadcasts the updated global list to all other applications, allowing them to subscribe to the new events.
There is currently no verification of event payload within Itential Platform. This is handled by the eventSystem in the application when it receives a subscribed event.
To handle a particular event, call the eventSystem.subscribe method. After subscribing, the event system calls the handler function when it receives the event and verifies the payload matches the schema.
Example
To stop listening for an event, call the eventSystem.unsubscribe method. This causes the event system to stop calling the handler function for that event.
Example
To send an event, call the eventSystem.publish method. This sends the event to Itential Platform for broadcast to all other applications in the environment. No source is required when publishing — the namespace is automatically added by the event system to ensure proper scope.
Example