编译zenoh-python 支持python 包直接加载plugin插件
了解zenoh的都应该支持zenoh 包含了几种角色,peer,client,router,这些都是在配置指定的,但是在一些语言sdk 中,zenoh 为了简单,一些模式尽管可以配置,但是实际参数是不能生效的,比如router 模式的plugin 加载
解决方法
可以参考zenohd 的方法(核心部分是plugins feature),使用上是一样的
参考构建
- Cargo.toml
[features]
default = ["zenoh/default", "zenoh-ext","zenoh/internal_config","zenoh/plugins","zenoh/runtime_plugins"]
- 构建
maturin build
- 使用
简单示例,核心是先得安装构建的pip whl 包
config3.json5 配置
{
"mode": "router",
"listen": {
"endpoints": ["tcp/0.0.0.0:7447"]
},
"plugins_loading": {
"enabled": true,
"search_dirs": ["./libs"]
},
"plugins": {
"mqtt": {
"port": 1883
},
"webserver": {
"http_port": 8080
},
// configuration of "storage-manager" plugin:
"storage_manager": {
"volumes": {
// configuration of a "fs" volume (the "zenoh_backend_fs" backend library will be loaded at startup)
"fs": {}
},
"storages": {
// configuration of a "demo" storage using the "fs" volume
"demo": {
// the key expression this storage will subscribes to
"key_expr": "demo/example/**",
// this prefix will be stripped from the received key when converting to file path
// this argument is optional.
"strip_prefix": "demo/example",
"volume": {
"id": "fs",
// the key/values will be stored as files within this directory (relative to ${ZENOH_BACKEND_FS_ROOT})
"dir": "example"
},
"replication": {
// This field was named publication_interval.
"interval": 10,
// This field was named delta.
"sub_intervals": 5,
"propagation_delay": 250,
// These fields did not exist before.
"hot": 6,
"warm": 30
}
},
"demov2": {
// the key expression this storage will subscribes to
"key_expr": "video/capture/**",
// this prefix will be stripped from the received key when converting to file path
// this argument is optional.
"strip_prefix": "video",
"volume": {
"id": "fs",
// the key/values will be stored as files within this directory (relative to ${ZENOH_BACKEND_FS_ROOT})
"dir": "examplev2"
},
"replication": {
// This field was named publication_interval.
"interval": 10,
// This field was named delta.
"sub_intervals": 5,
"propagation_delay": 250,
// These fields did not exist before.
"hot": 6,
"warm": 30
}
}
}
},
// Optionally, add the REST plugin
"rest": {
"http_port": 8001
},
"remote_api": {
"websocket_port": 10000
}
},
"adminspace": {
"permissions": {
"read": true,
"write": true
}
}
}
import zenoh
print("Opening session...")
with zenoh.open(zenoh.Config.from_file("config3.json5")) as session:
print("Declaring Queryable on 'demo/sensors/appv3'...")
with session.liveliness().declare_token("demo/sensors/appv3") as token:
print("Press CTRL-C to quit...")
while True:
pass
一些细节问题
注意zenoh插件以及zenoh 版本的对应,还有就是rust 版本,这个很重要,否则会有插件不能生效的问题,甚至服务出现segmentation fault,具体版本的下载可以通过release 部分
说明
rust 开发的服务启动参考如下,实际上就是zenoh::open
fn main() {
if let Err(e) = init_logging() {
eprintln!("{e}. Exiting...");
std::process::exit(-1);
}
tracing::info!("zenohd {}", *LONG_VERSION);
let args = Args::parse();
let config = config_from_args(&args);
tracing::info!("Initial conf: {}", &config);
let _session = match zenoh::open(config).wait() {
Ok(runtime) => runtime,
Err(e) => {
eprintln!("{e}. Exiting...");
std::process::exit(-1);
}
};
std::thread::park();
}
浙公网安备 33010602011771号