Pub/Sub with Rust Canister Development Kit. This example demonstrates how functions may be passed as arguments of inter-canister calls to be used as callbacks. Also, with canister upgrade mechanism, we can upgrade the canister code without losing the state.
This sample project demonstrates how functions may be passed as arguments of inter-canister calls to be used as callbacks.
A common problem in both distributed and decentralized systems is keeping separate services (or canisters) synchronized with one another. While there are many potential solutions to this problem, a popular one is the Publisher/Subscriber pattern or "PubSub". PubSub is an especially valuable pattern on the Internet Computer as its primary drawback, message delivery failures, does not apply.
This example requires an installation of:
- Install the IC SDK.
Begin by opening a terminal window.
Step 1: Navigate into the folder containing the project's files and start a local instance of the Internet Computer with the command:
cd examples/rust/pub-sub
dfx start --background
dfx deploy
dfx canister call sub init '("Apples")'
dfx canister call pub publish '(record { "topic" = "Apples"; "value" = 2 })'
dfx canister call sub getCount
The output should resemble the following:
(2 : nat)