4 Star 0 Fork 0

Gitee 极速下载/wasmcloud

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/wasmCloud/wasmCloud
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

Custom Capability Provider

This capability provider is a template for creating providers with custom capabilities. It uses the wasmcloud-provider-sdk and implements the Provider trait with an example handler that will persist the links that target the provider (target links) and links where the provider is the source and targets a component (source links).

The purpose of this example is to provide comprehensive comments on the usage of our wasmCloud provider SDK, from serving RPC exports to invoking component imports. The code is informative to read through and provides a base for extending wasmCloud with custom capabilities.

Building

Prerequisites:

  1. Rust toolchain
  2. wash

You can build this capability provider by running wash build. You can build the included test component with wash build -p ./component.

Running to test

Prerequisites:

  1. Rust toolchain
  2. nats-server
  3. nats-cli

You can run this capability provider as a binary by passing a simple base64 encoded HostData struct, in order to do basic testing. For example:

nats-server -js &
echo '{"lattice_rpc_url": "0.0.0.0:4222", "lattice_rpc_prefix": "default", "provider_key": "custom-template", "config": {"foo": "bar"}, "env_values": {}, "link_definitions": [], "otel_config": {"enable_observability": false}}' | base64 | cargo run

And in another terminal, you can request the health of the provider using the NATS CLI

nats req "wasmbus.rpc.default.custom-template.health" '{}'

Additionally, you can invoke the provider directly which will send test data to each linked component

wash call custom-template wasmcloud:example/system-info.call

Running as an application

You can deploy this provider, along with a component for testing, by deploying the wadm.yaml application. Make sure to build the component with wash build.

# Launch wasmCloud in the background
wash up -d
# Deploy the application
wash app deploy ./wadm.yaml

Customizing

Customizing this provider to meet your needs of a custom capability takes just a few steps.

  1. Update the wit/world.wit to include the data types and functions that model your custom capability. You can use the example as a base and the component model WIT reference as a guide for types and keywords.
  2. Implement any provider exports in src/provider.rs inside of the impl Handler {} block.
  3. Use the methods inside of the impl Provider {} block to handle invoking components. For inspiration, take a look at our other capability providers that implement various capabilities like HTTP, Messaging, Key-Value in the crates/provider-* folder.

Have any questions? Please feel free to file an issue and/or join us on the wasmCloud slack!

马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Rust
1
https://gitee.com/mirrors/wasmcloud.git
git@gitee.com:mirrors/wasmcloud.git
mirrors
wasmcloud
wasmcloud
main

搜索帮助