This page will guide you through the steps necessary to obtain and operate your own Kinetic Rules Engine (KRE).
After completing this Quickstart lesson, you will:
Getting started with KRL can be a big leap because there are so many things that are different about programming in KRL:
The result of these properties is a programming model that more closely resembles programming cloud-based persistent objects than anything else. We call these persistent computational objects "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
To complete the Quickstart, you will need
Prerequisite: you will need to install node (also known as Node.js) on your machine. Be sure that you are installing at least version 4. The installation includes npm, the node package manager, which you will use to install the pico engine. (Node.js is a trademark of Joyent, Inc. and is used with its permission. Picolabs is not endorsed by or affiliated with Joyent.)
Once you have npm and node on your machine, open a command line window and issue these two commands, which will install and start the node pico engine.
The node pico engine will spend some time initializing internal data structures before it starts its web server. After doing this, it will start a web server on port 8080.
Note that the web server displays the URL of its document root, ex. "http://localhost:8080" and then continues to run. As we will see later, messages will be logged to this console, so it is best not to close this command line window.
During the pico engine initialization, it creates a primary pico, naming it "Owner Pico" and then registers four rulesets and installs two of them in the owner pico. These are the minimum required for running the pico and the developer UI. You can visit the developer UI, "My Picos", at the address on which the pico engine is listening.
Your owner pico is represented by a rounded rectangle, which is placed on a canvas, allowing you to change its placement. Keep this tab open for use in registering and installing your ruleset, below.
Overall Structure of a KRL Ruleset
A first ruleset, in a file named hello_world.krl:
The following describes parts of the ruleset shown above:
Line 1: A ruleset starts with the
ruleset keyword, the ruleset identifier or RID, and a curly brace. In this case, the RID is
Lines 2-10: A ruleset usually contains a
meta block giving information about the ruleset. This information includes information like the ruleset
author, as well as pragmas that affect the ruleset's behavior. For example, this ruleset has a
shares pragma saying which global functions are shared with the outside world (including other rulesets).
Lines 12-17: A ruleset usually contains a
global block which globally binds values to names, some of which may be shared.In this case, the name
hello is bound to a function value and is shared.
Lines 19-23: A ruleset usually contains one or more rules. In this case there is one rule named
hello_world which will be watching for events with domain
echo and type
A recommended workflow for writing KRL is found in KRL Programming Workflow. Please read and set up a workflow using your favorite editor and Git.
Installing a ruleset to a pico is properly a user function, but as a developer, you are functioning in both user and developer capacities.
View your Owner Pico by visiting the "My Picos" page (linked from the "Pico Bootstrap" page), as shown above.
Single click on the rounded rectangle which represents your Owner Pico. It opens up, giving you access to information about it.
The "About" tab will be used in subsequent lessons.
Now, click on the "Rulesets" tab. Enter the URL to the KRL source code in the box beside the button "install ruleset from URL" and click on that button.
Clicking on the "install ruleset from URL" will cause the pico engine to get your ruleset using an HTTP GET, compile it, and register it.
If you're using GitHub to host your rulesets, be sure that you supply the "raw" URL. The raw URL returns the file without any GitHub page chrome. For example, this is a raw and cooked example of the same ruleset. If you're hosting your rulesets on Amazon S3, be sure the URL is public and can be retrieved using a browser.
Finally, the ruleset will be installed in this pico, as you can see when the page refreshes.
Notice that you are allowed to delete from the pico any ruleset that you install.
Having completed this quickstart, you should continue with Events and Queries Lesson