Introduction

In the Getting Started guide, you learned to define an Event in Zeleo which would then allow the user to create a Condition in Zeleo. Now you need to fire that event, which means a JSON document must be sent to Zeleo.

Condition Service

Once you have the Event defined in Zeleo as explained in the Getting Started guide, you will need to wire up a servce to acually send the event to Zeleo. This is pretty simple- you will need to send the JSON document of the event, encoded as a JWT token as defined here, that fits the Event you defined in the Development Tab. Make sure the JSON keys match the ones you defined in Zeleo so the Rule definition can be executed. The URL you will send that event to is available by clicking on the preview icon in your event:

Event Preview

And that’s it! The event will be evaluated against what the user has configured, and if that matches, consequences will be fired!

Here’s an example from our GitHub Zeleo Application:

/**
  * Fire the event. Example does not handle the response; you may want to persist and retry failures.
  *
  * @param url The Zeleo url of the event that is being fired.
  * @param payload The key/value pairs of fields.
  * @return
  * @throws Exception
  */
 private void fireEvent(final String url, Map<String, Object> payload) throws Exception {
    final ResteasyClient client = new ResteasyClientBuilder().build();
    final ResteasyWebTarget target = client.target(url); 
    final String json = JSONUtils.toJSON(payload);
    final String token = generateJWTToken(json);
    final Response response = target.request().post(Entity.entity(token, MediaType.TEXT_PLAIN));
}