@fluojs/microservices 1.0.0-beta.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.ko.md +182 -0
- package/README.md +179 -0
- package/dist/decorators.d.ts +51 -0
- package/dist/decorators.d.ts.map +1 -0
- package/dist/decorators.js +106 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/metadata.d.ts +9 -0
- package/dist/metadata.d.ts.map +1 -0
- package/dist/metadata.js +48 -0
- package/dist/module.d.ts +23 -0
- package/dist/module.d.ts.map +1 -0
- package/dist/module.js +55 -0
- package/dist/service.d.ts +116 -0
- package/dist/service.d.ts.map +1 -0
- package/dist/service.js +550 -0
- package/dist/status.d.ts +30 -0
- package/dist/status.d.ts.map +1 -0
- package/dist/status.js +79 -0
- package/dist/tokens.d.ts +7 -0
- package/dist/tokens.d.ts.map +1 -0
- package/dist/tokens.js +4 -0
- package/dist/transports/event-handler-logger.d.ts +3 -0
- package/dist/transports/event-handler-logger.d.ts.map +1 -0
- package/dist/transports/event-handler-logger.js +3 -0
- package/dist/transports/grpc-transport.d.ts +193 -0
- package/dist/transports/grpc-transport.d.ts.map +1 -0
- package/dist/transports/grpc-transport.js +1035 -0
- package/dist/transports/kafka-transport.d.ts +77 -0
- package/dist/transports/kafka-transport.d.ts.map +1 -0
- package/dist/transports/kafka-transport.js +289 -0
- package/dist/transports/mqtt-transport.d.ts +124 -0
- package/dist/transports/mqtt-transport.d.ts.map +1 -0
- package/dist/transports/mqtt-transport.js +460 -0
- package/dist/transports/nats-transport.d.ts +92 -0
- package/dist/transports/nats-transport.d.ts.map +1 -0
- package/dist/transports/nats-transport.js +218 -0
- package/dist/transports/rabbitmq-transport.d.ts +77 -0
- package/dist/transports/rabbitmq-transport.d.ts.map +1 -0
- package/dist/transports/rabbitmq-transport.js +263 -0
- package/dist/transports/redis-streams-transport.d.ts +136 -0
- package/dist/transports/redis-streams-transport.d.ts.map +1 -0
- package/dist/transports/redis-streams-transport.js +482 -0
- package/dist/transports/redis-transport.d.ts +73 -0
- package/dist/transports/redis-transport.d.ts.map +1 -0
- package/dist/transports/redis-transport.js +152 -0
- package/dist/transports/tcp-transport.d.ts +66 -0
- package/dist/transports/tcp-transport.d.ts.map +1 -0
- package/dist/transports/tcp-transport.js +283 -0
- package/dist/types.d.ts +105 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/package.json +105 -0
package/dist/module.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Provider } from '@fluojs/di';
|
|
2
|
+
import { type ModuleType } from '@fluojs/runtime';
|
|
3
|
+
import type { MicroserviceModuleOptions } from './types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Creates DI providers for the microservice runtime and transport options.
|
|
6
|
+
*
|
|
7
|
+
* @param options Microservice transport configuration consumed by the runtime lifecycle service.
|
|
8
|
+
* @returns Provider definitions that register `MICROSERVICE_OPTIONS`, `MicroserviceLifecycleService`, and the compatibility alias `MICROSERVICE`.
|
|
9
|
+
*/
|
|
10
|
+
export declare function createMicroservicesProviders(options: MicroserviceModuleOptions): Provider[];
|
|
11
|
+
/**
|
|
12
|
+
* Runtime module entrypoint for registering microservice transport wiring.
|
|
13
|
+
*/
|
|
14
|
+
export declare class MicroservicesModule {
|
|
15
|
+
/**
|
|
16
|
+
* Registers the microservice runtime providers as a global module.
|
|
17
|
+
*
|
|
18
|
+
* @param options Transport and handler runtime options for the microservice lifecycle service.
|
|
19
|
+
* @returns A module definition that exports `MicroserviceLifecycleService` and the compatibility token `MICROSERVICE`.
|
|
20
|
+
*/
|
|
21
|
+
static forRoot(options: MicroserviceModuleOptions): ModuleType;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=module.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAgB,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAIhE,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAE5D;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,yBAAyB,GAAG,QAAQ,EAAE,CA2B3F;AAED;;GAEG;AACH,qBAAa,mBAAmB;IAC9B;;;;;OAKG;IACH,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,yBAAyB,GAAG,UAAU;CAgB/D"}
|
package/dist/module.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { defineModule } from '@fluojs/runtime';
|
|
2
|
+
import { MicroserviceLifecycleService } from './service.js';
|
|
3
|
+
import { MICROSERVICE, MICROSERVICE_OPTIONS } from './tokens.js';
|
|
4
|
+
/**
|
|
5
|
+
* Creates DI providers for the microservice runtime and transport options.
|
|
6
|
+
*
|
|
7
|
+
* @param options Microservice transport configuration consumed by the runtime lifecycle service.
|
|
8
|
+
* @returns Provider definitions that register `MICROSERVICE_OPTIONS`, `MicroserviceLifecycleService`, and the compatibility alias `MICROSERVICE`.
|
|
9
|
+
*/
|
|
10
|
+
export function createMicroservicesProviders(options) {
|
|
11
|
+
return [{
|
|
12
|
+
provide: MICROSERVICE_OPTIONS,
|
|
13
|
+
useValue: options
|
|
14
|
+
}, MicroserviceLifecycleService, {
|
|
15
|
+
inject: [MicroserviceLifecycleService],
|
|
16
|
+
provide: MICROSERVICE,
|
|
17
|
+
useFactory: service => {
|
|
18
|
+
const runtime = service;
|
|
19
|
+
return {
|
|
20
|
+
bidiStream: runtime.bidiStream ? (pattern, signal) => runtime.bidiStream(pattern, signal) : undefined,
|
|
21
|
+
clientStream: runtime.clientStream ? (pattern, signal) => runtime.clientStream(pattern, signal) : undefined,
|
|
22
|
+
close: _signal => runtime.close(),
|
|
23
|
+
emit: (pattern, payload) => runtime.emit(pattern, payload),
|
|
24
|
+
listen: () => runtime.listen(),
|
|
25
|
+
send: (pattern, payload, signal) => runtime.send(pattern, payload, signal),
|
|
26
|
+
serverStream: runtime.serverStream ? (pattern, payload, signal) => runtime.serverStream(pattern, payload, signal) : undefined
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Runtime module entrypoint for registering microservice transport wiring.
|
|
34
|
+
*/
|
|
35
|
+
export class MicroservicesModule {
|
|
36
|
+
/**
|
|
37
|
+
* Registers the microservice runtime providers as a global module.
|
|
38
|
+
*
|
|
39
|
+
* @param options Transport and handler runtime options for the microservice lifecycle service.
|
|
40
|
+
* @returns A module definition that exports `MicroserviceLifecycleService` and the compatibility token `MICROSERVICE`.
|
|
41
|
+
*/
|
|
42
|
+
static forRoot(options) {
|
|
43
|
+
class MicroservicesModuleDefinition {}
|
|
44
|
+
const additionalExports = options.module?.additionalExports ?? [];
|
|
45
|
+
const additionalProviders = options.module?.providers ?? [];
|
|
46
|
+
const global = options.module?.global ?? true;
|
|
47
|
+
return defineModule(MicroservicesModuleDefinition, {
|
|
48
|
+
exports: [MicroserviceLifecycleService, MICROSERVICE, ...additionalExports],
|
|
49
|
+
global,
|
|
50
|
+
providers: [...createMicroservicesProviders({
|
|
51
|
+
transport: options.transport
|
|
52
|
+
}), ...additionalProviders]
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import type { Container } from '@fluojs/di';
|
|
2
|
+
import { type ApplicationLogger, type CompiledModule, type MicroserviceRuntime, type OnApplicationShutdown } from '@fluojs/runtime';
|
|
3
|
+
import type { Microservice, MicroserviceModuleOptions, ServerStreamWriter } from './types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Lifecycle-managed microservice runtime that discovers pattern handlers and binds them to a transport.
|
|
6
|
+
*
|
|
7
|
+
* The service resolves singleton or request-scoped handlers, exposes programmatic
|
|
8
|
+
* send/emit/stream APIs, and delegates transport-specific I/O to the configured adapter.
|
|
9
|
+
*/
|
|
10
|
+
export declare class MicroserviceLifecycleService implements Microservice, MicroserviceRuntime, OnApplicationShutdown {
|
|
11
|
+
private readonly runtimeContainer;
|
|
12
|
+
private readonly compiledModules;
|
|
13
|
+
private readonly logger;
|
|
14
|
+
private readonly moduleOptions;
|
|
15
|
+
private readonly descriptors;
|
|
16
|
+
private readonly handlerInstances;
|
|
17
|
+
private lifecycleState;
|
|
18
|
+
private lastListenError;
|
|
19
|
+
private listening;
|
|
20
|
+
private listenPromise;
|
|
21
|
+
constructor(runtimeContainer: Container, compiledModules: readonly CompiledModule[], logger: ApplicationLogger, moduleOptions: MicroserviceModuleOptions);
|
|
22
|
+
/**
|
|
23
|
+
* Starts transport listeners and discovers decorated handlers.
|
|
24
|
+
*
|
|
25
|
+
* @returns A promise that resolves once the configured transport is ready to accept traffic.
|
|
26
|
+
*/
|
|
27
|
+
listen(): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* Closes the configured transport and stops accepting microservice traffic.
|
|
30
|
+
*
|
|
31
|
+
* @returns A promise that resolves once shutdown completes.
|
|
32
|
+
*/
|
|
33
|
+
close(): Promise<void>;
|
|
34
|
+
onApplicationShutdown(): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Creates a platform status snapshot for health checks and diagnostics.
|
|
37
|
+
*
|
|
38
|
+
* @returns A structured snapshot describing handler counts, transport capabilities, and lifecycle state.
|
|
39
|
+
*/
|
|
40
|
+
createPlatformStatusSnapshot(): import("./status.js").MicroservicePlatformStatusSnapshot;
|
|
41
|
+
/**
|
|
42
|
+
* Sends one request-response message through the configured transport.
|
|
43
|
+
*
|
|
44
|
+
* @param pattern Pattern identifying the remote handler.
|
|
45
|
+
* @param payload Serializable payload forwarded to the transport.
|
|
46
|
+
* @param signal Optional abort signal passed to the transport.
|
|
47
|
+
* @returns The transport response payload.
|
|
48
|
+
*/
|
|
49
|
+
send(pattern: string, payload: unknown, signal?: AbortSignal): Promise<unknown>;
|
|
50
|
+
/**
|
|
51
|
+
* Emits one fire-and-forget event through the configured transport.
|
|
52
|
+
*
|
|
53
|
+
* @param pattern Pattern identifying the remote event channel.
|
|
54
|
+
* @param payload Serializable payload forwarded to the transport.
|
|
55
|
+
* @returns A promise that resolves once the transport accepts the event.
|
|
56
|
+
*/
|
|
57
|
+
emit(pattern: string, payload: unknown): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Opens a server-streaming request through the configured transport.
|
|
60
|
+
*
|
|
61
|
+
* @param pattern Pattern identifying the remote server-stream handler.
|
|
62
|
+
* @param payload Serializable request payload forwarded to the transport.
|
|
63
|
+
* @param signal Optional abort signal passed to the transport.
|
|
64
|
+
* @returns An async iterable of stream messages.
|
|
65
|
+
*
|
|
66
|
+
* @throws {Error} When the configured transport does not implement `serverStream()`.
|
|
67
|
+
*/
|
|
68
|
+
serverStream(pattern: string, payload: unknown, signal?: AbortSignal): AsyncIterable<unknown>;
|
|
69
|
+
/**
|
|
70
|
+
* Opens a client-streaming request through the configured transport.
|
|
71
|
+
*
|
|
72
|
+
* @param pattern Pattern identifying the remote client-stream handler.
|
|
73
|
+
* @param signal Optional abort signal passed to the transport.
|
|
74
|
+
* @returns A writer for request chunks plus a promise for the final response.
|
|
75
|
+
*
|
|
76
|
+
* @throws {Error} When the configured transport does not implement `clientStream()`.
|
|
77
|
+
*/
|
|
78
|
+
clientStream(pattern: string, signal?: AbortSignal): {
|
|
79
|
+
writer: ServerStreamWriter;
|
|
80
|
+
result: Promise<unknown>;
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* Opens a bidirectional stream through the configured transport.
|
|
84
|
+
*
|
|
85
|
+
* @param pattern Pattern identifying the remote bidi-stream handler.
|
|
86
|
+
* @param signal Optional abort signal passed to the transport.
|
|
87
|
+
* @returns A reader for response chunks and a writer for outbound chunks.
|
|
88
|
+
*
|
|
89
|
+
* @throws {Error} When the configured transport does not implement `bidiStream()`.
|
|
90
|
+
*/
|
|
91
|
+
bidiStream(pattern: string, signal?: AbortSignal): {
|
|
92
|
+
reader: AsyncIterable<unknown>;
|
|
93
|
+
writer: ServerStreamWriter;
|
|
94
|
+
};
|
|
95
|
+
private dispatchPacket;
|
|
96
|
+
private dispatchServerStream;
|
|
97
|
+
private invokeServerStreamHandler;
|
|
98
|
+
private invokeResolvedServerStreamHandler;
|
|
99
|
+
private dispatchClientStream;
|
|
100
|
+
private invokeClientStreamHandler;
|
|
101
|
+
private invokeResolvedClientStreamHandler;
|
|
102
|
+
private dispatchBidiStream;
|
|
103
|
+
private invokeBidiStreamHandler;
|
|
104
|
+
private invokeResolvedBidiStreamHandler;
|
|
105
|
+
private dispatchEventHandlers;
|
|
106
|
+
private invokeResolvedHandlerInScope;
|
|
107
|
+
private matchesPattern;
|
|
108
|
+
private discoverHandlerDescriptors;
|
|
109
|
+
private dedupeKey;
|
|
110
|
+
private isDuplicate;
|
|
111
|
+
private discoveryCandidates;
|
|
112
|
+
private invokeHandler;
|
|
113
|
+
private invokeResolvedHandler;
|
|
114
|
+
private resolveSingletonHandlerInstance;
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAY,MAAM,YAAY,CAAC;AACtD,OAAO,EACL,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACxB,KAAK,qBAAqB,EAC3B,MAAM,iBAAiB,CAAC;AAMzB,OAAO,KAAK,EAGV,YAAY,EACZ,yBAAyB,EAEzB,kBAAkB,EAEnB,MAAM,YAAY,CAAC;AA6BpB;;;;;GAKG;AACH,qBACa,4BAA6B,YAAW,YAAY,EAAE,mBAAmB,EAAE,qBAAqB;IASzG,OAAO,CAA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