@microde/microservice / Microservice
Class: Microservice
Defined in: microservice.ts:130
Composes modules and coordinates their complete lifecycle.
A microservice instance can run only once. Install all modules before calling run.
Example
const service = new Microservice();
service.install((context) => new DatabaseModule(context));
const result = await service.run();
process.exitCode = result.exitCode;
Constructors
Constructor
new Microservice():
Microservice
Defined in: microservice.ts:150
Returns
Microservice
Accessors
state
Get Signature
get state():
MicroserviceState
Defined in: microservice.ts:161
The service's current lifecycle state.
Returns
Methods
bind()
bind<
Consumer,Provider>(consumer,slotName,target):void
Defined in: microservice.ts:219
Binds one declared relationship slot to an exact installed module.
Type Parameters
Consumer
Consumer extends MicroserviceModule
Provider
Provider extends MicroserviceModule
Parameters
consumer
ModuleHandle<Consumer>
slotName
string
target
ModuleHandle<Provider>
Returns
void
install()
Call Signature
install<
Module>(id,factory):ModuleHandle<Module>
Defined in: microservice.ts:172
Creates and installs a module.
Type Parameters
Module
Module extends MicroserviceModule
Parameters
id
string
factory
(context) => Module
A synchronous factory that receives the module-facing context.
Returns
ModuleHandle<Module>
The installed module.
Throws
If called after execution has started, or if another installation is in progress.
Call Signature
install<
Module>(factory):Module
Defined in: microservice.ts:176
Creates and installs a module.
Type Parameters
Module
Module extends MicroserviceModule
Parameters
factory
(context) => Module
A synchronous factory that receives the module-facing context.
Returns
Module
The installed module.
Throws
If called after execution has started, or if another installation is in progress.
panic()
panic(
error?):never
Defined in: microservice.ts:366
Logs an optional fatal error and terminates the process immediately.
This bypasses the normal module shutdown lifecycle.
Parameters
error?
unknown
Returns
never
run()
run():
Promise<MicroserviceExecutionResult>
Defined in: microservice.ts:326
Runs the module lifecycle once.
Lifecycle failures are represented in the resolved result so cleanup can
finish before the caller receives the outcome. Calling run more than once
returns a rejected promise.
Returns
Promise<MicroserviceExecutionResult>
stop()
Call Signature
stop():
Promise<MicroserviceExecutionResult>
Defined in: microservice.ts:375
Requests an orderly stop.
Returns
Promise<MicroserviceExecutionResult>
Call Signature
stop(
exitCode):Promise<MicroserviceExecutionResult>
Defined in: microservice.ts:377
Requests an orderly stop with a specific exit code.
Parameters
exitCode
number
Returns
Promise<MicroserviceExecutionResult>
Call Signature
stop(
error):Promise<MicroserviceExecutionResult>
Defined in: microservice.ts:379
Requests an orderly stop caused by an error.
Parameters
error
unknown
Returns
Promise<MicroserviceExecutionResult>
Call Signature
stop(
exitCode,error):Promise<MicroserviceExecutionResult>
Defined in: microservice.ts:381
Requests an orderly stop with both an exit code and error.
Parameters
exitCode
number
error
unknown
Returns
Promise<MicroserviceExecutionResult>