-
Notifications
You must be signed in to change notification settings - Fork 2
How to Create a 4.1.2 Event Subscriber
A subscriber needs to have a RESTful server to receive events. For this you'll need a resource class. See the Jersey documentation.
Firstly, Arrowhead requires a system to have GET method, that can be pinged. It just needs to send back an empty OK message. Then, Arrowhead requires a POST method, to receive the events. These are at the path in the Event Filter URI. Please respond to the Event Handler, so that it knows the system successfully received the event.
The subscriber needs to be registered into the Event Handler.
As currently Arrowhead doesn't really support discovery, you have to know it before the consumer starts.
It'll either end up hardcoded, or, better, in the config file. Arrowhead provides some utilities for reading config files.
The Event Handler expects an Event Filter.
Create an EventFilter type object. The constructor will take three things:
- The name of the event type.
- The system identifier, which done an Arrowhead System type object. This basically requires a name, by which IP address and port number the system can be reached, and security info.
- The URI, where the Event Handler will send the events.
Is done by sending a http POST to the Event Handler. The path in the URI is eventhandler/subscription
. To be sure about the URI, use the Utility.getUri function. (This means the Orchestrator's URL should be stored in an are-we-safe, IP adress, port number triplet.)
For sending the http message, use the Utility.sendRequest, to receive an Arrowhead Exception in case of a problem.
When the service end, it should unsubscribe.
This is done by sending a DELETE request to the Event Handler, to the path of eventhandler/subscription/type/*eventType*/consumer/*systemName*
.