@omnitron-dev/titan-discovery 0.1.1
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/LICENSE +21 -0
- package/README.md +19 -0
- package/dist/discovery.module.d.ts +26 -0
- package/dist/discovery.module.d.ts.map +1 -0
- package/dist/discovery.module.js +109 -0
- package/dist/discovery.module.js.map +1 -0
- package/dist/discovery.service.d.ts +54 -0
- package/dist/discovery.service.d.ts.map +1 -0
- package/dist/discovery.service.js +574 -0
- package/dist/discovery.service.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/netron-integration.d.ts +28 -0
- package/dist/netron-integration.d.ts.map +1 -0
- package/dist/netron-integration.js +152 -0
- package/dist/netron-integration.js.map +1 -0
- package/dist/types.d.ts +49 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +6 -0
- package/dist/types.js.map +1 -0
- package/lua/register-heartbeat.lua +22 -0
- package/package.json +40 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 LuxQuant
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# @omnitron-dev/titan-discovery
|
|
2
|
+
|
|
3
|
+
> Redis-backed service discovery for the Titan framework
|
|
4
|
+
|
|
5
|
+
Part of the [Omni](../../README.md) monorepo — Fullstack Type-Safe RPC Framework.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add @omnitron-dev/titan-discovery
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Overview
|
|
14
|
+
|
|
15
|
+
Enables Titan services to register themselves and discover other services in a distributed environment. Uses Redis as the backing store for service registration, heartbeats, and lookup.
|
|
16
|
+
|
|
17
|
+
## License
|
|
18
|
+
|
|
19
|
+
MIT
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { IModule, IApplication } from '@omnitron-dev/titan';
|
|
2
|
+
import { type Token } from '@omnitron-dev/titan/nexus';
|
|
3
|
+
import type { DynamicModule } from '@omnitron-dev/titan/nexus';
|
|
4
|
+
import { NetronDiscoveryIntegration } from './netron-integration.js';
|
|
5
|
+
import { DiscoveryOptions, IDiscoveryService } from './types.js';
|
|
6
|
+
export interface DiscoveryModuleOptions extends DiscoveryOptions {
|
|
7
|
+
redisUrl?: string;
|
|
8
|
+
redisOptions?: any;
|
|
9
|
+
enableNetronIntegration?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare const DiscoveryModuleToken: Token<DiscoveryModule>;
|
|
12
|
+
export declare const NETRON_DISCOVERY_INTEGRATION_TOKEN: Token<NetronDiscoveryIntegration>;
|
|
13
|
+
export declare class DiscoveryModule implements IModule {
|
|
14
|
+
name: string;
|
|
15
|
+
version: string;
|
|
16
|
+
private discoveryService?;
|
|
17
|
+
private netronIntegration?;
|
|
18
|
+
private logger?;
|
|
19
|
+
static forRoot(options?: DiscoveryModuleOptions): DynamicModule;
|
|
20
|
+
onStart(app: IApplication): Promise<void>;
|
|
21
|
+
onStop(_app: IApplication): Promise<void>;
|
|
22
|
+
getService(): IDiscoveryService | undefined;
|
|
23
|
+
getNetronIntegration(): NetronDiscoveryIntegration | undefined;
|
|
24
|
+
}
|
|
25
|
+
export declare function createDiscoveryModule(options?: DiscoveryModuleOptions): DynamicModule;
|
|
26
|
+
//# sourceMappingURL=discovery.module.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discovery.module.d.ts","sourceRoot":"","sources":["../src/discovery.module.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAe,KAAK,KAAK,EAAgD,MAAM,2BAA2B,CAAC;AAClH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAK/D,OAAO,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AACrE,OAAO,EAKL,gBAAgB,EAChB,iBAAiB,EAClB,MAAM,YAAY,CAAC;AAGpB,MAAM,WAAW,sBAAuB,SAAQ,gBAAgB;IAC9D,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,GAAG,CAAC;IAMnB,uBAAuB,CAAC,EAAE,OAAO,CAAC;CACnC;AAGD,eAAO,MAAM,oBAAoB,EAAE,KAAK,CAAC,eAAe,CAAmD,CAAC;AAG5G,eAAO,MAAM,kCAAkC,EAAE,KAAK,CAAC,0BAA0B,CACV,CAAC;AAoBxE,qBAEa,eAAgB,YAAW,OAAO;IAC7C,IAAI,SAAe;IACnB,OAAO,SAAW;IAElB,OAAO,CAAC,gBAAgB,CAAC,CAAoB;IAC7C,OAAO,CAAC,iBAAiB,CAAC,CAA6B;IACvD,OAAO,CAAC,MAAM,CAAC,CAAU;IASzB,MAAM,CAAC,OAAO,CAAC,OAAO,GAAE,sBAA2B,GAAG,aAAa;IA2C7D,OAAO,CAAC,GAAG,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAmCzC,MAAM,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAsB/C,UAAU,IAAI,iBAAiB,GAAG,SAAS;IAO3C,oBAAoB,IAAI,0BAA0B,GAAG,SAAS;CAG/D;AAKD,wBAAgB,qBAAqB,CAAC,OAAO,GAAE,sBAA2B,GAAG,aAAa,CAEzF"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var DiscoveryModule_1;
|
|
8
|
+
import { Redis } from 'ioredis';
|
|
9
|
+
import { Module, Injectable } from '@omnitron-dev/titan/decorators';
|
|
10
|
+
import { createToken } from '@omnitron-dev/titan/nexus';
|
|
11
|
+
import { REDIS_MANAGER } from '@omnitron-dev/titan-redis';
|
|
12
|
+
import { DiscoveryService } from './discovery.service.js';
|
|
13
|
+
import { NetronDiscoveryIntegration } from './netron-integration.js';
|
|
14
|
+
import { DISCOVERY_SERVICE_TOKEN, REDIS_TOKEN, LOGGER_TOKEN, DISCOVERY_OPTIONS_TOKEN, } from './types.js';
|
|
15
|
+
export const DiscoveryModuleToken = createToken('DiscoveryModule');
|
|
16
|
+
export const NETRON_DISCOVERY_INTEGRATION_TOKEN = createToken('NetronDiscoveryIntegration');
|
|
17
|
+
let DiscoveryModule = DiscoveryModule_1 = class DiscoveryModule {
|
|
18
|
+
constructor() {
|
|
19
|
+
this.name = 'discovery';
|
|
20
|
+
this.version = '1.0.0';
|
|
21
|
+
}
|
|
22
|
+
static forRoot(options = {}) {
|
|
23
|
+
const mergedOptions = {
|
|
24
|
+
enableNetronIntegration: true,
|
|
25
|
+
...options,
|
|
26
|
+
};
|
|
27
|
+
const redisProvider = options.redisUrl || options.redisOptions
|
|
28
|
+
? [
|
|
29
|
+
REDIS_TOKEN,
|
|
30
|
+
{
|
|
31
|
+
useFactory: () => new Redis(options.redisUrl || options.redisOptions),
|
|
32
|
+
},
|
|
33
|
+
]
|
|
34
|
+
: [
|
|
35
|
+
REDIS_TOKEN,
|
|
36
|
+
{
|
|
37
|
+
useFactory: (manager) => manager.getInternalClient(),
|
|
38
|
+
inject: [REDIS_MANAGER],
|
|
39
|
+
},
|
|
40
|
+
];
|
|
41
|
+
const providers = [
|
|
42
|
+
[DISCOVERY_OPTIONS_TOKEN, { useValue: mergedOptions }],
|
|
43
|
+
redisProvider,
|
|
44
|
+
[DISCOVERY_SERVICE_TOKEN, { useClass: DiscoveryService }],
|
|
45
|
+
];
|
|
46
|
+
if (mergedOptions.enableNetronIntegration !== false) {
|
|
47
|
+
providers.push([NETRON_DISCOVERY_INTEGRATION_TOKEN, { useClass: NetronDiscoveryIntegration }]);
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
module: DiscoveryModule_1,
|
|
51
|
+
providers,
|
|
52
|
+
exports: [DISCOVERY_SERVICE_TOKEN, NETRON_DISCOVERY_INTEGRATION_TOKEN],
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
async onStart(app) {
|
|
56
|
+
try {
|
|
57
|
+
this.logger = app.resolve(LOGGER_TOKEN);
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
}
|
|
61
|
+
this.discoveryService = app.resolve(DISCOVERY_SERVICE_TOKEN);
|
|
62
|
+
await this.discoveryService.onStart();
|
|
63
|
+
const opts = app.resolve(DISCOVERY_OPTIONS_TOKEN);
|
|
64
|
+
if (opts.enableNetronIntegration !== false) {
|
|
65
|
+
try {
|
|
66
|
+
this.netronIntegration = app.resolve(NETRON_DISCOVERY_INTEGRATION_TOKEN);
|
|
67
|
+
if (typeof this.netronIntegration.onModuleInit === 'function') {
|
|
68
|
+
await this.netronIntegration.onModuleInit();
|
|
69
|
+
}
|
|
70
|
+
this.logger?.info('Netron-Discovery integration initialized');
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
this.logger?.debug?.({ error }, 'Netron-Discovery integration not initialized (Netron may not be available)');
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
this.logger?.info('DiscoveryModule started');
|
|
77
|
+
}
|
|
78
|
+
async onStop(_app) {
|
|
79
|
+
if (this.netronIntegration) {
|
|
80
|
+
try {
|
|
81
|
+
if (typeof this.netronIntegration.onModuleDestroy === 'function') {
|
|
82
|
+
await this.netronIntegration.onModuleDestroy();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
this.logger?.error?.({ error }, 'Error stopping Netron-Discovery integration');
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (this.discoveryService) {
|
|
90
|
+
await this.discoveryService.onStop();
|
|
91
|
+
}
|
|
92
|
+
this.logger?.info('DiscoveryModule stopped');
|
|
93
|
+
}
|
|
94
|
+
getService() {
|
|
95
|
+
return this.discoveryService;
|
|
96
|
+
}
|
|
97
|
+
getNetronIntegration() {
|
|
98
|
+
return this.netronIntegration;
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
DiscoveryModule = DiscoveryModule_1 = __decorate([
|
|
102
|
+
Injectable(),
|
|
103
|
+
Module({})
|
|
104
|
+
], DiscoveryModule);
|
|
105
|
+
export { DiscoveryModule };
|
|
106
|
+
export function createDiscoveryModule(options = {}) {
|
|
107
|
+
return DiscoveryModule.forRoot(options);
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=discovery.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discovery.module.js","sourceRoot":"","sources":["../src/discovery.module.ts"],"names":[],"mappings":";;;;;;;AAQA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAEpE,OAAO,EAAE,WAAW,EAA4D,MAAM,2BAA2B,CAAC;AAGlH,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AACrE,OAAO,EACL,uBAAuB,EACvB,WAAW,EACX,YAAY,EACZ,uBAAuB,GAGxB,MAAM,YAAY,CAAC;AAepB,MAAM,CAAC,MAAM,oBAAoB,GAA2B,WAAW,CAAkB,iBAAiB,CAAC,CAAC;AAG5G,MAAM,CAAC,MAAM,kCAAkC,GAC7C,WAAW,CAA6B,4BAA4B,CAAC,CAAC;AAsBjE,IAAM,eAAe,uBAArB,MAAM,eAAe;IAArB;QACL,SAAI,GAAG,WAAW,CAAC;QACnB,YAAO,GAAG,OAAO,CAAC;IA2HpB,CAAC;IA9GC,MAAM,CAAC,OAAO,CAAC,UAAkC,EAAE;QACjD,MAAM,aAAa,GAA2B;YAC5C,uBAAuB,EAAE,IAAI;YAC7B,GAAG,OAAO;SACX,CAAC;QAGF,MAAM,aAAa,GACjB,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,YA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,iBAAiB,CAAC;IAChC,CAAC;CACF,CAAA;AA7HY,eAAe;IAF3B,UAAU,EAAE;IACZ,MAAM,CAAC,EAAE,CAAC;GACE,eAAe,CA6H3B;;AAKD,MAAM,UAAU,qBAAqB,CAAC,UAAkC,EAAE;IACxE,OAAO,eAAe,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;AAC1C,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Redis } from 'ioredis';
|
|
2
|
+
import type { ILogger } from '@omnitron-dev/titan/module/logger';
|
|
3
|
+
import { type NodeInfo, type ServiceInfo, type DiscoveryEvent, type DiscoveryOptions, type IDiscoveryService } from './types.js';
|
|
4
|
+
import type { ILifecycle } from '@omnitron-dev/titan/types';
|
|
5
|
+
export declare class DiscoveryService implements IDiscoveryService, ILifecycle {
|
|
6
|
+
private redis;
|
|
7
|
+
private logger;
|
|
8
|
+
private nodeId;
|
|
9
|
+
private address;
|
|
10
|
+
private services;
|
|
11
|
+
private heartbeatTimer?;
|
|
12
|
+
private options;
|
|
13
|
+
private subscriber?;
|
|
14
|
+
private messageHandler?;
|
|
15
|
+
private eventEmitter;
|
|
16
|
+
private stopped;
|
|
17
|
+
private registered;
|
|
18
|
+
private shutdownPromise?;
|
|
19
|
+
constructor(redis: Redis, logger: ILogger, options?: DiscoveryOptions);
|
|
20
|
+
onInit(): Promise<void>;
|
|
21
|
+
onStart(): Promise<void>;
|
|
22
|
+
onStop(): Promise<void>;
|
|
23
|
+
onDestroy(): Promise<void>;
|
|
24
|
+
registerNode(nodeId: string, address: string, services: ServiceInfo[]): Promise<void>;
|
|
25
|
+
deregisterNode(nodeId: string): Promise<void>;
|
|
26
|
+
getActiveNodes(): Promise<NodeInfo[]>;
|
|
27
|
+
findNodesByService(serviceName: string, version?: string): Promise<NodeInfo[]>;
|
|
28
|
+
isNodeActive(nodeId: string): Promise<boolean>;
|
|
29
|
+
updateNodeAddress(nodeId: string, address: string): Promise<void>;
|
|
30
|
+
updateNodeServices(nodeId: string, services: ServiceInfo[]): Promise<void>;
|
|
31
|
+
onEvent(handler: (event: DiscoveryEvent) => void): void;
|
|
32
|
+
offEvent(handler: (event: DiscoveryEvent) => void): void;
|
|
33
|
+
private startHeartbeat;
|
|
34
|
+
private publishHeartbeat;
|
|
35
|
+
private cleanupInactiveNodes;
|
|
36
|
+
private setupPubSub;
|
|
37
|
+
private unsubscribeFromEvents;
|
|
38
|
+
private publishEvent;
|
|
39
|
+
getNodeId(): string;
|
|
40
|
+
getAddress(): string;
|
|
41
|
+
getServices(): ServiceInfo[];
|
|
42
|
+
isRegistered(): boolean;
|
|
43
|
+
findNodes(): Promise<NodeInfo[]>;
|
|
44
|
+
getAllNodes(): Promise<NodeInfo[]>;
|
|
45
|
+
getNodeInfo(nodeId: string): Promise<NodeInfo | null>;
|
|
46
|
+
nodeExists(nodeId: string): Promise<boolean>;
|
|
47
|
+
registerService(service: ServiceInfo): Promise<void>;
|
|
48
|
+
unregisterService(serviceName: string): Promise<void>;
|
|
49
|
+
updateServices(services: ServiceInfo[]): Promise<void>;
|
|
50
|
+
updateAddress(address: string): Promise<void>;
|
|
51
|
+
private generateNodeId;
|
|
52
|
+
private detectAddress;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=discovery.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discovery.service.d.ts","sourceRoot":"","sources":["../src/discovery.service.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAMhC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;AACjE,OAAO,EACL,KAAK,QAAQ,EACb,KAAK,WAAW,EAChB,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EAIvB,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AA2C5D,qBACa,gBAAiB,YAAW,iBAA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,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAkBhF,OAAO,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,IAAI,GAAG,IAAI;IAOvD,QAAQ,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,IAAI,GAAG,IAAI;YAO1C,cAAc;YAgBd,gBAAgB;YAoEhB,oBAAoB;YAiBpB,WAAW;YAiCX,qBAAqB;YAkBrB,YAAY;IAwB1B,SAAS,IAAI,MAAM;IAOnB,UAAU,IAAI,MAAM;IAOpB,WAAW,IAAI,WAAW,EAAE;IAO5B,YAAY,IAAI,OAAO;IAOjB,SAAS,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;IAkDhC,WAAW,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;IA6ClC,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;IA0BrD,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAgB5C,eAAe,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAiBpD,iBAAiB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAYrD,cAAc,CAAC,QAAQ,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAYtD,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAYnD,OAAO,CAAC,cAAc;IAWtB,OAAO,CAAC,aAAa;CAkDtB"}
|
|
@@ -0,0 +1,574 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
11
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
|
+
};
|
|
13
|
+
import { Redis } from 'ioredis';
|
|
14
|
+
import { EventEmitter } from '@omnitron-dev/eventemitter';
|
|
15
|
+
import os from 'node:os';
|
|
16
|
+
import { Injectable, Inject, Optional } from '@omnitron-dev/titan/decorators';
|
|
17
|
+
import { Errors } from '@omnitron-dev/titan/errors';
|
|
18
|
+
import { safeJsonParseWithFallback } from '@omnitron-dev/titan/utils';
|
|
19
|
+
import { REDIS_TOKEN, LOGGER_TOKEN, DISCOVERY_OPTIONS_TOKEN, } from './types.js';
|
|
20
|
+
const DEFAULT_HEARTBEAT_INTERVAL = 5000;
|
|
21
|
+
const DEFAULT_HEARTBEAT_TTL = 15000;
|
|
22
|
+
const DEFAULT_REDIS_PREFIX = 'titan:discovery';
|
|
23
|
+
const DEFAULT_PUBSUB_CHANNEL = 'titan:discovery:events';
|
|
24
|
+
const REGISTER_HEARTBEAT_SCRIPT = `
|
|
25
|
+
-- Redis Lua script for atomic heartbeat registration
|
|
26
|
+
-- KEYS: nodeKey, heartbeatKey, nodesIndexKey
|
|
27
|
+
-- ARGV: nodeId, address, services, timestamp, ttlSeconds, ttlMs
|
|
28
|
+
local nodeKey = KEYS[1]
|
|
29
|
+
local heartbeatKey = KEYS[2]
|
|
30
|
+
local nodesIndexKey = KEYS[3]
|
|
31
|
+
|
|
32
|
+
local nodeId = ARGV[1]
|
|
33
|
+
local address = ARGV[2]
|
|
34
|
+
local services = ARGV[3]
|
|
35
|
+
local timestamp = ARGV[4]
|
|
36
|
+
local ttlSeconds = tonumber(ARGV[5])
|
|
37
|
+
local ttlMs = tonumber(ARGV[6])
|
|
38
|
+
|
|
39
|
+
-- Store node information
|
|
40
|
+
redis.call('hset', nodeKey, 'address', address, 'services', services, 'timestamp', timestamp)
|
|
41
|
+
redis.call('expire', nodeKey, ttlSeconds)
|
|
42
|
+
|
|
43
|
+
-- Update heartbeat timestamp
|
|
44
|
+
redis.call('set', heartbeatKey, timestamp, 'PX', ttlMs)
|
|
45
|
+
|
|
46
|
+
-- Add to index if new
|
|
47
|
+
redis.call('sadd', nodesIndexKey, nodeId)
|
|
48
|
+
|
|
49
|
+
return 1
|
|
50
|
+
`;
|
|
51
|
+
let DiscoveryService = class DiscoveryService {
|
|
52
|
+
constructor(redis, logger, options) {
|
|
53
|
+
this.eventEmitter = new EventEmitter();
|
|
54
|
+
this.stopped = false;
|
|
55
|
+
this.registered = false;
|
|
56
|
+
if (!redis) {
|
|
57
|
+
throw Errors.badRequest('Redis instance must be provided for DiscoveryService');
|
|
58
|
+
}
|
|
59
|
+
this.redis = redis;
|
|
60
|
+
this.logger = logger;
|
|
61
|
+
this.nodeId = this.generateNodeId();
|
|
62
|
+
this.address = this.detectAddress();
|
|
63
|
+
this.services = [];
|
|
64
|
+
this.options = {
|
|
65
|
+
heartbeatInterval: options?.heartbeatInterval ?? DEFAULT_HEARTBEAT_INTERVAL,
|
|
66
|
+
heartbeatTTL: options?.heartbeatTTL ?? DEFAULT_HEARTBEAT_TTL,
|
|
67
|
+
pubSubEnabled: options?.pubSubEnabled ?? false,
|
|
68
|
+
pubSubChannel: options?.pubSubChannel ?? DEFAULT_PUBSUB_CHANNEL,
|
|
69
|
+
clientMode: options?.clientMode ?? false,
|
|
70
|
+
redisPrefix: options?.redisPrefix ?? DEFAULT_REDIS_PREFIX,
|
|
71
|
+
maxRetries: options?.maxRetries ?? 3,
|
|
72
|
+
retryDelay: options?.retryDelay ?? 1000,
|
|
73
|
+
};
|
|
74
|
+
if (this.options.clientMode) {
|
|
75
|
+
this.logger.info('DiscoveryService started in client mode (no heartbeat or node registration)');
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
this.logger.info({
|
|
79
|
+
nodeId: this.nodeId,
|
|
80
|
+
address: this.address,
|
|
81
|
+
services: this.services,
|
|
82
|
+
}, 'DiscoveryService initialized');
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
async onInit() {
|
|
86
|
+
this.logger.debug('DiscoveryService initialized');
|
|
87
|
+
}
|
|
88
|
+
async onStart() {
|
|
89
|
+
if (this.stopped) {
|
|
90
|
+
throw Errors.conflict('Cannot start a stopped DiscoveryService');
|
|
91
|
+
}
|
|
92
|
+
if (this.options.pubSubEnabled) {
|
|
93
|
+
await this.setupPubSub();
|
|
94
|
+
}
|
|
95
|
+
if (!this.options.clientMode) {
|
|
96
|
+
await this.startHeartbeat();
|
|
97
|
+
this.logger.info('DiscoveryService started');
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
async onStop() {
|
|
101
|
+
if (this.stopped) {
|
|
102
|
+
return this.shutdownPromise;
|
|
103
|
+
}
|
|
104
|
+
this.stopped = true;
|
|
105
|
+
this.shutdownPromise = (async () => {
|
|
106
|
+
this.logger.info(`Initiating graceful shutdown for node '${this.nodeId}'`);
|
|
107
|
+
if (this.heartbeatTimer) {
|
|
108
|
+
clearInterval(this.heartbeatTimer);
|
|
109
|
+
this.heartbeatTimer = undefined;
|
|
110
|
+
this.logger.debug('Heartbeat timer stopped');
|
|
111
|
+
}
|
|
112
|
+
try {
|
|
113
|
+
if (this.registered && !this.options.clientMode) {
|
|
114
|
+
await this.deregisterNode(this.nodeId);
|
|
115
|
+
this.registered = false;
|
|
116
|
+
this.logger.info(`Node '${this.nodeId}' deregistered successfully`);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
this.logger.error({ error }, `Error deregistering node '${this.nodeId}'`);
|
|
121
|
+
}
|
|
122
|
+
try {
|
|
123
|
+
if (this.subscriber) {
|
|
124
|
+
await this.unsubscribeFromEvents();
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
this.logger.error({ error }, 'Error during PubSub unsubscribe');
|
|
129
|
+
}
|
|
130
|
+
this.logger.info('DiscoveryService shutdown completed');
|
|
131
|
+
})();
|
|
132
|
+
return this.shutdownPromise;
|
|
133
|
+
}
|
|
134
|
+
async onDestroy() {
|
|
135
|
+
await this.onStop();
|
|
136
|
+
}
|
|
137
|
+
async registerNode(nodeId, address, services) {
|
|
138
|
+
this.nodeId = nodeId || this.nodeId;
|
|
139
|
+
this.address = address || this.address;
|
|
140
|
+
this.services = services || this.services;
|
|
141
|
+
if (!this.options.clientMode) {
|
|
142
|
+
await this.publishHeartbeat();
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
async deregisterNode(nodeId) {
|
|
146
|
+
const prefix = this.options.redisPrefix;
|
|
147
|
+
const nodeKey = `${prefix}:nodes:${nodeId}`;
|
|
148
|
+
const heartbeatKey = `${prefix}:heartbeat:${nodeId}`;
|
|
149
|
+
const nodesIndexKey = `${prefix}:index:nodes`;
|
|
150
|
+
const pipeline = this.redis.pipeline();
|
|
151
|
+
pipeline.del(nodeKey);
|
|
152
|
+
pipeline.del(heartbeatKey);
|
|
153
|
+
pipeline.srem(nodesIndexKey, nodeId);
|
|
154
|
+
await pipeline.exec();
|
|
155
|
+
if (this.options.pubSubEnabled) {
|
|
156
|
+
await this.publishEvent('NODE_DEREGISTERED', nodeId);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
async getActiveNodes() {
|
|
160
|
+
try {
|
|
161
|
+
const prefix = this.options.redisPrefix;
|
|
162
|
+
const nodesIndexKey = `${prefix}:index:nodes`;
|
|
163
|
+
const nodeIds = await this.redis.smembers(nodesIndexKey);
|
|
164
|
+
if (!nodeIds.length)
|
|
165
|
+
return [];
|
|
166
|
+
const pipeline = this.redis.pipeline();
|
|
167
|
+
nodeIds.forEach((id) => {
|
|
168
|
+
pipeline.hgetall(`${prefix}:nodes:${id}`);
|
|
169
|
+
pipeline.exists(`${prefix}:heartbeat:${id}`);
|
|
170
|
+
});
|
|
171
|
+
const results = await pipeline.exec();
|
|
172
|
+
const activeNodes = [];
|
|
173
|
+
const nodesToDeregister = [];
|
|
174
|
+
if (!results)
|
|
175
|
+
return activeNodes;
|
|
176
|
+
for (let i = 0; i < nodeIds.length; i++) {
|
|
177
|
+
const nodeId = nodeIds[i];
|
|
178
|
+
if (!nodeId)
|
|
179
|
+
continue;
|
|
180
|
+
const nodeDataResult = results[i * 2];
|
|
181
|
+
const heartbeatResult = results[i * 2 + 1];
|
|
182
|
+
if (!nodeDataResult || !heartbeatResult) {
|
|
183
|
+
nodesToDeregister.push(nodeId);
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
const [nodeDataErr, nodeData] = nodeDataResult;
|
|
187
|
+
const [heartbeatErr, heartbeatExists] = heartbeatResult;
|
|
188
|
+
if (nodeDataErr || heartbeatErr || !heartbeatExists || !nodeData || typeof nodeData !== 'object') {
|
|
189
|
+
nodesToDeregister.push(nodeId);
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
const nodeDataTyped = nodeData;
|
|
193
|
+
const address = typeof nodeDataTyped['address'] === 'string' ? nodeDataTyped['address'] : null;
|
|
194
|
+
const servicesRaw = typeof nodeDataTyped['services'] === 'string' ? nodeDataTyped['services'] : null;
|
|
195
|
+
const timestampRaw = typeof nodeDataTyped['timestamp'] === 'string' ? nodeDataTyped['timestamp'] : null;
|
|
196
|
+
if (!address || !servicesRaw || !timestampRaw) {
|
|
197
|
+
nodesToDeregister.push(nodeId);
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
let services;
|
|
201
|
+
try {
|
|
202
|
+
services = JSON.parse(servicesRaw);
|
|
203
|
+
}
|
|
204
|
+
catch {
|
|
205
|
+
nodesToDeregister.push(nodeId);
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
activeNodes.push({
|
|
209
|
+
nodeId,
|
|
210
|
+
address,
|
|
211
|
+
services,
|
|
212
|
+
timestamp: Number(timestampRaw),
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
if (nodesToDeregister.length > 0) {
|
|
216
|
+
await this.cleanupInactiveNodes(nodesToDeregister);
|
|
217
|
+
}
|
|
218
|
+
return activeNodes;
|
|
219
|
+
}
|
|
220
|
+
catch (error) {
|
|
221
|
+
this.logger.error({ error }, 'Error fetching active nodes');
|
|
222
|
+
throw error;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
async findNodesByService(serviceName, version) {
|
|
226
|
+
try {
|
|
227
|
+
const activeNodes = await this.getActiveNodes();
|
|
228
|
+
return activeNodes.filter((node) => node.services.some((service) => service.name === serviceName && (!version || service.version === version)));
|
|
229
|
+
}
|
|
230
|
+
catch (error) {
|
|
231
|
+
this.logger.error({ error, serviceName, version }, 'Error finding nodes by service');
|
|
232
|
+
throw error;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
async isNodeActive(nodeId) {
|
|
236
|
+
const prefix = this.options.redisPrefix;
|
|
237
|
+
const heartbeatKey = `${prefix}:heartbeat:${nodeId}`;
|
|
238
|
+
const exists = await this.redis.exists(heartbeatKey);
|
|
239
|
+
return exists === 1;
|
|
240
|
+
}
|
|
241
|
+
async updateNodeAddress(nodeId, address) {
|
|
242
|
+
if (nodeId === this.nodeId) {
|
|
243
|
+
this.address = address;
|
|
244
|
+
}
|
|
245
|
+
const prefix = this.options.redisPrefix;
|
|
246
|
+
const nodeKey = `${prefix}:nodes:${nodeId}`;
|
|
247
|
+
await this.redis.hset(nodeKey, 'address', address);
|
|
248
|
+
if (this.options.pubSubEnabled) {
|
|
249
|
+
await this.publishEvent('NODE_UPDATED', nodeId);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
async updateNodeServices(nodeId, services) {
|
|
253
|
+
if (nodeId === this.nodeId) {
|
|
254
|
+
this.services = services;
|
|
255
|
+
}
|
|
256
|
+
const prefix = this.options.redisPrefix;
|
|
257
|
+
const nodeKey = `${prefix}:nodes:${nodeId}`;
|
|
258
|
+
await this.redis.hset(nodeKey, 'services', JSON.stringify(services));
|
|
259
|
+
if (this.options.pubSubEnabled) {
|
|
260
|
+
await this.publishEvent('NODE_UPDATED', nodeId);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
onEvent(handler) {
|
|
264
|
+
this.eventEmitter.on('discovery:event', handler);
|
|
265
|
+
}
|
|
266
|
+
offEvent(handler) {
|
|
267
|
+
this.eventEmitter.off('discovery:event', handler);
|
|
268
|
+
}
|
|
269
|
+
async startHeartbeat() {
|
|
270
|
+
if (this.options.clientMode) {
|
|
271
|
+
this.logger.debug('Heartbeat disabled in client mode');
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
await this.publishHeartbeat();
|
|
275
|
+
this.heartbeatTimer = setInterval(() => this.publishHeartbeat(), this.options.heartbeatInterval);
|
|
276
|
+
}
|
|
277
|
+
async publishHeartbeat() {
|
|
278
|
+
if (this.stopped || this.options.clientMode) {
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
const prefix = this.options.redisPrefix;
|
|
282
|
+
const nodeKey = `${prefix}:nodes:${this.nodeId}`;
|
|
283
|
+
const heartbeatKey = `${prefix}:heartbeat:${this.nodeId}`;
|
|
284
|
+
const nodesIndexKey = `${prefix}:index:nodes`;
|
|
285
|
+
const maxRetries = this.options.maxRetries;
|
|
286
|
+
let lastError;
|
|
287
|
+
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
|
288
|
+
try {
|
|
289
|
+
await this.redis.eval(REGISTER_HEARTBEAT_SCRIPT, 3, nodeKey, heartbeatKey, nodesIndexKey, this.nodeId, this.address, JSON.stringify(this.services), Date.now().toString(), Math.ceil(this.options.heartbeatTTL / 1000).toString(), this.options.heartbeatTTL.toString());
|
|
290
|
+
const eventType = this.registered ? 'NODE_UPDATED' : 'NODE_REGISTERED';
|
|
291
|
+
if (!this.registered) {
|
|
292
|
+
this.registered = true;
|
|
293
|
+
}
|
|
294
|
+
if (attempt > 1) {
|
|
295
|
+
this.logger.info(`Heartbeat succeeded after ${attempt} attempts`);
|
|
296
|
+
}
|
|
297
|
+
if (this.options.pubSubEnabled) {
|
|
298
|
+
await this.publishEvent(eventType);
|
|
299
|
+
}
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
catch (error) {
|
|
303
|
+
lastError = error;
|
|
304
|
+
this.logger.warn({ error, attempt }, 'Heartbeat attempt failed');
|
|
305
|
+
if (attempt < maxRetries) {
|
|
306
|
+
await new Promise((resolve) => setTimeout(resolve, this.options.retryDelay * Math.pow(2, attempt - 1)));
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
this.logger.error({ error: lastError }, `All ${maxRetries} heartbeat attempts failed`);
|
|
311
|
+
}
|
|
312
|
+
async cleanupInactiveNodes(nodeIds) {
|
|
313
|
+
const prefix = this.options.redisPrefix;
|
|
314
|
+
const pipeline = this.redis.pipeline();
|
|
315
|
+
nodeIds.forEach((id) => {
|
|
316
|
+
pipeline.del(`${prefix}:nodes:${id}`);
|
|
317
|
+
pipeline.del(`${prefix}:heartbeat:${id}`);
|
|
318
|
+
pipeline.srem(`${prefix}:index:nodes`, id);
|
|
319
|
+
});
|
|
320
|
+
await pipeline.exec();
|
|
321
|
+
this.logger.debug({ nodeIds }, 'Cleaned up inactive nodes');
|
|
322
|
+
}
|
|
323
|
+
async setupPubSub() {
|
|
324
|
+
this.subscriber = this.redis.duplicate();
|
|
325
|
+
await this.subscriber.subscribe(this.options.pubSubChannel);
|
|
326
|
+
this.messageHandler = (channel, message) => {
|
|
327
|
+
if (channel === this.options.pubSubChannel) {
|
|
328
|
+
try {
|
|
329
|
+
const event = JSON.parse(message);
|
|
330
|
+
if (event.nodeId !== this.nodeId) {
|
|
331
|
+
this.eventEmitter.emit('discovery:event', event);
|
|
332
|
+
this.logger.debug({ event }, 'Received discovery event');
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
catch (error) {
|
|
336
|
+
this.logger.error({ error, message }, 'Failed to parse discovery event');
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
};
|
|
340
|
+
this.subscriber.on('message', this.messageHandler);
|
|
341
|
+
this.logger.debug('PubSub setup completed');
|
|
342
|
+
}
|
|
343
|
+
async unsubscribeFromEvents() {
|
|
344
|
+
if (this.subscriber) {
|
|
345
|
+
if (this.messageHandler) {
|
|
346
|
+
this.subscriber.off('message', this.messageHandler);
|
|
347
|
+
this.messageHandler = undefined;
|
|
348
|
+
}
|
|
349
|
+
await this.subscriber.unsubscribe(this.options.pubSubChannel);
|
|
350
|
+
this.subscriber.disconnect();
|
|
351
|
+
this.subscriber = undefined;
|
|
352
|
+
this.logger.debug('Unsubscribed from PubSub events');
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
async publishEvent(type, nodeId) {
|
|
356
|
+
if (!this.options.pubSubEnabled || !this.redis) {
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
const event = {
|
|
360
|
+
type,
|
|
361
|
+
nodeId: nodeId || this.nodeId,
|
|
362
|
+
address: this.address,
|
|
363
|
+
services: this.services,
|
|
364
|
+
timestamp: Date.now(),
|
|
365
|
+
};
|
|
366
|
+
try {
|
|
367
|
+
await this.redis.publish(this.options.pubSubChannel, JSON.stringify(event));
|
|
368
|
+
this.logger.debug({ event }, 'Published discovery event');
|
|
369
|
+
}
|
|
370
|
+
catch (error) {
|
|
371
|
+
this.logger.error({ error, event }, 'Failed to publish discovery event');
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
getNodeId() {
|
|
375
|
+
return this.nodeId;
|
|
376
|
+
}
|
|
377
|
+
getAddress() {
|
|
378
|
+
return this.address;
|
|
379
|
+
}
|
|
380
|
+
getServices() {
|
|
381
|
+
return [...this.services];
|
|
382
|
+
}
|
|
383
|
+
isRegistered() {
|
|
384
|
+
return this.registered;
|
|
385
|
+
}
|
|
386
|
+
async findNodes() {
|
|
387
|
+
const prefix = this.options.redisPrefix;
|
|
388
|
+
const nodesIndexKey = `${prefix}:index:nodes`;
|
|
389
|
+
try {
|
|
390
|
+
const nodeIds = await this.redis.smembers(nodesIndexKey);
|
|
391
|
+
if (nodeIds.length === 0)
|
|
392
|
+
return [];
|
|
393
|
+
const pipeline = this.redis.pipeline();
|
|
394
|
+
for (const nodeId of nodeIds) {
|
|
395
|
+
pipeline.hgetall(`${prefix}:nodes:${nodeId}`);
|
|
396
|
+
pipeline.exists(`${prefix}:heartbeat:${nodeId}`);
|
|
397
|
+
}
|
|
398
|
+
const results = await pipeline.exec();
|
|
399
|
+
if (!results)
|
|
400
|
+
return [];
|
|
401
|
+
const nodes = [];
|
|
402
|
+
for (let i = 0; i < nodeIds.length; i++) {
|
|
403
|
+
const nodeDataResult = results[i * 2];
|
|
404
|
+
const heartbeatResult = results[i * 2 + 1];
|
|
405
|
+
if (!nodeDataResult || !heartbeatResult)
|
|
406
|
+
continue;
|
|
407
|
+
const [nodeErr, nodeData] = nodeDataResult;
|
|
408
|
+
const [hbErr, isActive] = heartbeatResult;
|
|
409
|
+
if (nodeErr || hbErr)
|
|
410
|
+
continue;
|
|
411
|
+
if (nodeData && nodeData['address'] && isActive === 1) {
|
|
412
|
+
nodes.push({
|
|
413
|
+
nodeId: nodeIds[i],
|
|
414
|
+
address: nodeData['address'],
|
|
415
|
+
services: safeJsonParseWithFallback(nodeData['services'] || '[]', []),
|
|
416
|
+
timestamp: parseInt(nodeData['timestamp'] || '0'),
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
return nodes;
|
|
421
|
+
}
|
|
422
|
+
catch (error) {
|
|
423
|
+
this.logger.error({ error }, 'Failed to find nodes');
|
|
424
|
+
return [];
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
async getAllNodes() {
|
|
428
|
+
const prefix = this.options.redisPrefix;
|
|
429
|
+
const nodesIndexKey = `${prefix}:index:nodes`;
|
|
430
|
+
try {
|
|
431
|
+
const nodeIds = await this.redis.smembers(nodesIndexKey);
|
|
432
|
+
if (nodeIds.length === 0)
|
|
433
|
+
return [];
|
|
434
|
+
const pipeline = this.redis.pipeline();
|
|
435
|
+
for (const nodeId of nodeIds) {
|
|
436
|
+
pipeline.hgetall(`${prefix}:nodes:${nodeId}`);
|
|
437
|
+
}
|
|
438
|
+
const results = await pipeline.exec();
|
|
439
|
+
if (!results)
|
|
440
|
+
return [];
|
|
441
|
+
const nodes = [];
|
|
442
|
+
for (let i = 0; i < nodeIds.length; i++) {
|
|
443
|
+
const result = results[i];
|
|
444
|
+
if (!result)
|
|
445
|
+
continue;
|
|
446
|
+
const [err, nodeData] = result;
|
|
447
|
+
if (err)
|
|
448
|
+
continue;
|
|
449
|
+
if (nodeData && nodeData['address']) {
|
|
450
|
+
nodes.push({
|
|
451
|
+
nodeId: nodeIds[i],
|
|
452
|
+
address: nodeData['address'],
|
|
453
|
+
services: safeJsonParseWithFallback(nodeData['services'] || '[]', []),
|
|
454
|
+
timestamp: parseInt(nodeData['timestamp'] || '0'),
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
return nodes;
|
|
459
|
+
}
|
|
460
|
+
catch (error) {
|
|
461
|
+
this.logger.error({ error }, 'Failed to get all nodes');
|
|
462
|
+
return [];
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
async getNodeInfo(nodeId) {
|
|
466
|
+
const prefix = this.options.redisPrefix;
|
|
467
|
+
const nodeKey = `${prefix}:nodes:${nodeId}`;
|
|
468
|
+
try {
|
|
469
|
+
const nodeData = await this.redis.hgetall(nodeKey);
|
|
470
|
+
if (!nodeData || !nodeData['address']) {
|
|
471
|
+
return null;
|
|
472
|
+
}
|
|
473
|
+
return {
|
|
474
|
+
nodeId,
|
|
475
|
+
address: nodeData['address'],
|
|
476
|
+
services: safeJsonParseWithFallback(nodeData['services'] || '[]', []),
|
|
477
|
+
timestamp: parseInt(nodeData['timestamp'] || '0'),
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
catch (error) {
|
|
481
|
+
this.logger.error({ error, nodeId }, 'Failed to get node info');
|
|
482
|
+
return null;
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
async nodeExists(nodeId) {
|
|
486
|
+
const prefix = this.options.redisPrefix;
|
|
487
|
+
const nodeKey = `${prefix}:nodes:${nodeId}`;
|
|
488
|
+
try {
|
|
489
|
+
const exists = await this.redis.exists(nodeKey);
|
|
490
|
+
return exists === 1;
|
|
491
|
+
}
|
|
492
|
+
catch (error) {
|
|
493
|
+
this.logger.error({ error, nodeId }, 'Failed to check node existence');
|
|
494
|
+
return false;
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
async registerService(service) {
|
|
498
|
+
const exists = this.services.some((s) => s.name === service.name && s.version === service.version);
|
|
499
|
+
if (!exists) {
|
|
500
|
+
this.services.push(service);
|
|
501
|
+
if (this.registered && !this.options.clientMode) {
|
|
502
|
+
await this.publishHeartbeat();
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
async unregisterService(serviceName) {
|
|
507
|
+
this.services = this.services.filter((s) => s.name !== serviceName);
|
|
508
|
+
if (this.registered && !this.options.clientMode) {
|
|
509
|
+
await this.publishHeartbeat();
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
async updateServices(services) {
|
|
513
|
+
this.services = [...services];
|
|
514
|
+
if (this.registered && !this.options.clientMode) {
|
|
515
|
+
await this.publishHeartbeat();
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
async updateAddress(address) {
|
|
519
|
+
this.address = address;
|
|
520
|
+
if (this.registered && !this.options.clientMode) {
|
|
521
|
+
await this.publishHeartbeat();
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
generateNodeId() {
|
|
525
|
+
return `titan-${process.pid}-${Date.now()}-${Math.random().toString(36).substring(7)}`;
|
|
526
|
+
}
|
|
527
|
+
detectAddress() {
|
|
528
|
+
const envHost = process.env['HOST'] || process.env['TITAN_HOST'];
|
|
529
|
+
const envPort = process.env['PORT'] || process.env['TITAN_PORT'] || '3000';
|
|
530
|
+
if (envHost) {
|
|
531
|
+
return `${envHost}:${envPort}`;
|
|
532
|
+
}
|
|
533
|
+
try {
|
|
534
|
+
const interfaces = os.networkInterfaces();
|
|
535
|
+
const addresses = [];
|
|
536
|
+
for (const name of Object.keys(interfaces)) {
|
|
537
|
+
const iface = interfaces[name];
|
|
538
|
+
if (!iface)
|
|
539
|
+
continue;
|
|
540
|
+
for (const addr of iface) {
|
|
541
|
+
if (addr.family === 'IPv4') {
|
|
542
|
+
addresses.push({
|
|
543
|
+
address: addr.address,
|
|
544
|
+
internal: addr.internal,
|
|
545
|
+
family: addr.family,
|
|
546
|
+
});
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
const externalAddr = addresses.find((a) => !a.internal);
|
|
551
|
+
if (externalAddr) {
|
|
552
|
+
return `${externalAddr.address}:${envPort}`;
|
|
553
|
+
}
|
|
554
|
+
const nonLoopback = addresses.find((a) => a.address !== '127.0.0.1');
|
|
555
|
+
if (nonLoopback) {
|
|
556
|
+
return `${nonLoopback.address}:${envPort}`;
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
catch (err) {
|
|
560
|
+
this.logger.warn({ error: err.message }, 'Failed to detect network address from interfaces');
|
|
561
|
+
}
|
|
562
|
+
return `localhost:${envPort}`;
|
|
563
|
+
}
|
|
564
|
+
};
|
|
565
|
+
DiscoveryService = __decorate([
|
|
566
|
+
Injectable(),
|
|
567
|
+
__param(0, Inject(REDIS_TOKEN)),
|
|
568
|
+
__param(1, Inject(LOGGER_TOKEN)),
|
|
569
|
+
__param(2, Optional()),
|
|
570
|
+
__param(2, Inject(DISCOVERY_OPTIONS_TOKEN)),
|
|
571
|
+
__metadata("design:paramtypes", [Redis, Object, Object])
|
|
572
|
+
], DiscoveryService);
|
|
573
|
+
export { DiscoveryService };
|
|
574
|
+
//# sourceMappingURL=discovery.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discovery.service.js","sourceRoot":"","sources":["../src/discovery.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAWA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,gCAAgC,CAAC;AAC9E,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACpD,OAAO,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AAEtE,OAAO,EAML,WAAW,EACX,YAAY,EACZ,uBAAuB,GACxB,MAAM,YAAY,CAAC;AAIpB,MAAM,0BAA0B,GAAG,IAAI,CAAC;AACxC,MAAM,qBAAqB,GAAG,KAAK,CAAC;AACpC,MAAM,oBAAoB,GAAG,iBAAiB,CAAC;AAC/C,MAAM,sBAAsB,GAAG,wBAAwB,CAAC;AAKxD,MAAM,yBAAyB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;CA0BjC,CAAC;AAOK,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IAe3B,YACuB,KAAY,EACX,MAAe,EACQ,OAA0B;QARjE,iBAAY,GAAG,IAAI,YAAY,EAAE,CAAC;QAClC,YAAO,GAAG,KAAK,CAAC;QAChB,eAAU,GAAG,KAAK,CAAC;QAQzB,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,MAAM,MAAM,CAAC,UAAU,CAAC,sDAAsD,CAAC,CAAC;QAClF,CAAC;QA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AAC;YACrE,IAAI,WAAW,EAAE,CAAC;gBAChB,OAAO,GAAG,WAAW,CAAC,OAAO,IAAI,OAAO,EAAE,CAAC;YAC7C,CAAC;QACH,CAAC;QAAC,OAAO,GAAQ,EAAE,CAAC;YAClB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,GAAG,CAAC,OAAO,EAAE,EAAE,kDAAkD,CAAC,CAAC;QAC/F,CAAC;QAGD,OAAO,aAAa,OAAO,EAAE,CAAC;IAChC,CAAC;CACF,CAAA;AAxxBY,gBAAgB;IAD5B,UAAU,EAAE;IAiBR,WAAA,MAAM,CAAC,WAAW,CAAC,CAAA;IACnB,WAAA,MAAM,CAAC,YAAY,CAAC,CAAA;IACpB,WAAA,QAAQ,EAAE,CAAA;IAAE,WAAA,MAAM,CAAC,uBAAuB,CAAC,CAAA;qCAFhB,KAAK;GAhBxB,gBAAgB,CAwxB5B"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { DiscoveryModule, DiscoveryModuleToken, NETRON_DISCOVERY_INTEGRATION_TOKEN, createDiscoveryModule, } from './discovery.module.js';
|
|
2
|
+
export { DiscoveryService } from './discovery.service.js';
|
|
3
|
+
export { NetronDiscoveryIntegration } from './netron-integration.js';
|
|
4
|
+
export { DISCOVERY_SERVICE_TOKEN, REDIS_TOKEN, DISCOVERY_OPTIONS_TOKEN } from './types.js';
|
|
5
|
+
export type { NodeInfo, ServiceInfo, DiscoveryOptions, DiscoveryEvent, IDiscoveryService, } from './types.js';
|
|
6
|
+
export type { DiscoveryModuleOptions } from './discovery.module.js';
|
|
7
|
+
export type { NetronDiscoveryIntegrationOptions } from './netron-integration.js';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAmCA,OAAO,EACL,eAAe,EACf,oBAAoB,EACpB,kCAAkC,EAClC,qBAAqB,GACtB,MAAM,uBAAuB,CAAC;AAM/B,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAM1D,OAAO,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AAQrE,OAAO,EAAE,uBAAuB,EAAE,WAAW,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAM3F,YAAY,EAEV,QAAQ,EACR,WAAW,EACX,gBAAgB,EAChB,cAAc,EAGd,iBAAiB,GAClB,MAAM,YAAY,CAAC;AAEpB,YAAY,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAEpE,YAAY,EAAE,iCAAiC,EAAE,MAAM,yBAAyB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { DiscoveryModule, DiscoveryModuleToken, NETRON_DISCOVERY_INTEGRATION_TOKEN, createDiscoveryModule, } from './discovery.module.js';
|
|
2
|
+
export { DiscoveryService } from './discovery.service.js';
|
|
3
|
+
export { NetronDiscoveryIntegration } from './netron-integration.js';
|
|
4
|
+
export { DISCOVERY_SERVICE_TOKEN, REDIS_TOKEN, DISCOVERY_OPTIONS_TOKEN } from './types.js';
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAmCA,OAAO,EACL,eAAe,EACf,oBAAoB,EACpB,kCAAkC,EAClC,qBAAqB,GACtB,MAAM,uBAAuB,CAAC;AAM/B,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAM1D,OAAO,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AAQrE,OAAO,EAAE,uBAAuB,EAAE,WAAW,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type IDiscoveryService } from './types.js';
|
|
2
|
+
import type { Netron } from '@omnitron-dev/titan/netron';
|
|
3
|
+
import type { ILogger } from '@omnitron-dev/titan/module/logger';
|
|
4
|
+
export interface NetronDiscoveryIntegrationOptions {
|
|
5
|
+
enabled?: boolean;
|
|
6
|
+
registerExisting?: boolean;
|
|
7
|
+
includeMetadata?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare class NetronDiscoveryIntegration {
|
|
10
|
+
private netron;
|
|
11
|
+
private discovery;
|
|
12
|
+
private logger?;
|
|
13
|
+
private enabled;
|
|
14
|
+
private serviceExposeHandler;
|
|
15
|
+
private serviceUnexposeHandler;
|
|
16
|
+
private initialized;
|
|
17
|
+
constructor(netron: Netron | null, discovery: IDiscoveryService | null, logger?: ILogger | undefined);
|
|
18
|
+
onModuleInit(): Promise<void>;
|
|
19
|
+
onModuleDestroy(): Promise<void>;
|
|
20
|
+
private handleServiceExpose;
|
|
21
|
+
private handleServiceUnexpose;
|
|
22
|
+
private registerExistingServices;
|
|
23
|
+
setEnabled(enabled: boolean): void;
|
|
24
|
+
isEnabled(): boolean;
|
|
25
|
+
isActive(): boolean;
|
|
26
|
+
resyncServices(): Promise<void>;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=netron-integration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"netron-integration.d.ts","sourceRoot":"","sources":["../src/netron-integration.ts"],"names":[],"mappings":"AAYA,OAAO,EAA2B,KAAK,iBAAiB,EAAoB,MAAM,YAAY,CAAC;AAE/F,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAEzD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;AAMjE,MAAM,WAAW,iCAAiC;IAIhD,OAAO,CAAC,EAAE,OAAO,CAAC;IAMlB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAM3B,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAqBD,qBACa,0BAA0B;IAOD,OAAO,CAAC,MAAM;IACH,OAAO,CAAC,SAAS;IAC5B,OAAO,CAAC,MAAM,CAAC;IARnD,OAAO,CAAC,OAAO,CAAQ;IACvB,OAAO,CAAC,oBAAoB,CAAsC;IAClE,OAAO,CAAC,sBAAsB,CAAwC;IACtE,OAAO,CAAC,WAAW,CAAS;gBAGgB,MAAM,EAAE,MAAM,GAAG,IAAI,EACV,SAAS,EAAE,iBAAiB,GAAG,IAAI,EAC9C,MAAM,CAAC,EAAE,OAAO,YAAA;IAYtD,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAoC7B,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC;YAiBxB,mBAAmB;YAiCnB,qBAAqB;YAuBrB,wBAAwB;IAuCtC,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAQlC,SAAS,IAAI,OAAO;IAOpB,QAAQ,IAAI,OAAO;IAQb,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;CAStC"}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
11
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
|
+
};
|
|
13
|
+
import { Injectable, Inject, Optional, PostConstruct, PreDestroy } from '@omnitron-dev/titan/decorators';
|
|
14
|
+
import { NETRON_TOKEN } from '@omnitron-dev/titan/application';
|
|
15
|
+
import { DISCOVERY_SERVICE_TOKEN } from './types.js';
|
|
16
|
+
import { NETRON_EVENT_SERVICE_EXPOSE, NETRON_EVENT_SERVICE_UNEXPOSE } from '@omnitron-dev/titan/netron';
|
|
17
|
+
import { LOGGER_TOKEN } from './types.js';
|
|
18
|
+
let NetronDiscoveryIntegration = class NetronDiscoveryIntegration {
|
|
19
|
+
constructor(netron, discovery, logger) {
|
|
20
|
+
this.netron = netron;
|
|
21
|
+
this.discovery = discovery;
|
|
22
|
+
this.logger = logger;
|
|
23
|
+
this.enabled = true;
|
|
24
|
+
this.initialized = false;
|
|
25
|
+
this.serviceExposeHandler = this.handleServiceExpose.bind(this);
|
|
26
|
+
this.serviceUnexposeHandler = this.handleServiceUnexpose.bind(this);
|
|
27
|
+
}
|
|
28
|
+
async onModuleInit() {
|
|
29
|
+
if (this.initialized) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (!this.netron) {
|
|
33
|
+
this.logger?.debug?.('NetronDiscoveryIntegration: Netron not available, skipping integration');
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (!this.discovery) {
|
|
37
|
+
this.logger?.debug?.('NetronDiscoveryIntegration: Discovery service not available, skipping integration');
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
this.logger?.info?.('NetronDiscoveryIntegration: Initializing Netron-Discovery integration');
|
|
41
|
+
this.netron.on(NETRON_EVENT_SERVICE_EXPOSE, this.serviceExposeHandler);
|
|
42
|
+
this.netron.on(NETRON_EVENT_SERVICE_UNEXPOSE, this.serviceUnexposeHandler);
|
|
43
|
+
await this.registerExistingServices();
|
|
44
|
+
this.initialized = true;
|
|
45
|
+
this.logger?.info?.('NetronDiscoveryIntegration: Integration initialized successfully');
|
|
46
|
+
}
|
|
47
|
+
async onModuleDestroy() {
|
|
48
|
+
if (!this.initialized || !this.netron) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
this.logger?.debug?.('NetronDiscoveryIntegration: Cleaning up event listeners');
|
|
52
|
+
this.netron.off(NETRON_EVENT_SERVICE_EXPOSE, this.serviceExposeHandler);
|
|
53
|
+
this.netron.off(NETRON_EVENT_SERVICE_UNEXPOSE, this.serviceUnexposeHandler);
|
|
54
|
+
this.initialized = false;
|
|
55
|
+
}
|
|
56
|
+
async handleServiceExpose(event) {
|
|
57
|
+
if (!this.enabled || !this.discovery) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
try {
|
|
61
|
+
const serviceInfo = {
|
|
62
|
+
name: event.name,
|
|
63
|
+
version: event.version,
|
|
64
|
+
};
|
|
65
|
+
this.logger?.debug?.({ service: event.name, version: event.version }, 'NetronDiscoveryIntegration: Registering service with Discovery');
|
|
66
|
+
await this.discovery.registerService(serviceInfo);
|
|
67
|
+
this.logger?.info?.({ service: event.name, version: event.version }, 'NetronDiscoveryIntegration: Service registered with Discovery');
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
this.logger?.error?.({ error, service: event.name }, 'NetronDiscoveryIntegration: Failed to register service with Discovery');
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
async handleServiceUnexpose(event) {
|
|
74
|
+
if (!this.enabled || !this.discovery) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
try {
|
|
78
|
+
this.logger?.debug?.({ service: event.name }, 'NetronDiscoveryIntegration: Unregistering service from Discovery');
|
|
79
|
+
await this.discovery.unregisterService(event.name);
|
|
80
|
+
this.logger?.info?.({ service: event.name }, 'NetronDiscoveryIntegration: Service unregistered from Discovery');
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
this.logger?.error?.({ error, service: event.name }, 'NetronDiscoveryIntegration: Failed to unregister service from Discovery');
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
async registerExistingServices() {
|
|
87
|
+
if (!this.netron || !this.discovery) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const existingServices = this.netron.services;
|
|
91
|
+
if (existingServices.size === 0) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
this.logger?.debug?.({ count: existingServices.size }, 'NetronDiscoveryIntegration: Registering existing services');
|
|
95
|
+
for (const [qualifiedName, stub] of existingServices) {
|
|
96
|
+
try {
|
|
97
|
+
const meta = stub.definition.meta;
|
|
98
|
+
const serviceInfo = {
|
|
99
|
+
name: meta.name,
|
|
100
|
+
version: meta.version,
|
|
101
|
+
};
|
|
102
|
+
await this.discovery.registerService(serviceInfo);
|
|
103
|
+
this.logger?.debug?.({ service: meta.name, version: meta.version }, 'NetronDiscoveryIntegration: Existing service registered');
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
this.logger?.error?.({ error, qualifiedName }, 'NetronDiscoveryIntegration: Failed to register existing service');
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
setEnabled(enabled) {
|
|
111
|
+
this.enabled = enabled;
|
|
112
|
+
this.logger?.info?.({ enabled }, 'NetronDiscoveryIntegration: Integration enabled state changed');
|
|
113
|
+
}
|
|
114
|
+
isEnabled() {
|
|
115
|
+
return this.enabled;
|
|
116
|
+
}
|
|
117
|
+
isActive() {
|
|
118
|
+
return this.initialized && this.enabled && !!this.netron && !!this.discovery;
|
|
119
|
+
}
|
|
120
|
+
async resyncServices() {
|
|
121
|
+
if (!this.isActive()) {
|
|
122
|
+
this.logger?.warn?.('NetronDiscoveryIntegration: Cannot resync - integration not active');
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
this.logger?.info?.('NetronDiscoveryIntegration: Resyncing services');
|
|
126
|
+
await this.registerExistingServices();
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
__decorate([
|
|
130
|
+
PostConstruct(),
|
|
131
|
+
__metadata("design:type", Function),
|
|
132
|
+
__metadata("design:paramtypes", []),
|
|
133
|
+
__metadata("design:returntype", Promise)
|
|
134
|
+
], NetronDiscoveryIntegration.prototype, "onModuleInit", null);
|
|
135
|
+
__decorate([
|
|
136
|
+
PreDestroy(),
|
|
137
|
+
__metadata("design:type", Function),
|
|
138
|
+
__metadata("design:paramtypes", []),
|
|
139
|
+
__metadata("design:returntype", Promise)
|
|
140
|
+
], NetronDiscoveryIntegration.prototype, "onModuleDestroy", null);
|
|
141
|
+
NetronDiscoveryIntegration = __decorate([
|
|
142
|
+
Injectable(),
|
|
143
|
+
__param(0, Optional()),
|
|
144
|
+
__param(0, Inject(NETRON_TOKEN)),
|
|
145
|
+
__param(1, Optional()),
|
|
146
|
+
__param(1, Inject(DISCOVERY_SERVICE_TOKEN)),
|
|
147
|
+
__param(2, Optional()),
|
|
148
|
+
__param(2, Inject(LOGGER_TOKEN)),
|
|
149
|
+
__metadata("design:paramtypes", [Object, Object, Object])
|
|
150
|
+
], NetronDiscoveryIntegration);
|
|
151
|
+
export { NetronDiscoveryIntegration };
|
|
152
|
+
//# sourceMappingURL=netron-integration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"netron-integration.js","sourceRoot":"","sources":["../src/netron-integration.ts"],"names":[],"mappings":";;;;;;;;;;;;AAUA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AACzG,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAC/D,OAAO,EAAE,uBAAuB,EAA4C,MAAM,YAAY,CAAC;AAC/F,OAAO,EAAE,2BAA2B,EAAE,6BAA6B,EAAE,MAAM,4BAA4B,CAAC;AAIxG,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AA4CnC,IAAM,0BAA0B,GAAhC,MAAM,0BAA0B;IAMrC,YACoC,MAA6B,EAClB,SAA2C,EACtD,MAAwB;QAFhB,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EAAE;IAQR,WAAA,QAAQ,EAAE,CAAA;IAAE,WAAA,MAAM,CAAC,YAAY,CAAC,CAAA;IAChC,WAAA,QAAQ,EAAE,CAAA;IAAE,WAAA,MAAM,CAAC,uBAAuB,CAAC,CAAA;IAC3C,WAAA,QAAQ,EAAE,CAAA;IAAE,WAAA,MAAM,CAAC,YAAY,CAAC,CAAA;;GATxB,0BAA0B,CAyMtC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export interface NodeInfo {
|
|
2
|
+
nodeId: string;
|
|
3
|
+
address: string;
|
|
4
|
+
services: ServiceInfo[];
|
|
5
|
+
timestamp: number;
|
|
6
|
+
}
|
|
7
|
+
export interface ServiceInfo {
|
|
8
|
+
name: string;
|
|
9
|
+
version?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface DiscoveryOptions {
|
|
12
|
+
heartbeatInterval?: number;
|
|
13
|
+
heartbeatTTL?: number;
|
|
14
|
+
pubSubEnabled?: boolean;
|
|
15
|
+
pubSubChannel?: string;
|
|
16
|
+
clientMode?: boolean;
|
|
17
|
+
redisPrefix?: string;
|
|
18
|
+
maxRetries?: number;
|
|
19
|
+
retryDelay?: number;
|
|
20
|
+
}
|
|
21
|
+
export interface DiscoveryEvent {
|
|
22
|
+
type: 'NODE_REGISTERED' | 'NODE_UPDATED' | 'NODE_DEREGISTERED';
|
|
23
|
+
nodeId: string;
|
|
24
|
+
address: string;
|
|
25
|
+
services: ServiceInfo[];
|
|
26
|
+
timestamp: number;
|
|
27
|
+
}
|
|
28
|
+
export interface IDiscoveryService {
|
|
29
|
+
onStart(): Promise<void>;
|
|
30
|
+
onStop(): Promise<void>;
|
|
31
|
+
registerNode(nodeId: string, address: string, services: ServiceInfo[]): Promise<void>;
|
|
32
|
+
deregisterNode(nodeId: string): Promise<void>;
|
|
33
|
+
getActiveNodes(): Promise<NodeInfo[]>;
|
|
34
|
+
findNodesByService(serviceName: string, version?: string): Promise<NodeInfo[]>;
|
|
35
|
+
isNodeActive(nodeId: string): Promise<boolean>;
|
|
36
|
+
updateNodeAddress(nodeId: string, address: string): Promise<void>;
|
|
37
|
+
updateNodeServices(nodeId: string, services: ServiceInfo[]): Promise<void>;
|
|
38
|
+
onEvent(handler: (event: DiscoveryEvent) => void): void;
|
|
39
|
+
offEvent(handler: (event: DiscoveryEvent) => void): void;
|
|
40
|
+
registerService(service: ServiceInfo): Promise<void>;
|
|
41
|
+
unregisterService(serviceName: string): Promise<void>;
|
|
42
|
+
}
|
|
43
|
+
import { type Token } from '@omnitron-dev/titan/nexus';
|
|
44
|
+
import type { Redis } from 'ioredis';
|
|
45
|
+
export { LOGGER_TOKEN } from '@omnitron-dev/titan/module/logger';
|
|
46
|
+
export declare const DISCOVERY_SERVICE_TOKEN: Token<IDiscoveryService>;
|
|
47
|
+
export declare const REDIS_TOKEN: Token<Redis>;
|
|
48
|
+
export declare const DISCOVERY_OPTIONS_TOKEN: Token<DiscoveryOptions>;
|
|
49
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAWA,MAAM,WAAW,QAAQ;IAEvB,MAAM,EAAE,MAAM,CAAC;IAEf,OAAO,EAAE,MAAM,CAAC;IAEhB,QAAQ,EAAE,WAAW,EAAE,CAAC;IAExB,SAAS,EAAE,MAAM,CAAC;CACnB;AAMD,MAAM,WAAW,WAAW;IAE1B,IAAI,EAAE,MAAM,CAAC;IAEb,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAOD,MAAM,WAAW,gBAAgB;IAM/B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAO3B,YAAY,CAAC,EAAE,MAAM,CAAC;IAOtB,aAAa,CAAC,EAAE,OAAO,CAAC;IAOxB,aAAa,CAAC,EAAE,MAAM,CAAC;IAOvB,UAAU,CAAC,EAAE,OAAO,CAAC;IAMrB,WAAW,CAAC,EA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Ac,KAAK,IAAI,GAAG,IAAI,CAAC;IAMzD,eAAe,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAMrD,iBAAiB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACvD;AAED,OAAO,EAAe,KAAK,KAAK,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAsBrC,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AAKjE,eAAO,MAAM,uBAAuB,EAAE,KAAK,CAAC,iBAAiB,CAAsD,CAAC;AACpH,eAAO,MAAM,WAAW,EAAE,KAAK,CAAC,KAAK,CAA+B,CAAC;AACrE,eAAO,MAAM,uBAAuB,EAAE,KAAK,CAAC,gBAAgB,CAAqD,CAAC"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { createToken } from '@omnitron-dev/titan/nexus';
|
|
2
|
+
export { LOGGER_TOKEN } from '@omnitron-dev/titan/module/logger';
|
|
3
|
+
export const DISCOVERY_SERVICE_TOKEN = createToken('DiscoveryService');
|
|
4
|
+
export const REDIS_TOKEN = createToken('Redis');
|
|
5
|
+
export const DISCOVERY_OPTIONS_TOKEN = createToken('DiscoveryOptions');
|
|
6
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAiKA,OAAO,EAAE,WAAW,EAAc,MAAM,2BAA2B,CAAC;AAuBpE,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AAKjE,MAAM,CAAC,MAAM,uBAAuB,GAA6B,WAAW,CAAoB,kBAAkB,CAAC,CAAC;AACpH,MAAM,CAAC,MAAM,WAAW,GAAiB,WAAW,CAAQ,OAAO,CAAC,CAAC;AACrE,MAAM,CAAC,MAAM,uBAAuB,GAA4B,WAAW,CAAmB,kBAAkB,CAAC,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
-- KEYS[1] - node key (hash)
|
|
2
|
+
-- KEYS[2] - heartbeat key (string)
|
|
3
|
+
-- KEYS[3] - nodes index set
|
|
4
|
+
|
|
5
|
+
-- ARGV[1] - node id
|
|
6
|
+
-- ARGV[2] - address
|
|
7
|
+
-- ARGV[3] - services (JSON)
|
|
8
|
+
-- ARGV[4] - timestamp
|
|
9
|
+
-- ARGV[5] - node TTL (seconds)
|
|
10
|
+
-- ARGV[6] - heartbeat TTL (milliseconds)
|
|
11
|
+
|
|
12
|
+
redis.call('HMSET', KEYS[1],
|
|
13
|
+
'address', ARGV[2],
|
|
14
|
+
'services', ARGV[3],
|
|
15
|
+
'timestamp', ARGV[4]
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
redis.call('EXPIRE', KEYS[1], ARGV[5])
|
|
19
|
+
redis.call('PSETEX', KEYS[2], ARGV[6], '1')
|
|
20
|
+
redis.call('SADD', KEYS[3], ARGV[1])
|
|
21
|
+
|
|
22
|
+
return 1
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@omnitron-dev/titan-discovery",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Service discovery module for Titan framework with Redis-backed registration",
|
|
5
|
+
"author": "LuxQuant",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "dist/index.js",
|
|
9
|
+
"types": "dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"lua"
|
|
19
|
+
],
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"ioredis": "^5.8.2",
|
|
22
|
+
"@omnitron-dev/eventemitter": "0.1.1"
|
|
23
|
+
},
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"@omnitron-dev/titan": "0.1.1",
|
|
26
|
+
"@omnitron-dev/titan-redis": "0.1.1"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/node": "25.0.3",
|
|
30
|
+
"reflect-metadata": "^0.2.2",
|
|
31
|
+
"typescript": "^5.9.3",
|
|
32
|
+
"vitest": "^4.1.0"
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "rm -rf dist node_modules/.tmp && tsc -p ./tsconfig.json",
|
|
36
|
+
"test": "vitest run",
|
|
37
|
+
"clean": "rm -rf dist",
|
|
38
|
+
"typecheck": "tsc --noEmit"
|
|
39
|
+
}
|
|
40
|
+
}
|