Skip to content

Commit

Permalink
Add how to adjust Zenoh configuration. (#5)
Browse files Browse the repository at this point in the history
Signed-off-by: ChenYing Kuo <[email protected]>
  • Loading branch information
evshary authored May 8, 2024
1 parent 8f9d39a commit 1206f1c
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ async-std = "1.12.0"
async-trait = "0.1"
chrono = "0.4.31"
env_logger = "0.10.0"
up-rust = { git = "https://github.com/eclipse-uprotocol/up-rust", rev = "c705ac97602ad6917a93d23651e8a504ec7bb718" }
up-client-zenoh = { git = "https://github.com/eclipse-uprotocol/up-client-zenoh-rust", rev = "dc0a3a95564ab1c83771fe71f0da5a261d469fb6" }
up-rust = { git = "https://github.com/eclipse-uprotocol/up-rust", rev = "1bb08ba7a3666e58c316489fbcf3da3e29dee611" }
up-client-zenoh = { git = "https://github.com/eclipse-uprotocol/up-client-zenoh-rust", rev = "cb592dc5abbaf9dcd204f592733404ea7c61e999" }
zenoh = { version = "0.10.1-rc", features = ["unstable"]}

[[bin]]
Expand Down
17 changes: 17 additions & 0 deletions src/common_uuri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
//

use up_rust::{Number, UAuthority, UEntity, UResource, UResourceBuilder};
use zenoh::config::Config;

pub enum ExampleType {
Publisher,
Expand Down Expand Up @@ -61,3 +62,19 @@ pub fn pub_resource() -> UResource {
pub fn rpc_resource() -> UResource {
UResourceBuilder::for_rpc_request(Some("getTime".to_string()), Some(5678))
}

#[allow(clippy::must_use_candidate, clippy::missing_panics_doc)]
pub fn get_zenoh_config() -> Config {
// Load the config from file path
// Config Examples: https://github.com/eclipse-zenoh/zenoh/blob/0.10.1-rc/DEFAULT_CONFIG.json5
// let mut zenoh_cfg = Config::from_file("./DEFAULT_CONFIG.json5").unwrap();

// Loat the default config struct
let mut zenoh_cfg = Config::default();
// You can choose from Router, Peer, Client
zenoh_cfg
.set_mode(Some(zenoh::config::WhatAmI::Peer))
.unwrap();

zenoh_cfg
}
3 changes: 1 addition & 2 deletions src/publisher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use common_uuri::ExampleType;
use std::time;
use up_client_zenoh::UPClientZenoh;
use up_rust::{UMessageBuilder, UPayloadFormat, UTransport, UUIDBuilder, UUri};
use zenoh::config::Config;

#[async_std::main]
async fn main() {
Expand All @@ -27,7 +26,7 @@ async fn main() {

println!("uProtocol publisher example");
let publisher = UPClientZenoh::new(
Config::default(),
common_uuri::get_zenoh_config(),
common_uuri::authority(),
common_uuri::entity(&ExampleType::Publisher),
)
Expand Down
3 changes: 1 addition & 2 deletions src/rpc_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ pub mod common_uuri;
use common_uuri::ExampleType;
use up_client_zenoh::UPClientZenoh;
use up_rust::{CallOptions, Data, RpcClient, UPayload, UPayloadFormat, UUri};
use zenoh::config::Config;

#[async_std::main]
async fn main() {
Expand All @@ -25,7 +24,7 @@ async fn main() {

println!("uProtocol RPC client example");
let rpc_client = UPClientZenoh::new(
Config::default(),
common_uuri::get_zenoh_config(),
common_uuri::authority(),
common_uuri::entity(&ExampleType::RpcClient),
)
Expand Down
3 changes: 1 addition & 2 deletions src/rpc_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use up_rust::{
Data, UListener, UMessage, UMessageBuilder, UPayloadFormat, UStatus, UTransport, UUIDBuilder,
UUri,
};
use zenoh::config::Config;

struct RpcListener {
up_client: Arc<UPClientZenoh>,
Expand Down Expand Up @@ -72,7 +71,7 @@ async fn main() {
println!("uProtocol RPC server example");
let rpc_server = Arc::new(
UPClientZenoh::new(
Config::default(),
common_uuri::get_zenoh_config(),
common_uuri::authority(),
common_uuri::entity(&ExampleType::RpcServer),
)
Expand Down
3 changes: 1 addition & 2 deletions src/subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use common_uuri::ExampleType;
use std::{sync::Arc, time};
use up_client_zenoh::UPClientZenoh;
use up_rust::{Data, UListener, UMessage, UStatus, UTransport, UUri};
use zenoh::config::Config;

struct SubscriberListener;
#[async_trait]
Expand All @@ -43,7 +42,7 @@ async fn main() {

println!("uProtocol subscriber example");
let subscriber = UPClientZenoh::new(
Config::default(),
common_uuri::get_zenoh_config(),
common_uuri::authority(),
common_uuri::entity(&ExampleType::Subscriber),
)
Expand Down

0 comments on commit 1206f1c

Please sign in to comment.