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

ReadMe doc is outdated,need update. #249

Open
linglongchen opened this issue Nov 25, 2024 · 2 comments
Open

ReadMe doc is outdated,need update. #249

linglongchen opened this issue Nov 25, 2024 · 2 comments

Comments

@linglongchen
Copy link

async fn regi_nacos(webConf: &WebServerConfig) {
// 请注意!一般情况下,应用下仅需一个 Naming 客户端,而且需要长期持有直至应用停止。
// 因为它内部会初始化与服务端的长链接,后续的数据交互及变更订阅,都是实时地通过长链接告知客户端的。
let naming_service = NamingServiceBuilder::new(
ClientProps::new()
.server_addr("127.0.0.1:8848")
// Attention! "public" is "", it is recommended to customize the namespace with clear meaning.
.namespace("")
.app_name("simple_app"),
)
.enable_auth_plugin_http()
.build();

pub struct ExampleInstanceChangeListener;

impl NamingEventListener for ExampleInstanceChangeListener {
    fn event(&self, event: std::sync::Arc<NamingChangeEvent>) {
        tracing::info!("subscriber notify event={:?}", event);
    }
}

// // example naming subscriber
// let subscriber = Arc::new(ExampleInstanceChangeListener);
// let _subscribe_ret = naming_service.subscribe(
//     "test-service".to_string(),
//     Some(constants::DEFAULT_GROUP.to_string()),
//     Vec::default(),
//     subscriber,
// ).await;

// example naming register instances
let service_instance1 = ServiceInstance {
    ip: "127.0.0.1".to_string(),
    port: webConf.port.clone() as i32,
    ..Default::default()
};
use nacos_sdk::api::naming::NamingService; //add this import otherwise exception
//use unwrap
let _register_instance_ret = naming_service.unwrap().batch_register_instance(
    "test-service".to_string(),
    Some(constants::DEFAULT_GROUP.to_string()),
    vec![service_instance1],
).await;

}

@CherishCai
Copy link
Collaborator

这应该是个小问题?依赖自行引入即可

@CherishCai
Copy link
Collaborator

你的使用中,没有仅一个 naming_service 并保持它,可以参考 examples/lazy_app.rs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants