Emit an Event
Why emit an Event?
Events are emitted from a Service (e.g.: a web server receiving a request, or a blockchain technology receiving a new transaction). These events are emitted to achieve a desired effect or to be used as a trigger to make another task happen. Each Service has different kinds of events that you can send to the Engine.
Steps to follow
To emit events from your Service, you'll need to:
- Add the definition of the event in the Service's
- Emit the event when it happens on the Service
To create an event, the first step is to update the Service's
mesg.yml file and add an event indexed by its key with the following attributes:
|name||String|| ||Name of the event. If the name is not set, it will be the same as the ID you choose for the event.|
|description||String|| ||Describe the event, what's its purpose is and why users would want to use it.|
|data||map<id,Data>|| ||The structure of the event's data.|
|name||String|| ||Name of the data|
|description||String|| ||Description of the data|
|type||Type|| ||Type of data|
|object||Data|| ||Nested data. Data can contain child data. It can only be defined when |
|optional||Boolean|| ||Mark the data as optional|
|repeated||Boolean|| ||Define this data as an array of the type selected|
The data type can be one of the following:
Example of an event definition in a
... events: eventX: name: "Event X" description: "This is event X" data: foo: name: "Foo" description: "Foo is a string" type: String optional: false bar: name: "Bar" description: "Bar is an optional array of boolean" type: Boolean optional: true repeated: true ...
Emit an Event
Consider emitting event when the service is ready. If the service needs to synchronize data first, it should wait for the synchronization to complete before emitting events.
You need help ? Check out the MESG Forum.