...
- Explain what a pico subscription is
- Understand pico-to-pico relationships based on subscriptions
- Use the developer tools to manage pico subscriptions
- Programmatically link picos using a subscription and have them interact.
Prerequisites
You should have already completed the following lessons:
Pico Engine Quickstart lesson. (Be able to register and install rulesets)
Events and Queries Lesson. (Be able to create channels and understand how events are raised on channels)
- Pico State Lesson. (Be able to store and retrieve state using entity variables, both simple and complex)
Pico-Based Systems Lesson. (Be able to manage the pico lifecycle using UI and programmatically)
- Read Wrangler Subscriptions description.
Contents
Table of Contents | ||
---|---|---|
|
Subscriptions
Subscriptions play an important role in building systems of picos. In Pico-Based Systems Lesson, you created child picos. If the parent-child relationship were the only one that existed, we could create hierarchies of picos, but not peer-to-peer systems of picos. Subscriptions allow us to establish relationships between any two picos.
A subscription represents a relationship between two picos. It has a name and two channels, one from each pico participating in the subscription to the other. Each side in the subscription can be given a role to further identify the purpose of the subscription.
Managing Subscriptions Programmatically
Wrangler provides functions, actions, and rules for managing subscriptions from within your KRL code.
In this section, we'll use a simple example. Here the owner pico has three child picos, as shown by the familiar black parent-child edges. However, let's say the "Mischief Pico" needs to communicate with the other two picos.
The subscriptions which we will create to enable this pico to pico communication are shown as dashed magenta lines. (This diagram is available at localhost:8080/?subscr )
Info | ||
---|---|---|
| ||
Very soon, the ability to manage subscriptions will be built-in to every pico. Right now, you will need to install the ruleset with RID "io.picolabs.subscription" into the three picos which will participate in subscriptions. This can be done in the Rulesets tab of each pico, by clicking on the "install ruleset" button beside the dropdown when it shows "io.picolabs.subscription". The "io.picolabs.subscription" ruleset is automatically registered in the pico engine during start-up, because it exists (in a file named "io.picolabs.subscriptions.krl") in the folder name "krl". However, it is not automatically installed in any pico. Soon, it will be. |
...
Motivation
In the previous lesson, you learned about creating pico parent-child relationships. However, in distributed systems, not everything is a parent-child relationship. In fact, there are many systems which are based off of peer-to-peer relationships. Each node in a peer-to-peer system needs some way to communicate with a different node independent of a parent child hierarchy. For example, a flower store may wish to create a relationship with a delivery driver, so that the store can broadcast a new delivery request, and the driver can bid on delivering that request. This is where subscriptions come in. Subscriptions are a relationship link from one pico to another completely independent of the parent-child hierarchy. This lesson will show you how to create these subscriptions (relationships) among picos so that they may communicate directly with each other rather than through some other median.
Prerequisites
You should have already completed the following lessons:
Pico Engine Quickstart lesson. (Be able to register and install rulesets)
Events and Queries Lesson. (Be able to create channels and understand how events are raised on channels)
- Pico State Lesson. (Be able to store and retrieve state using entity variables, both simple and complex)
Pico-Based Systems Lesson. (Be able to manage the pico lifecycle using UI and programmatically)
- Read Wrangler Subscriptions description.
Contents
Table of Contents | ||
---|---|---|
|
Subscriptions
A subscription represents a relationship between two picos. It has a name and two channels, one from each pico participating in the subscription to the other. Each side in the subscription can be given a role to further identify the purpose of the subscription.
Managing Subscriptions Programmatically
Wrangler provides functions, actions, and rules for managing subscriptions from within your KRL code.
In this section, we'll use a simple example. Here the owner pico has three child picos, as shown by the familiar black parent-child edges. However, let's say the "Mischief Pico" needs to communicate with the other two picos.
The subscriptions which we will create to enable this pico to pico communication are shown as dashed magenta lines. (This diagram is available at localhost:8080/?subscr )
Prepare for this section by manually creating three child picos of your root pico.
...
Info | ||
---|---|---|
| ||
Very soonEventually, Wrangler will fully integrate subscriptions, so that when you delete a child pico any subscriptions it participates in will also be deleted. In the meantime, you may wish to programmatically delete such subscriptions before requesting the deletion of the child pico. |
...