...
- 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 maxLevel 2
...
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:
Write and register a ruleset named
track_trips
that contains a rule calledprocess_trips
that responds to thecar:new_trip
event with an attributemileage
. This rule should return a directive namedtrip
with the optiontrip_length
set to the value of themileage
attribute.- Using the Pico Engine UI, create a pico that represents a car and install your
track_trips
ruleset in it. Using one of the techniques in Raising Events, test your ruleset. Try it with and without the mileage attribute.
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 operatoras()
.Modify the
process_trips
rule to raise an event.with domainexplicit
and typetrip_processed
. The explicit event should include any attributes that were in thecar:new_trip
event. Hint:event:attrs()
returns all attributes of the current event.In the same ruleset, write a new rule named
find_long_trips
that selects on theexplicit:trip_processed
event. It should read themileage
attribute and, if it contains a value greater than the numeric value of the global variable namedlong_trip
, raises another explicit event with domainexplicit
, typefound_long_trip
, and any atrributes passed along. Note, there are multiple ways to accomplish this. You can pick any positive value forlong_trip
that you like.In the same ruleset, write another rule called
trip_fuel_usage
that selects on theexplicit: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.Use ruleset logging and debugging tools to convince yourself that your rules work.