Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ftr: add nacos registry example #118

Merged
merged 1 commit into from
Mar 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/echo/src/generated/grpc.examples.echo.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// @generated by apache/dubbo-rust.

/// EchoRequest is the request for echo.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct EchoRequest {
#[prost(string, tag = "1")]
pub message: ::prost::alloc::string::String,
}
/// EchoResponse is the response for echo.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct EchoResponse {
#[prost(string, tag = "1")]
Expand Down
1 change: 1 addition & 0 deletions examples/greeter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ logger = {path="../../common/logger"}
dubbo = {path = "../../dubbo", version = "0.3.0" }
dubbo-config = {path = "../../config", version = "0.3.0" }
dubbo-registry-zookeeper = {path = "../../registry/zookeeper", version = "0.3.0" }
dubbo-registry-nacos = {path = "../../registry/nacos", version = "0.3.0" }

[build-dependencies]
dubbo-build = {path = "../../dubbo-build", version = "0.3.0" }
35 changes: 21 additions & 14 deletions examples/greeter/src/greeter/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,36 @@ pub mod protos {
include!(concat!(env!("OUT_DIR"), "/org.apache.dubbo.sample.tri.rs"));
}

use dubbo::codegen::*;
use std::env;

use dubbo::{codegen::*, common::url::Url};
use dubbo_registry_nacos::nacos_registry::NacosRegistry;
use dubbo_registry_zookeeper::zookeeper_registry::ZookeeperRegistry;
use futures_util::StreamExt;
use protos::{greeter_client::GreeterClient, GreeterRequest};

#[tokio::main]
async fn main() {
logger::init();
// let mut cli = GreeterClient::new(ClientBuilder::from_static(&"http://127.0.0.1:8888"));

// Here is example for zk
// let zk_connect_string = match env::var("ZOOKEEPER_SERVERS") {
// Ok(val) => val,
// Err(_) => "localhost:2181".to_string(),
// };
// let zkr = ZookeeperRegistry::new(&zk_connect_string);
// let directory = RegistryDirectory::new(Box::new(zkr));
// cli = cli.with_directory(Box::new(directory));
let mut builder = ClientBuilder::new();

if let Ok(zk_servers) = env::var("ZOOKEEPER_SERVERS") {
let zkr = ZookeeperRegistry::new(&zk_servers);
let directory = RegistryDirectory::new(Box::new(zkr));
builder = builder.with_directory(Box::new(directory));
} else if let Ok(nacos_url_str) = env::var("NACOS_URL") {
// NACOS_URL=nacos://mse-96efa264-p.nacos-ans.mse.aliyuncs.com
let nacos_url = Url::from_url(&nacos_url_str).unwrap();
let registry = NacosRegistry::new(nacos_url);
let directory = RegistryDirectory::new(Box::new(registry));
builder = builder.with_directory(Box::new(directory));
} else {
builder = builder.with_host("http://127.0.0.1:8888");
}

let mut cli = GreeterClient::new(builder);

let zkr = ZookeeperRegistry::default();
let directory = RegistryDirectory::new(Box::new(zkr));
let mut cli = GreeterClient::new(ClientBuilder::new().with_registry_directory(directory));
// using loop for loadbalance test
println!("# unary call");
let resp = cli
.greet(Request::new(GreeterRequest {
Expand Down
3 changes: 2 additions & 1 deletion registry/nacos/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ repository = "https://github.com/apache/dubbo-rust.git"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
nacos-sdk = { version = "0.2", features = ["naming", "auth-by-http"] }
nacos-sdk = { version = "0.2.3", features = ["naming", "auth-by-http"] }
dubbo.workspace = true
serde_json.workspace = true
serde = { workspace = true, features = ["derive"] }
anyhow.workspace = true
logger.workspace = true
[dev-dependencies]
tracing-subscriber = "0.3.16"
tracing = "0.1"
2 changes: 1 addition & 1 deletion registry/nacos/src/nacos_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const INNERCLASS_SYMBOL: &str = "$";
const INNERCLASS_COMPATIBLE_SYMBOL: &str = "___";

pub struct NacosRegistry {
nacos_naming_service: Arc<dyn NamingService>,
nacos_naming_service: Arc<dyn NamingService + Sync + Send + 'static>,
listeners: Mutex<HashMap<String, HashSet<Arc<NotifyListenerWrapper>>>>,
}

Expand Down