@danqiusheng/nest-nacos 1.0.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -0
- package/LICENSE +21 -21
- package/README.en.md +197 -0
- package/README.md +353 -385
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/nacos-config.service.d.ts +25 -45
- package/dist/nacos-config.service.d.ts.map +1 -1
- package/dist/nacos-config.service.js +241 -102
- package/dist/nacos-config.service.js.map +1 -1
- package/dist/nacos-naming.service.d.ts +16 -46
- package/dist/nacos-naming.service.d.ts.map +1 -1
- package/dist/nacos-naming.service.js +119 -88
- package/dist/nacos-naming.service.js.map +1 -1
- package/dist/nacos.decorators.d.ts +0 -4
- package/dist/nacos.decorators.d.ts.map +1 -1
- package/dist/nacos.decorators.js +1 -12
- package/dist/nacos.decorators.js.map +1 -1
- package/dist/nacos.health.d.ts +2 -6
- package/dist/nacos.health.d.ts.map +1 -1
- package/dist/nacos.health.js +5 -25
- package/dist/nacos.health.js.map +1 -1
- package/dist/nacos.interfaces.d.ts +85 -57
- package/dist/nacos.interfaces.d.ts.map +1 -1
- package/dist/nacos.module.d.ts +2 -11
- package/dist/nacos.module.d.ts.map +1 -1
- package/dist/nacos.module.js +22 -19
- package/dist/nacos.module.js.map +1 -1
- package/dist/nacos.providers.d.ts +4 -11
- package/dist/nacos.providers.d.ts.map +1 -1
- package/dist/nacos.providers.js +37 -23
- package/dist/nacos.providers.js.map +1 -1
- package/dist/nacos.utils.d.ts +6 -0
- package/dist/nacos.utils.d.ts.map +1 -0
- package/dist/nacos.utils.js +79 -0
- package/dist/nacos.utils.js.map +1 -0
- package/package.json +19 -10
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nacos-naming.service.d.ts","sourceRoot":"","sources":["../src/nacos-naming.service.ts"],"names":[],"mappings":"AAAA
|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M,EAClB,QAAQ,CAAC,EAAE,MAAM,EACjB,OAAO,UAAO,EACd,SAAS,UAAO,GACf,OAAO,CAAC,oBAAoB,EAAE,CAAC;IAQ5B,cAAc,CAClB,WAAW,EAAE,MAAM,EACnB,SAAS,GAAE,6BAAkC,GAC5C,OAAO,CAAC,oBAAoB,CAAC;IAqBhC,SAAS,CACP,IAAI,EAAE,MAAM,GAAG;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,EAC7E,QAAQ,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,KAAK,IAAI,GAC/B,IAAI;IASP,WAAW,CACT,IAAI,EAAE,MAAM,GAAG;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,EAC7E,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,KAAK,IAAI,GAChC,IAAI;IAaD,eAAe,IAAI,OAAO,CAAC,IAAI,GAAG,MAAM,CAAC;IAK/C,sBAAsB,IAAI,oBAAoB,EAAE;IAOhD,YAAY,IAAI,iBAAiB,GAAG,IAAI;IAIxC,OAAO,CAAC,QAAQ;IAYhB,OAAO,CAAC,eAAe;IAKvB,OAAO,CAAC,YAAY;IAKpB,OAAO,CAAC,eAAe;CAIxB"}
|
|
@@ -14,132 +14,163 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
14
14
|
var NacosNamingService_1;
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
16
|
exports.NacosNamingService = void 0;
|
|
17
|
-
/**
|
|
18
|
-
* NestJS Nacos 插件 - Naming 服务(服务发现/注册)
|
|
19
|
-
*
|
|
20
|
-
* 封装 NacosNamingClient,负责:
|
|
21
|
-
* - 客户端生命周期管理(初始化 / 关闭)
|
|
22
|
-
* - 服务实例自动注册与注销
|
|
23
|
-
* - 服务订阅与实例查询
|
|
24
|
-
*/
|
|
25
17
|
const common_1 = require("@nestjs/common");
|
|
26
18
|
const nacos_constants_1 = require("./nacos.constants");
|
|
19
|
+
const nacos_utils_1 = require("./nacos.utils");
|
|
27
20
|
let NacosNamingService = NacosNamingService_1 = class NacosNamingService {
|
|
28
21
|
constructor(client, options) {
|
|
29
22
|
this.client = client;
|
|
30
23
|
this.options = options;
|
|
31
24
|
this.logger = new common_1.Logger(NacosNamingService_1.name);
|
|
32
|
-
/** 已注册的实例配置(用于模块销毁时注销) */
|
|
33
25
|
this.registeredInstances = [];
|
|
26
|
+
this.subscriptions = new Map();
|
|
27
|
+
this.roundRobinIndexes = new Map();
|
|
34
28
|
}
|
|
35
|
-
/** 模块初始化:等待客户端就绪 + 自动注册实例 */
|
|
36
29
|
async onModuleInit() {
|
|
37
|
-
if (!this.client)
|
|
38
|
-
this.logger.warn('NacosNamingClient 未初始化,Naming 功能跳过');
|
|
30
|
+
if (!this.client)
|
|
39
31
|
return;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
// 自动注册配置中的服务实例
|
|
44
|
-
const instances = this.options?.instances ?? [];
|
|
45
|
-
for (const inst of instances) {
|
|
46
|
-
await this.register(inst);
|
|
47
|
-
}
|
|
32
|
+
await (0, nacos_utils_1.withRetry)(() => this.client.ready(), this.options?.retry);
|
|
33
|
+
for (const instance of this.options?.instances ?? [])
|
|
34
|
+
await this.register(instance);
|
|
48
35
|
}
|
|
49
|
-
/** 模块销毁:注销所有已注册实例 + 关闭客户端 */
|
|
50
36
|
async onModuleDestroy() {
|
|
51
37
|
if (!this.client)
|
|
52
38
|
return;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
39
|
+
try {
|
|
40
|
+
for (const instance of [...this.registeredInstances]) {
|
|
41
|
+
try {
|
|
42
|
+
await this.deregister(instance);
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
this.logger.error(`Failed to deregister ${instance.serviceName}`, error);
|
|
46
|
+
}
|
|
60
47
|
}
|
|
48
|
+
for (const subscription of this.subscriptions.values())
|
|
49
|
+
subscription.clear();
|
|
50
|
+
this.subscriptions.clear();
|
|
51
|
+
}
|
|
52
|
+
finally {
|
|
53
|
+
const close = this.client.close;
|
|
54
|
+
if (typeof close === 'function')
|
|
55
|
+
await close.call(this.client);
|
|
61
56
|
}
|
|
62
|
-
this.logger.log('NacosNamingClient 已关闭');
|
|
63
57
|
}
|
|
64
|
-
|
|
65
|
-
* 注册服务实例
|
|
66
|
-
* @param inst 实例配置
|
|
67
|
-
*/
|
|
68
|
-
async register(inst) {
|
|
58
|
+
async register(instance) {
|
|
69
59
|
if (!this.client)
|
|
70
|
-
throw new Error('NacosNamingClient
|
|
71
|
-
const { serviceName, ip, port, groupName, ...rest } =
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* 注销服务实例
|
|
83
|
-
* @param inst 实例配置
|
|
84
|
-
*/
|
|
85
|
-
async deregister(inst) {
|
|
60
|
+
throw new Error('NacosNamingClient is not initialized');
|
|
61
|
+
const { serviceName, ip, port, groupName, ...rest } = instance;
|
|
62
|
+
await (0, nacos_utils_1.withRetry)(() => this.client.registerInstance(serviceName, { ip, port, ...rest }, groupName), this.options?.retry);
|
|
63
|
+
const existing = this.registeredInstances.findIndex((item) => this.sameInstance(item, instance));
|
|
64
|
+
if (existing >= 0)
|
|
65
|
+
this.registeredInstances[existing] = { ...instance };
|
|
66
|
+
else
|
|
67
|
+
this.registeredInstances.push({ ...instance });
|
|
68
|
+
}
|
|
69
|
+
async deregister(instance) {
|
|
86
70
|
if (!this.client)
|
|
87
|
-
throw new Error('NacosNamingClient
|
|
88
|
-
const { serviceName, ip, port, groupName } =
|
|
89
|
-
await this.client.deregisterInstance(serviceName, { ip, port }, groupName);
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
*/
|
|
71
|
+
throw new Error('NacosNamingClient is not initialized');
|
|
72
|
+
const { serviceName, ip, port, groupName } = instance;
|
|
73
|
+
await (0, nacos_utils_1.withRetry)(() => this.client.deregisterInstance(serviceName, { ip, port }, groupName), this.options?.retry);
|
|
74
|
+
const index = this.registeredInstances.findIndex((item) => this.sameInstance(item, instance));
|
|
75
|
+
if (index >= 0)
|
|
76
|
+
this.registeredInstances.splice(index, 1);
|
|
77
|
+
}
|
|
78
|
+
async updateWeight(instance, weight) {
|
|
79
|
+
if (!Number.isFinite(weight) || weight < 0)
|
|
80
|
+
throw new Error('weight must be a non-negative number');
|
|
81
|
+
await this.register({ ...instance, weight });
|
|
82
|
+
}
|
|
100
83
|
async getAllInstances(serviceName, groupName, clusters, subscribe = true) {
|
|
101
84
|
if (!this.client)
|
|
102
|
-
throw new Error('NacosNamingClient
|
|
103
|
-
return this.client.getAllInstances(serviceName, groupName, clusters, subscribe);
|
|
85
|
+
throw new Error('NacosNamingClient is not initialized');
|
|
86
|
+
return (0, nacos_utils_1.withRetry)(() => this.client.getAllInstances(serviceName, groupName, clusters, subscribe), this.options?.retry);
|
|
104
87
|
}
|
|
105
|
-
/**
|
|
106
|
-
* 查询健康实例
|
|
107
|
-
*/
|
|
108
88
|
async selectInstances(serviceName, groupName, clusters, healthy = true, subscribe = true) {
|
|
109
89
|
if (!this.client)
|
|
110
|
-
throw new Error('NacosNamingClient
|
|
111
|
-
return this.client.selectInstances(serviceName, groupName, clusters, healthy, subscribe);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
90
|
+
throw new Error('NacosNamingClient is not initialized');
|
|
91
|
+
return (0, nacos_utils_1.withRetry)(() => this.client.selectInstances(serviceName, groupName, clusters, healthy, subscribe), this.options?.retry);
|
|
92
|
+
}
|
|
93
|
+
async selectInstance(serviceName, selection = {}) {
|
|
94
|
+
const instances = await this.selectInstances(serviceName, selection.groupName, selection.clusters, true, selection.subscribe ?? true);
|
|
95
|
+
const eligible = instances.filter((instance) => this.matchesMetadata(instance, selection.metadata));
|
|
96
|
+
if (eligible.length === 0)
|
|
97
|
+
throw new Error(`No healthy instance available for ${serviceName}`);
|
|
98
|
+
const strategy = selection.strategy ?? 'random';
|
|
99
|
+
if (strategy === 'roundRobin') {
|
|
100
|
+
const key = `${selection.groupName ?? 'DEFAULT_GROUP'}@@${serviceName}@@${selection.clusters ?? ''}`;
|
|
101
|
+
const index = this.roundRobinIndexes.get(key) ?? 0;
|
|
102
|
+
this.roundRobinIndexes.set(key, (index + 1) % eligible.length);
|
|
103
|
+
return eligible[index % eligible.length];
|
|
104
|
+
}
|
|
105
|
+
if (strategy === 'weighted')
|
|
106
|
+
return this.weighted(eligible);
|
|
107
|
+
return eligible[Math.floor(Math.random() * eligible.length)];
|
|
108
|
+
}
|
|
118
109
|
subscribe(info, listener) {
|
|
119
110
|
if (!this.client)
|
|
120
|
-
throw new Error('NacosNamingClient
|
|
111
|
+
throw new Error('NacosNamingClient is not initialized');
|
|
121
112
|
this.client.subscribe(info, listener);
|
|
122
|
-
this.
|
|
113
|
+
const key = this.subscriptionKey(info);
|
|
114
|
+
const listeners = this.subscriptions.get(key) ?? new Set();
|
|
115
|
+
listeners.add(listener);
|
|
116
|
+
this.subscriptions.set(key, listeners);
|
|
123
117
|
}
|
|
124
|
-
/**
|
|
125
|
-
* 取消订阅
|
|
126
|
-
*/
|
|
127
118
|
unSubscribe(info, listener) {
|
|
128
119
|
if (!this.client)
|
|
129
|
-
throw new Error('NacosNamingClient
|
|
130
|
-
|
|
131
|
-
this.
|
|
120
|
+
throw new Error('NacosNamingClient is not initialized');
|
|
121
|
+
this.client.unSubscribe(info, listener);
|
|
122
|
+
const key = this.subscriptionKey(info);
|
|
123
|
+
if (listener) {
|
|
124
|
+
const listeners = this.subscriptions.get(key);
|
|
125
|
+
listeners?.delete(listener);
|
|
126
|
+
if (listeners?.size === 0)
|
|
127
|
+
this.subscriptions.delete(key);
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
this.subscriptions.delete(key);
|
|
131
|
+
}
|
|
132
132
|
}
|
|
133
|
-
|
|
134
|
-
getServerStatus() {
|
|
133
|
+
async getServerStatus() {
|
|
135
134
|
if (!this.client)
|
|
136
135
|
return 'DOWN';
|
|
137
|
-
return this.client.getServerStatus();
|
|
136
|
+
return Promise.resolve(this.client.getServerStatus());
|
|
137
|
+
}
|
|
138
|
+
getRegisteredInstances() {
|
|
139
|
+
return this.registeredInstances.map((instance) => ({
|
|
140
|
+
...instance,
|
|
141
|
+
metadata: instance.metadata ? { ...instance.metadata } : undefined,
|
|
142
|
+
}));
|
|
138
143
|
}
|
|
139
|
-
/** 获取原始客户端(需要使用高级 API 时) */
|
|
140
144
|
getRawClient() {
|
|
141
145
|
return this.client;
|
|
142
146
|
}
|
|
147
|
+
weighted(instances) {
|
|
148
|
+
const weights = instances.map((instance) => Math.max(0, instance.weight ?? 1));
|
|
149
|
+
const total = weights.reduce((sum, weight) => sum + weight, 0);
|
|
150
|
+
if (total <= 0)
|
|
151
|
+
return instances[Math.floor(Math.random() * instances.length)];
|
|
152
|
+
let cursor = Math.random() * total;
|
|
153
|
+
for (let index = 0; index < instances.length; index++) {
|
|
154
|
+
cursor -= weights[index];
|
|
155
|
+
if (cursor < 0)
|
|
156
|
+
return instances[index];
|
|
157
|
+
}
|
|
158
|
+
return instances[instances.length - 1];
|
|
159
|
+
}
|
|
160
|
+
matchesMetadata(instance, metadata) {
|
|
161
|
+
if (!metadata)
|
|
162
|
+
return true;
|
|
163
|
+
return Object.entries(metadata).every(([key, value]) => instance.metadata?.[key] === value);
|
|
164
|
+
}
|
|
165
|
+
sameInstance(left, right) {
|
|
166
|
+
return left.serviceName === right.serviceName && left.ip === right.ip && left.port === right.port &&
|
|
167
|
+
(left.groupName ?? 'DEFAULT_GROUP') === (right.groupName ?? 'DEFAULT_GROUP');
|
|
168
|
+
}
|
|
169
|
+
subscriptionKey(info) {
|
|
170
|
+
if (typeof info === 'string')
|
|
171
|
+
return `DEFAULT_GROUP@@${info}@@`;
|
|
172
|
+
return `${info.groupName ?? 'DEFAULT_GROUP'}@@${info.serviceName}@@${info.clusters ?? ''}`;
|
|
173
|
+
}
|
|
143
174
|
};
|
|
144
175
|
exports.NacosNamingService = NacosNamingService;
|
|
145
176
|
exports.NacosNamingService = NacosNamingService = NacosNamingService_1 = __decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nacos-naming.service.js","sourceRoot":"","sources":["../src/nacos-naming.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA
|
|
1
|
+
{"version":3,"file":"nacos-naming.service.js","sourceRoot":"","sources":["../src/nacos-naming.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAqG;AAErG,uDAAuE;AAOvE,+CAA0C;AAGnC,IAAM,kBAAkB,0BAAxB,MAAM,kBAAkB;IAM7B,YAC2C,MAAiD,EACvD,OAAmD;QAD5B,WAAM,GAAN,MAAM,CAA0B;QACtC,YAAO,GAAP,OAAO,CAA2B;QAPvE,WAAM,GAAG,IAAI,eAAM,CAAC,oBAAkB,CAAC,IAAI,CAAC,CAAC;QAC7C,wBAAmB,GAA2B,EAAE,CAAC;QACjD,kBAAa,GAAG,IAAI,GAAG,EAAuC,CAAC;QAC/D,sBAAiB,GAAG,IAAI,GAAG,EAAkB,CAAC;IAK5D,CAAC;IAEJ,KAAK,CAAC,YAAY;QAChB,IAAI,CAAC,IAAI,CAAC,MAAM;YAAE,OAAO;QACzB,MAAM,IAAA,uBAAS,EAAC,GAAG,EAAE,CAAC,IAAI,CAAC,MAAO,CAAC,KAAK,EAAE,EAAE,IA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C,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC,GAAG,CAAC,KAAK,KAAK,CAAC,CAAC;IAC9F,CAAC;IAEO,YAAY,CAAC,IAA0B,EAAE,KAA2B;QAC1E,OAAO,IAAI,CAAC,WAAW,KAAK,KAAK,CAAC,WAAW,IAAI,IAAI,CAAC,EAAE,KAAK,KAAK,CAAC,EAAE,IAAI,IAAI,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI;YAC/F,CAAC,IAAI,CAAC,SAAS,IAAI,eAAe,CAAC,KAAK,CAAC,KAAK,CAAC,SAAS,IAAI,eAAe,CAAC,CAAC;IACjF,CAAC;IAEO,eAAe,CAAC,IAA6E;QACnG,IAAI,OAAO,IAAI,KAAK,QAAQ;YAAE,OAAO,kBAAkB,IAAI,IAAI,CAAC;QAChE,OAAO,GAAG,IAAI,CAAC,SAAS,IAAI,eAAe,KAAK,IAAI,CAAC,WAAW,KAAK,IAAI,CAAC,QAAQ,IAAI,EAAE,EAAE,CAAC;IAC7F,CAAC;CACF,CAAA;AAxLY,gDAAkB;6BAAlB,kBAAkB;IAD9B,IAAA,mBAAU,GAAE;IAQR,WAAA,IAAA,iBAAQ,GAAE,CAAA;IAAE,WAAA,IAAA,eAAM,EAAC,qCAAmB,CAAC,CAAA;IACvC,WAAA,IAAA,iBAAQ,GAAE,CAAA;IAAE,WAAA,IAAA,eAAM,EAAC,+BAAa,CAAC,CAAA;;GARzB,kBAAkB,CAwL9B"}
|
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
/** 注入 NacosNamingService */
|
|
2
1
|
export declare const InjectNacosNaming: () => PropertyDecorator & ParameterDecorator;
|
|
3
|
-
/** 注入 NacosConfigService */
|
|
4
2
|
export declare const InjectNacosConfig: () => PropertyDecorator & ParameterDecorator;
|
|
5
|
-
/** 注入原始 Naming 客户端(高级用法) */
|
|
6
3
|
export declare const InjectNacosNamingClient: () => PropertyDecorator & ParameterDecorator;
|
|
7
|
-
/** 注入原始 Config 客户端(高级用法) */
|
|
8
4
|
export declare const InjectNacosConfigClient: () => PropertyDecorator & ParameterDecorator;
|
|
9
5
|
//# sourceMappingURL=nacos.decorators.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nacos.decorators.d.ts","sourceRoot":"","sources":["../src/nacos.decorators.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"nacos.decorators.d.ts","sourceRoot":"","sources":["../src/nacos.decorators.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,iBAAiB,8CAAmC,CAAC;AAClE,eAAO,MAAM,iBAAiB,8CAAmC,CAAC;AAClE,eAAO,MAAM,uBAAuB,8CAAoC,CAAC;AACzE,eAAO,MAAM,uBAAuB,8CAAoC,CAAC"}
|
package/dist/nacos.decorators.js
CHANGED
|
@@ -1,27 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.InjectNacosConfigClient = exports.InjectNacosNamingClient = exports.InjectNacosConfig = exports.InjectNacosNaming = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* NestJS Nacos 插件 - 装饰器
|
|
6
|
-
*
|
|
7
|
-
* @InjectNacosNaming() — 注入 Naming 服务
|
|
8
|
-
* @InjectNacosConfig() — 注入 Config 服务
|
|
9
|
-
* @NacosConfig() — 参数装饰器:在路由/方法参数上直接获取某 dataId 的配置值(需配合 ConfigService 预加载)
|
|
10
|
-
*/
|
|
11
4
|
const common_1 = require("@nestjs/common");
|
|
12
5
|
const nacos_constants_1 = require("./nacos.constants");
|
|
13
|
-
const nacos_naming_service_1 = require("./nacos-naming.service");
|
|
14
6
|
const nacos_config_service_1 = require("./nacos-config.service");
|
|
15
|
-
|
|
7
|
+
const nacos_naming_service_1 = require("./nacos-naming.service");
|
|
16
8
|
const InjectNacosNaming = () => (0, common_1.Inject)(nacos_naming_service_1.NacosNamingService);
|
|
17
9
|
exports.InjectNacosNaming = InjectNacosNaming;
|
|
18
|
-
/** 注入 NacosConfigService */
|
|
19
10
|
const InjectNacosConfig = () => (0, common_1.Inject)(nacos_config_service_1.NacosConfigService);
|
|
20
11
|
exports.InjectNacosConfig = InjectNacosConfig;
|
|
21
|
-
/** 注入原始 Naming 客户端(高级用法) */
|
|
22
12
|
const InjectNacosNamingClient = () => (0, common_1.Inject)(nacos_constants_1.NACOS_NAMING_CLIENT);
|
|
23
13
|
exports.InjectNacosNamingClient = InjectNacosNamingClient;
|
|
24
|
-
/** 注入原始 Config 客户端(高级用法) */
|
|
25
14
|
const InjectNacosConfigClient = () => (0, common_1.Inject)(nacos_constants_1.NACOS_CONFIG_CLIENT);
|
|
26
15
|
exports.InjectNacosConfigClient = InjectNacosConfigClient;
|
|
27
16
|
//# sourceMappingURL=nacos.decorators.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nacos.decorators.js","sourceRoot":"","sources":["../src/nacos.decorators.ts"],"names":[],"mappings":";;;AAAA
|
|
1
|
+
{"version":3,"file":"nacos.decorators.js","sourceRoot":"","sources":["../src/nacos.decorators.ts"],"names":[],"mappings":";;;AAAA,2CAAwC;AACxC,uDAA6E;AAC7E,iEAA4D;AAC5D,iEAA4D;AAErD,MAAM,iBAAiB,GAAG,GAAG,EAAE,CAAC,IAAA,eAAM,EAAC,yCAAkB,CAAC,CAAC;AAArD,QAAA,iBAAiB,qBAAoC;AAC3D,MAAM,iBAAiB,GAAG,GAAG,EAAE,CAAC,IAAA,eAAM,EAAC,yCAAkB,CAAC,CAAC;AAArD,QAAA,iBAAiB,qBAAoC;AAC3D,MAAM,uBAAuB,GAAG,GAAG,EAAE,CAAC,IAAA,eAAM,EAAC,qCAAmB,CAAC,CAAC;AAA5D,QAAA,uBAAuB,2BAAqC;AAClE,MAAM,uBAAuB,GAAG,GAAG,EAAE,CAAC,IAAA,eAAM,EAAC,qCAAmB,CAAC,CAAC;AAA5D,QAAA,uBAAuB,2BAAqC"}
|
package/dist/nacos.health.d.ts
CHANGED
|
@@ -3,12 +3,8 @@ export declare class NacosHealthIndicator {
|
|
|
3
3
|
private readonly namingService;
|
|
4
4
|
private readonly logger;
|
|
5
5
|
constructor(namingService: NacosNamingService);
|
|
6
|
-
|
|
7
|
-
* 检查 Nacos 服务端连接状态
|
|
8
|
-
* @returns { status: 'up' | 'down' }
|
|
9
|
-
*/
|
|
10
|
-
isHealthy(): {
|
|
6
|
+
isHealthy(): Promise<{
|
|
11
7
|
status: 'up' | 'down';
|
|
12
|
-
}
|
|
8
|
+
}>;
|
|
13
9
|
}
|
|
14
10
|
//# sourceMappingURL=nacos.health.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nacos.health.d.ts","sourceRoot":"","sources":["../src/nacos.health.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"nacos.health.d.ts","sourceRoot":"","sources":["../src/nacos.health.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAE5D,qBACa,oBAAoB;IAGnB,OAAO,CAAC,QAAQ,CAAC,aAAa;IAF1C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAyC;gBAEnC,aAAa,EAAE,kBAAkB;IAExD,SAAS,IAAI,OAAO,CAAC;QAAE,MAAM,EAAE,IAAI,GAAG,MAAM,CAAA;KAAE,CAAC;CAStD"}
|
package/dist/nacos.health.js
CHANGED
|
@@ -11,21 +11,6 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
11
11
|
var NacosHealthIndicator_1;
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
13
|
exports.NacosHealthIndicator = void 0;
|
|
14
|
-
/**
|
|
15
|
-
* NestJS Nacos 插件 - 健康检查指示器(可选)
|
|
16
|
-
*
|
|
17
|
-
* 配合 @nestjs/terminus 使用,暴露 /health 端点时可检查 Nacos 连接状态。
|
|
18
|
-
* 用法:在 HealthController 中注入并调用 .isHealthy()
|
|
19
|
-
*
|
|
20
|
-
* import { HealthIndicatorService } from '@nestjs/terminus';
|
|
21
|
-
* @Injectable()
|
|
22
|
-
* export class HealthService {
|
|
23
|
-
* constructor(private nacos: NacosHealthIndicator) {}
|
|
24
|
-
* check() { return this.nacos.isHealthy('nacos'); }
|
|
25
|
-
* }
|
|
26
|
-
*
|
|
27
|
-
* 若未安装 @nestjs/terminus,可直接使用 isHealthy() 方法。
|
|
28
|
-
*/
|
|
29
14
|
const common_1 = require("@nestjs/common");
|
|
30
15
|
const nacos_naming_service_1 = require("./nacos-naming.service");
|
|
31
16
|
let NacosHealthIndicator = NacosHealthIndicator_1 = class NacosHealthIndicator {
|
|
@@ -33,18 +18,13 @@ let NacosHealthIndicator = NacosHealthIndicator_1 = class NacosHealthIndicator {
|
|
|
33
18
|
this.namingService = namingService;
|
|
34
19
|
this.logger = new common_1.Logger(NacosHealthIndicator_1.name);
|
|
35
20
|
}
|
|
36
|
-
|
|
37
|
-
* 检查 Nacos 服务端连接状态
|
|
38
|
-
* @returns { status: 'up' | 'down' }
|
|
39
|
-
*/
|
|
40
|
-
isHealthy() {
|
|
21
|
+
async isHealthy() {
|
|
41
22
|
try {
|
|
42
|
-
const serverStatus = this.namingService.getServerStatus();
|
|
43
|
-
|
|
44
|
-
return { status: isUp ? 'up' : 'down' };
|
|
23
|
+
const serverStatus = await this.namingService.getServerStatus();
|
|
24
|
+
return { status: serverStatus === 'UP' ? 'up' : 'down' };
|
|
45
25
|
}
|
|
46
|
-
catch (
|
|
47
|
-
this.logger.error('Nacos
|
|
26
|
+
catch (error) {
|
|
27
|
+
this.logger.error('Nacos health check failed', error);
|
|
48
28
|
return { status: 'down' };
|
|
49
29
|
}
|
|
50
30
|
}
|
package/dist/nacos.health.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nacos.health.js","sourceRoot":"","sources":["../src/nacos.health.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA
|
|
1
|
+
{"version":3,"file":"nacos.health.js","sourceRoot":"","sources":["../src/nacos.health.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAAoD;AACpD,iEAA4D;AAGrD,IAAM,oBAAoB,4BAA1B,MAAM,oBAAoB;IAG/B,YAA6B,aAAiC;QAAjC,kBAAa,GAAb,aAAa,CAAoB;QAF7C,WAAM,GAAG,IAAI,eAAM,CAAC,sBAAoB,CAAC,IAAI,CAAC,CAAC;IAEC,CAAC;IAElE,KAAK,CAAC,SAAS;QACb,IAAI,CAAC;YACH,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,eAAe,EAAE,CAAC;YAChE,OAAO,EAAE,MAAM,EAAE,YAAY,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;QAC3D,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,2BAA2B,EAAE,KAAK,CAAC,CAAC;YACtD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;QAC5B,CAAC;IACH,CAAC;CACF,CAAA;AAdY,oDAAoB;+BAApB,oBAAoB;IADhC,IAAA,mBAAU,GAAE;qCAIiC,yCAAkB;GAHnD,oBAAoB,CAchC"}
|
|
@@ -1,99 +1,127 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export type
|
|
7
|
-
|
|
1
|
+
import { ModuleMetadata, Type } from '@nestjs/common';
|
|
2
|
+
/** The current Node SDK uses the Nacos 1.x HTTP OpenAPI and supports Nacos 2.x. */
|
|
3
|
+
export type NacosTransport = 'http' | 'grpc';
|
|
4
|
+
export type NacosConfigFormat = 'auto' | 'json' | 'yaml' | 'properties' | 'txt';
|
|
5
|
+
export type NacosStartupFailureMode = 'throw' | 'fallback' | 'continue';
|
|
6
|
+
export type NacosLoadBalancingStrategy = 'random' | 'roundRobin' | 'weighted';
|
|
7
|
+
export interface NacosRetryOptions {
|
|
8
|
+
/** Total attempts, including the first call. Defaults to 3. */
|
|
9
|
+
attempts?: number;
|
|
10
|
+
/** Delay before the second attempt. Defaults to 300ms. */
|
|
11
|
+
delayMs?: number;
|
|
12
|
+
/** Delay multiplier. Defaults to 2. */
|
|
13
|
+
backoffFactor?: number;
|
|
14
|
+
/** Maximum delay between attempts. Defaults to 3000ms. */
|
|
15
|
+
maxDelayMs?: number;
|
|
16
|
+
}
|
|
8
17
|
export interface NacosNamingOptions {
|
|
9
|
-
/** Nacos 服务端地址列表,如 '127.0.0.1:8848' 或数组 */
|
|
10
18
|
serverList: string | string[];
|
|
11
|
-
/** 命名空间 ID,默认 'public' */
|
|
12
19
|
namespace?: string;
|
|
13
|
-
/**
|
|
20
|
+
/** `grpc` is rejected because nacos@2.6.x does not implement it. */
|
|
14
21
|
transport?: NacosTransport;
|
|
15
|
-
/** 用户名 */
|
|
16
22
|
username?: string;
|
|
17
|
-
/** 密码 */
|
|
18
23
|
password?: string;
|
|
19
|
-
/** 是否启用 TLS/SSL */
|
|
20
24
|
ssl?: boolean;
|
|
21
|
-
/** AccessKey(阿里云 RAM 认证) */
|
|
22
25
|
ak?: string;
|
|
23
|
-
/** SecretKey(阿里云 RAM 认证) */
|
|
24
26
|
sk?: string;
|
|
25
|
-
/** 应用名 */
|
|
26
27
|
appName?: string;
|
|
27
28
|
}
|
|
28
|
-
/** Config 客户端配置 */
|
|
29
29
|
export interface NacosConfigOptions {
|
|
30
|
-
/** Nacos 服务端地址列表 */
|
|
31
30
|
serverAddr: string | string[];
|
|
32
|
-
/**
|
|
31
|
+
/** Empty string selects the public namespace. */
|
|
33
32
|
namespace?: string;
|
|
34
|
-
/**
|
|
33
|
+
/** `grpc` is rejected because nacos@2.6.x does not implement it. */
|
|
35
34
|
transport?: NacosTransport;
|
|
36
|
-
/** 用户名 */
|
|
37
35
|
username?: string;
|
|
38
|
-
/** 密码 */
|
|
39
36
|
password?: string;
|
|
40
|
-
/** 是否启用 TLS/SSL */
|
|
41
37
|
ssl?: boolean;
|
|
42
|
-
/** AccessKey(阿里云 RAM 认证) */
|
|
43
38
|
accessKey?: string;
|
|
44
|
-
/** SecretKey(阿里云 RAM 认证) */
|
|
45
39
|
secretKey?: string;
|
|
46
|
-
/** 签名区域 ID(v4 签名) */
|
|
47
40
|
signatureRegionId?: string;
|
|
48
41
|
}
|
|
49
|
-
/** 服务注册实例配置 */
|
|
50
42
|
export interface NacosInstanceOptions {
|
|
51
|
-
/** 服务名 */
|
|
52
43
|
serviceName: string;
|
|
53
|
-
/** 实例 IP */
|
|
54
44
|
ip: string;
|
|
55
|
-
/** 实例端口 */
|
|
56
45
|
port: number;
|
|
57
|
-
/** 权重,默认 1.0 */
|
|
58
46
|
weight?: number;
|
|
59
|
-
/** 是否临时实例(客户端存活时有效),默认 true */
|
|
60
47
|
ephemeral?: boolean;
|
|
61
|
-
/** 集群名 */
|
|
62
48
|
clusterName?: string;
|
|
63
|
-
/** 分组名,默认 'DEFAULT_GROUP' */
|
|
64
49
|
groupName?: string;
|
|
65
|
-
/** 元数据 */
|
|
66
50
|
metadata?: Record<string, string>;
|
|
67
51
|
}
|
|
68
|
-
|
|
52
|
+
export interface NacosConfigDescriptor {
|
|
53
|
+
dataId: string;
|
|
54
|
+
group?: string;
|
|
55
|
+
format?: NacosConfigFormat;
|
|
56
|
+
/** Subscribe after the initial load. Defaults to true. */
|
|
57
|
+
subscribe?: boolean;
|
|
58
|
+
/** Whether failure must stop startup when no fallback is available. Defaults to true. */
|
|
59
|
+
required?: boolean;
|
|
60
|
+
/** Optional cache file override. */
|
|
61
|
+
cachePath?: string;
|
|
62
|
+
}
|
|
63
|
+
export interface NacosConfigLoadingOptions {
|
|
64
|
+
cacheDir?: string;
|
|
65
|
+
failureMode?: NacosStartupFailureMode;
|
|
66
|
+
retry?: NacosRetryOptions;
|
|
67
|
+
}
|
|
69
68
|
export interface NacosModuleOptions {
|
|
70
|
-
/**
|
|
69
|
+
/**
|
|
70
|
+
* Shared Nacos address for both Naming and Config clients.
|
|
71
|
+
* Use the nested client options only when their addresses differ.
|
|
72
|
+
*/
|
|
73
|
+
serverAddr?: string | string[];
|
|
74
|
+
/** Shared namespace. Defaults to the public namespace. */
|
|
75
|
+
namespace?: string;
|
|
76
|
+
/** Shared username for both clients. */
|
|
77
|
+
username?: string;
|
|
78
|
+
/** Shared password for both clients. */
|
|
79
|
+
password?: string;
|
|
80
|
+
/** Shared TLS switch for both clients. */
|
|
81
|
+
ssl?: boolean;
|
|
71
82
|
naming?: NacosNamingOptions;
|
|
72
|
-
/** Config 配置中心配置(不传则不启用) */
|
|
73
83
|
config?: NacosConfigOptions;
|
|
74
|
-
/** 要注册的服务实例(可选,模块初始化时自动注册) */
|
|
75
84
|
instances?: NacosInstanceOptions[];
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
85
|
+
subscribeConfigs?: NacosConfigDescriptor[];
|
|
86
|
+
configLoading?: NacosConfigLoadingOptions;
|
|
87
|
+
retry?: NacosRetryOptions;
|
|
88
|
+
}
|
|
89
|
+
/** A server address string is shorthand for `{ serverAddr }`. */
|
|
90
|
+
export type NacosModuleOptionsInput = NacosModuleOptions | string;
|
|
91
|
+
export interface NacosOptionsFactory {
|
|
92
|
+
createNacosOptions(): Promise<NacosModuleOptionsInput> | NacosModuleOptionsInput;
|
|
81
93
|
}
|
|
82
|
-
/** 异步配置工厂 */
|
|
83
|
-
export type NacosOptionsFactory = {
|
|
84
|
-
createNacosOptions(): Promise<NacosModuleOptions> | NacosModuleOptions;
|
|
85
|
-
};
|
|
86
|
-
/** 异步模块配置 */
|
|
87
94
|
export interface NacosModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
|
|
88
|
-
/** 模块注入的 Token 名,用于多实例隔离,默认 'default' */
|
|
89
95
|
name?: string;
|
|
90
|
-
|
|
91
|
-
useFactory?: (...args: any[]) => Promise<NacosModuleOptions> | NacosModuleOptions;
|
|
92
|
-
/** 依赖注入的 Provider */
|
|
96
|
+
useFactory?: (...args: any[]) => Promise<NacosModuleOptionsInput> | NacosModuleOptionsInput;
|
|
93
97
|
inject?: any[];
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
+
useClass?: Type<NacosOptionsFactory>;
|
|
99
|
+
useExisting?: Type<NacosOptionsFactory> | string | symbol;
|
|
100
|
+
}
|
|
101
|
+
export interface NacosServiceInstance {
|
|
102
|
+
instanceId?: string;
|
|
103
|
+
ip: string;
|
|
104
|
+
port: number;
|
|
105
|
+
weight?: number;
|
|
106
|
+
healthy?: boolean;
|
|
107
|
+
enabled?: boolean;
|
|
108
|
+
ephemeral?: boolean;
|
|
109
|
+
clusterName?: string;
|
|
110
|
+
serviceName?: string;
|
|
111
|
+
metadata?: Record<string, string>;
|
|
112
|
+
}
|
|
113
|
+
export interface NacosInstanceSelectionOptions {
|
|
114
|
+
groupName?: string;
|
|
115
|
+
clusters?: string;
|
|
116
|
+
metadata?: Record<string, string>;
|
|
117
|
+
strategy?: NacosLoadBalancingStrategy;
|
|
118
|
+
subscribe?: boolean;
|
|
119
|
+
}
|
|
120
|
+
export interface NacosConfigState {
|
|
121
|
+
dataId: string;
|
|
122
|
+
group: string;
|
|
123
|
+
format: NacosConfigFormat;
|
|
124
|
+
source: 'nacos' | 'fallback';
|
|
125
|
+
updatedAt: string;
|
|
98
126
|
}
|
|
99
127
|
//# sourceMappingURL=nacos.interfaces.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nacos.interfaces.d.ts","sourceRoot":"","sources":["../src/nacos.interfaces.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"nacos.interfaces.d.ts","sourceRoot":"","sources":["../src/nacos.interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAE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