Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • complete the Pico Engine Quickstart
  • have the hello_world ruleset from the Quickstart registered in the pico engine, and installed in a pico
  • have installed the event console (latest GitHub version) in Google ChromePostman, or some other HTTP app.

Contents

Table of Contents
maxLevel2

...

Directives allow picos to direct endpoints to react a certain way to an event.  Our rule's directive just says hello, but it could be used to do more complex things. Directives allow the program's logic to be placed in the rules, not in the end points.  Placing logic in the rules provides loose coupling with easier scaling and maintenance.

2. Using the event console (This method is currently deprecated. Avoid using it.)

The Kynetx event console is a Google Chrome application that you can add to your browser to make it easy to send events. You can find it on GitHub and install it into your browser following the instructions. You can then launch it and enter in the host:port of your pico engine, the channel identifier and the event domain and type. You will need to un-check the box beside "Use HTTPS".

...

Exercises (Intermediate, presumes completion of Modules and External APIs Lesson)

Do the following:

  1. Write and register a ruleset named track_trips that contains a rule called process_trips that responds to the car:new_trip event with an attribute mileage. This rule should return a directive named trip with the option trip_length set to the value of the mileage attribute.

  2. Using the Pico Engine UI, create a pico that represents a car and install your track_trips ruleset in it.
  3. Using one of the techniques in Raising Events, test your ruleset.  Try it with and without the mileage attribute.

  4. Modify the select statement in the process_trips rule so that it will not fire unless there is a mileage attribute with the string value of a positive number. Hint: read the docs for the universal operator as().

  5. Modify the process_trips rule to raise an event.with domain explicit and type trip_processed. The explicit event should include any attributes that were in the car:new_trip event. Hint: event:attrs() returns all attributes of the current event.

  6. In the same ruleset, write a new rule named find_long_trips that selects on the explicit:trip_processed event. It should read the mileage attribute and, if it contains a value greater than the numeric value of the global variable named long_trip, raises another explicit event with domain explicit, type found_long_trip, and any atrributes passed along. Note, there are multiple ways to accomplish this.  You can pick any positive value for long_trip that you like.

  7. In the same ruleset, write another rule called trip_fuel_usage that selects on the explicit:trip_processed event. The rule should use the VIN event attribute as input to the vehicle information function you created in Modules and External APIs Lesson to retrieve information about this vehicle. Using the number in the mileage attribute, calculate the gallons of gas used for this trip (assume it was highway). Your rule action should return a directive that contains the miles driven and gallons of gas used for the trip. 

  8. Use ruleset logging and debugging tools to convince yourself that your rules work.