This example demonstrates a component that subscribes to a channel and is invoked when messages are published.
config.toml: Component configuration with asubscriptionpropertypublish.sh: Publishes a message viacomposable publish
This example reuses the greeter component from the hello-world example.
Change into the examples/messaging directory.
Publish a name via publish.sh (it will build the greeter component if not already built):
./publish.sh AliceOutput:
... invocation complete component=greeter function=greet result="Hello, Alice!"
You can also run composable publish directly:
composable publish config.toml --channel names --body Bob
- Subscription: The
subscriptionproperty on a component tells the runtime to create a channel and subscribe the component to it. When a message arrives, the runtime invokes the component's exported function with the message body as the argument. - Publishing:
composable publishstarts the runtime, publishes a single message to the named channel, waits for processing, and exits.
Note
At this time, the component must export exactly one function, but more configuration options will be available for subscriptions soon, including the target function.
[component.greeter]
uri = "../hello-world/greeter/target/wasm32-unknown-unknown/release/greeter.wasm"
subscription = "names"