This page will guide you through the steps necessary to obtain and operate your own Kinetic Rules Engine (KRE).
Learning Objectives
After completing this quickstart Quickstart lesson, you will:
- understand important concepts about programming in KRL including ruleset structure*
- know how to install and operate the node pico-engine
- know how to use the "Engine RulesetsMy Picos" page to register a ruleset
- know how to add install a ruleset to a pico
- become familiar with using the "My Picos" page to work with your picos
...
KRL is executed by your instance of the node pico-engine, an open-source, cloud-based rule processing system. All of the properties listed above are present in any KRE system.
To be executed, a ruleset must be
- available via HTTP and identified by a URL
- The URL must be registered with one or more pico engines where it will be known by a ruleset ID or RID
- The RID must be installed in one or more picos
- The pico must receive a request via the Sky Cloud API or the Sky Event API
Prerequisites
To complete the Quickstart, you will need
- An editor
- A Github account
- A pico engine
Install and run the node pico-engine
Prerequisite: you will need to install node (also known as Node.js) on your machine. It includes npm, the node package manager.
...
Note that the web server displays the URL of its document root, ex. "http://localhost:8084" and then continues to run. As we will see later, messages will be logged to this console.
Create a primary, or owner pico
Visit the default web page of your web server. As this page loads, it will perform a bootstrap sequence, which creates a During the pico engine initialization, it creates a primary pico, naming it "Owner Pico" and then registers and installs two rulesets.
Subsequent visits to the same page will short-circuit the bootstrap (because it's already been done).
In the console window in which the node pico-engine is running, there will be some logging concerning the two events sent during intial bootstrapping. You may find it interesting to try to make sense of these log messages.
Writing KRL
Here is a sample KRL rulesetThese are the minimum required for running the pico and the developer UI. You can visit the developer UI at the address on which the pico engine is listening. From there you will have a link to the main developer UI page, "My Picos":
Your owner pico is represented by a rounded rectangle, which is placed on a canvas, allowing you to change its placement.
Writing KRL
Do the following:
- Create a
git
repo for your KRL rulesets and put it on Github. You can create a different repo for each ruleset if you like or create one repo and put multiple rulesets in it. Create file in your ruleset repo called
hello.krl
and put the code below into it.- Validate your ruleset using the "Engine Rulesets" page.
- Check your ruleset into Github.
A first ruleset, in a file named hello.krl:
Code Block | ||
---|---|---|
| ||
ruleset hello_world { meta { name "Hello World" description << A first ruleset for the Quickstart >> author "Phil Windley" logging on shares hello } global { hello = function(obj) { msg = "Hello " + obj; msg } } rule hello_world { select when echo hello send_directive("say") with something = "Hello World" } } |
Open To validate, open the "Engine Rulesets" page (linked from the "Pico Bootstrap" page), and paste the ruleset above into the big text area, and click the "validate" button. When your KRL compiles correctly, you will see a result of "ok" beneath the buttons, with the page looking like this screenshot.
...