首页  

nacos Java客户端使用     所属分类 nacos 浏览量 1466
引入依赖
com.alibaba.nacos:nacos-client:1.1.4


服务注册与发现

Properties properties = new Properties();
// 127.0.0.1:8848,127.0.0.1:8858
properties.setProperty("serverAddr", "127.0.0.1:8848");

NamingService naming = NamingFactory.createNamingService(properties);

void registerInstance(String serviceName, String ip, int port) throws NacosException;
void registerInstance(String serviceName, String groupName, String ip, int port) throws NacosException;

void deregisterInstance(String serviceName, String ip, int port) throws NacosException;
void deregisterInstance(String serviceName, String groupName, String ip, int port) throws NacosException;

List< Instance > getAllInstances(String serviceName) throws NacosException;
List< Instance > getAllInstances(String serviceName, String groupName) throws NacosException;


配置中心 配置更新读取删除 

ConfigService configService = NacosFactory.createConfigService(properties);

String getConfig(String dataId, String group, long timeoutMs) throws NacosException;
boolean publishConfig(String dataId, String group, String content) throws NacosException;
void addListener(String dataId, String group, Listener listener) throws NacosException;
boolean removeConfig(String dataId, String group) throws NacosException;


完整代码
https://gitee.com/dyyx/nacosdemo/blob/master/clientdemo/src/main/java/dyyx/NacosDemo.java

官方例子
https://github.com/nacos-group/nacos-examples



rest 接口


服务注册
curl -X POST 'http://127.0.0.1:8848/nacos/v1/ns/instance?serviceName=service001&ip=127.0.0.1&port=8080'

服务发现
curl -X GET 'http://127.0.0.1:8848/nacos/v1/ns/instance/list?serviceName=service001'

发布配置
curl -X POST "http://127.0.0.1:8848/nacos/v1/cs/configs?dataId=data001&group=test&content=hello"

获取配置
curl -X GET "http://127.0.0.1:8848/nacos/v1/cs/configs?dataId=data001&group=test"

上一篇     下一篇
三十条架构设计原则

单体应用vs微服务

nacos介绍

threadlocal实例及原理

使用int作为key的IntHashMap

netty高性能要点