Skip to content

How to Create a 4.1.2 Event Publisher

Kadosa Koltai edited this page Oct 17, 2019 · 2 revisions

Publishing

The publisher only needs to send an event to the Event Handler, no registering is necessary.

Finding the URL of 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 a Publish Event.

Creating the Publish Event

Is done by creating a PublishEvent type object.

Firstly, the system needs to identify itself, which is done by creating an Arrowhead System type object of itself. This basically requires a name, by which IP address and port number the system can be reached, and a null for security info.

Secondly, the actual event is given, in the form of an Event object. This consist of:

  1. The name of the event type.
  2. The body of the vent, coded into a string.
  3. The time of event creation, given as a ZonedDateTime.
  4. Metadata, in key-value pairs, as a Map.

Finally, the path to the feedback resource. If not null null, the Event Handler will send POST message here on completion of event propagation. The response will contain a Map of ArrowheadSystem-bool, where the bool denotes if the key system successfully received the event.

Publishing the Event

Is done by sending a http POST to the Event Handler. The path in the URI is eventhandler/publish. 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.

Server

If you want to receive the confirmation message, you'll need to have a RESTful server. For this you'll need a resource class. See the Jersey documentation.

The Event Handler send such messages as a POST message to the path you specified as the feedback.

The Arrowhead requires systems to have GET method, that can be pinged. It just needs to send back an empty OK message.