Compare commits
2 Commits
Author | SHA1 | Date |
---|---|---|
|
c834d4af57 | |
|
9491d6f604 |
|
@ -3,11 +3,8 @@
|
||||||
const NacosConfigClient = require('nacos').NacosConfigClient;
|
const NacosConfigClient = require('nacos').NacosConfigClient;
|
||||||
|
|
||||||
const configClient = new NacosConfigClient({
|
const configClient = new NacosConfigClient({
|
||||||
serverAddr: 'aliyun.nacos.net:80',
|
serverAddr: '106.14.43.196:8848',
|
||||||
namespace: '',
|
namespace: '',
|
||||||
// 如果nacos开启了认证鉴权,需要在此处填写用户名密码
|
|
||||||
// username: 'xxx',
|
|
||||||
// password: 'xxx'
|
|
||||||
});
|
});
|
||||||
|
|
||||||
function sleep(time){
|
function sleep(time){
|
||||||
|
@ -21,7 +18,7 @@ function sleep(time){
|
||||||
(async () => {
|
(async () => {
|
||||||
await configClient.ready();
|
await configClient.ready();
|
||||||
|
|
||||||
const dataId = 'nacos.test.22';
|
const dataId = 'nacos.test.1';
|
||||||
const group = 'DEFAULT_GROUP';
|
const group = 'DEFAULT_GROUP';
|
||||||
const str = `example_test_${Math.random()}_${Date.now()}`;
|
const str = `example_test_${Math.random()}_${Date.now()}`;
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,6 @@
|
||||||
"name": "nacos-example",
|
"name": "nacos-example",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"nacos": "^2.5.0"
|
"nacos": "^1.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,5 +16,5 @@
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"version": "2.6.0"
|
"version": "2.5.2"
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
"ci": "npm run cov",
|
"ci": "npm run cov",
|
||||||
"build": "lerna run build && cp ./README.md ./packages/nacos/README.md"
|
"build": "lerna run build && cp ./README.md ./packages/nacos/README.md"
|
||||||
},
|
},
|
||||||
"license": "Apache-2.0",
|
"license": "Apache",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/nacos-group/nacos-sdk-nodejs/issues"
|
"url": "https://github.com/nacos-group/nacos-sdk-nodejs/issues"
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "nacos-config",
|
"name": "nacos-config",
|
||||||
"version": "2.6.0",
|
"version": "2.5.2",
|
||||||
"description": "nacos config client",
|
"description": "nacos config client",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"nacos-config",
|
"nacos-config",
|
||||||
|
|
|
@ -142,7 +142,7 @@ export class HttpAgent {
|
||||||
// 携带统一的头部信息
|
// 携带统一的头部信息
|
||||||
Object.assign(headers, {
|
Object.assign(headers, {
|
||||||
'Client-Version': VERSION,
|
'Client-Version': VERSION,
|
||||||
'Content-Type': 'application/x-www-form-urlencoded; charset=GBK',
|
'Content-Type': 'application/x-www-form-urlencoded; charset=utf8',
|
||||||
'Spas-AccessKey': this.accessKey,
|
'Spas-AccessKey': this.accessKey,
|
||||||
timeStamp: ts,
|
timeStamp: ts,
|
||||||
exConfigInfo: 'true',
|
exConfigInfo: 'true',
|
||||||
|
|
|
@ -262,8 +262,6 @@ export interface ClientOptions {
|
||||||
serverAddr?: string; // 用于直连,包含端口
|
serverAddr?: string; // 用于直连,包含端口
|
||||||
unit?: string; // 内部单元化用
|
unit?: string; // 内部单元化用
|
||||||
nameServerAddr?: string; // 老的兼容参数,逐步废弃,同 endpoint
|
nameServerAddr?: string; // 老的兼容参数,逐步废弃,同 endpoint
|
||||||
username?: string; // 认证的用户名
|
|
||||||
password?: string; // 认证的密码
|
|
||||||
cacheDir?: string; // 缓存文件的路径
|
cacheDir?: string; // 缓存文件的路径
|
||||||
identityKey?: string; // Identity Key
|
identityKey?: string; // Identity Key
|
||||||
identityValue?: string; // Identity Value
|
identityValue?: string; // Identity Value
|
||||||
|
|
|
@ -3,35 +3,14 @@
|
||||||
* Create Time: 2021/8/20 9:12
|
* Create Time: 2021/8/20 9:12
|
||||||
*/
|
*/
|
||||||
interface Instance {
|
interface Instance {
|
||||||
instanceId: string,
|
|
||||||
ip: string, //IP of instance
|
ip: string, //IP of instance
|
||||||
port: number, //Port of instance
|
port: number, //Port of instance
|
||||||
healthy: boolean,
|
|
||||||
enabled: boolean,
|
|
||||||
serviceName?: string,
|
|
||||||
weight?: number,
|
weight?: number,
|
||||||
ephemeral?: boolean,
|
ephemeral?: boolean,
|
||||||
clusterName?: string
|
clusterName?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Host {
|
type Hosts = string[];
|
||||||
instanceId: string;
|
|
||||||
ip: string;
|
|
||||||
port: number;
|
|
||||||
weight: number;
|
|
||||||
healthy: boolean;
|
|
||||||
enabled: boolean;
|
|
||||||
ephemeral: boolean;
|
|
||||||
clusterName: string;
|
|
||||||
serviceName: string;
|
|
||||||
metadata: any;
|
|
||||||
instanceHeartBeatInterval: number;
|
|
||||||
instanceIdGenerator: string;
|
|
||||||
instanceHeartBeatTimeOut: number;
|
|
||||||
ipDeleteTimeout: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
type Hosts = Host[];
|
|
||||||
|
|
||||||
interface SubscribeInfo {
|
interface SubscribeInfo {
|
||||||
serviceName: string,
|
serviceName: string,
|
||||||
|
@ -39,22 +18,11 @@ interface SubscribeInfo {
|
||||||
clusters?: string
|
clusters?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
interface NacosNamingClientConfig {
|
|
||||||
logger: typeof console,
|
|
||||||
serverList: string | string[],
|
|
||||||
namespace?: string,
|
|
||||||
username?: string,
|
|
||||||
password?: string,
|
|
||||||
endpoint?: string,
|
|
||||||
vipSrvRefInterMillis?: number,
|
|
||||||
ssl?: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Nacos服务发现组件
|
* Nacos服务发现组件
|
||||||
*/
|
*/
|
||||||
export class NacosNamingClient {
|
export class NacosNamingClient {
|
||||||
constructor (config: NacosNamingClientConfig);
|
constructor (config: { logger: typeof console, serverList: string | string[], namespace?: string })
|
||||||
|
|
||||||
ready: () => Promise<void>;
|
ready: () => Promise<void>;
|
||||||
// Register an instance to service
|
// Register an instance to service
|
||||||
|
@ -76,14 +44,6 @@ export class NacosNamingClient {
|
||||||
clusters?: string, //Cluster names
|
clusters?: string, //Cluster names
|
||||||
subscribe?: boolean //whether subscribe the service, default is true
|
subscribe?: boolean //whether subscribe the service, default is true
|
||||||
) => Promise<Hosts>;
|
) => Promise<Hosts>;
|
||||||
// Select instance list of service.
|
|
||||||
selectInstances: (
|
|
||||||
serviceName: string,
|
|
||||||
groupName?: string,
|
|
||||||
clusters?: string,
|
|
||||||
healthy?: boolean,
|
|
||||||
subscribe?: boolean
|
|
||||||
) => Promise<Hosts>;
|
|
||||||
// Get the status of nacos server, 'UP' or 'DOWN'.
|
// Get the status of nacos server, 'UP' or 'DOWN'.
|
||||||
getServerStatus: () => 'UP' | 'DOWN';
|
getServerStatus: () => 'UP' | 'DOWN';
|
||||||
subscribe: (
|
subscribe: (
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "nacos-naming",
|
"name": "nacos-naming",
|
||||||
"version": "2.6.0",
|
"version": "2.5.0",
|
||||||
"description": "nacos (https://nacos.io/en-us/) nodejs sdk",
|
"description": "nacos (https://nacos.io/en-us/) nodejs sdk",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"files": [
|
"files": [
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "nacos",
|
"name": "nacos",
|
||||||
"version": "2.6.0",
|
"version": "2.5.2",
|
||||||
"description": "nacos client main package",
|
"description": "nacos client main package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"nacos",
|
"nacos",
|
||||||
|
@ -12,8 +12,8 @@
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"author": "czy88840616@gmail.com",
|
"author": "czy88840616@gmail.com",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"nacos-config": "^2.6.0",
|
"nacos-config": "^2.5.2",
|
||||||
"nacos-naming": "^2.6.0"
|
"nacos-naming": "^2.5.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/mocha": "^5.2.5",
|
"@types/mocha": "^5.2.5",
|
||||||
|
|
Loading…
Reference in New Issue