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: A
[subscription.<name>]block declares that a component should be subscribed to a channel. Thechannelfield defaults to the subscription's name. When a message arrives on the channel, the runtime invokes the component's function with the message body as the argument. Optional fields:function(required when the component exports more than one), and the four mapping blocks -param-mapping,param-encoding,result-decoding,result-mapping- which apply in pipeline order to bridge the Message and the WIT call. See the mapping module docs for details. - Publishing:
composable publishstarts the runtime, publishes a single message to the named channel, waits for processing, and exits.
[component.greeter]
uri = "../hello-world/greeter/target/wasm32-unknown-unknown/release/greeter.wasm"
[subscription.names]
component = "greeter"