abstract class Server<EventsMap extends Record<string, Function> = Record<string, Function>, Status extends string = string> {
transportId?: Transport | symbol
protected messageHandlers: Map<string, MessageHandler>
protected logger: LoggerService
protected serializer: ConsumerSerializer
protected deserializer: ConsumerDeserializer
protected _status$: ReplaySubject<Status>
status: Observable<Status>
abstract on<EventKey extends keyof EventsMap = keyof EventsMap, EventCallback extends EventsMap[EventKey] = EventsMap[EventKey]>(event: EventKey, callback: EventCallback): any
abstract unwrap<T>(): T
abstract listen(callback: (...optionalParams: unknown[]) => any): any
abstract close(): any
addHandler(pattern: any, callback: MessageHandler<any, any, any>, isEventHandler: boolean = false, extras: Record<string, any> = {})
getHandlers(): Map<string, MessageHandler>
getHandlerByPattern(pattern: string): MessageHandler | null
send(stream$: Observable<any>, respond: (data: WritePacket<any>) => void | Promise<unknown>): Subscription
handleEvent(pattern: string, packet: ReadPacket<any>, context: BaseRpcContext<unknown[]>): Promise<any>
transformToObservable(resultOrDeferred: any)
getOptionsProp<Options extends MicroserviceOptions['options'], Attribute extends keyof Options, DefaultValue extends Options[Attribute] = Options[Attribute]>(obj: Options, prop: Attribute, defaultValue: DefaultValue = undefined as DefaultValue)
protected handleError(error: string)
protected loadPackage<T = any>(name: string, ctx: string, loader?: Function): T
protected initializeSerializer(options: { url?: string; maxSendMessageLength?: number; maxReceiveMessageLength?: number; maxMetadataSize?: number; keepalive?: { keepaliveTimeMs?: number; keepaliveTimeoutMs?: number; keepalivePermitWithoutCalls?: number; http2MaxPingsWithoutData?: number; http2MinTimeBetweenPingsMs?: number; http2MinPingIntervalWithoutData...)
protected initializeDeserializer(options: { url?: string; maxSendMessageLength?: number; maxReceiveMessageLength?: number; maxMetadataSize?: number; keepalive?: { keepaliveTimeMs?: number; keepaliveTimeoutMs?: number; keepalivePermitWithoutCalls?: number; http2MaxPingsWithoutData?: number; http2MinTimeBetweenPingsMs?: number; http2MinPingIntervalWithoutData...)
protected getRouteFromPattern(pattern: string): string
protected normalizePattern(pattern: MsPattern): string
}
Properties
Property |
Description |
transportId?: Transport | symbol
|
Read-only.
Unique transport identifier.
|
protected messageHandlers: Map<string, MessageHandler>
|
Read-only.
|
protected logger: LoggerService
|
Read-only.
|
protected serializer: ConsumerSerializer
|
|
protected deserializer: ConsumerDeserializer
|
|
protected _status$: ReplaySubject<Status>
|
|
status: Observable<Status>
|
Read-only.
Returns an observable that emits status changes.
|
Methods
on()
|
Registers an event listener for the given event.
|
abstract on<EventKey extends keyof EventsMap = keyof EventsMap, EventCallback extends EventsMap[EventKey] = EventsMap[EventKey]>(event: EventKey, callback: EventCallback): any
Parameters
Option |
Type |
Description |
event
|
EventKey |
Event name
|
callback
|
EventCallback |
Callback to be executed when the event is emitted
|
Returns
any
|
unwrap()
|
Returns an instance of the underlying server/broker instance,
or a group of servers if there are more than one.
|
abstract unwrap<T>(): T
Parameters
There are no parameters.
Returns
T
|
listen()
|
Method called when server is being initialized.
|
abstract listen(callback: (...optionalParams: unknown[]) => any): any
Parameters
Option |
Type |
Description |
callback
|
(...optionalParams: unknown[]) => any |
Function to be called upon initialization
|
Returns
any
|
close()
|
Method called when server is being terminated.
|
abstract close(): any
Parameters
There are no parameters.
Returns
any
|
addHandler()
|
addHandler(pattern: any, callback: MessageHandler<any, any, any>, isEventHandler: boolean = false, extras: Record<string, any> = {})
Parameters
Option |
Type |
Description |
pattern
|
any |
|
callback
|
MessageHandler |
|
isEventHandler
|
boolean |
Optional. Default is false .
|
extras
|
Record |
Optional. Default is {} .
|
|
getHandlers()
|
getHandlers(): Map<string, MessageHandler>
Parameters
There are no parameters.
Returns
Map<string, MessageHandler>
|
getHandlerByPattern()
|
getHandlerByPattern(pattern: string): MessageHandler | null
Parameters
Option |
Type |
Description |
pattern
|
string |
|
Returns
MessageHandler | null
|
send()
|
send(stream$: Observable<any>, respond: (data: WritePacket<any>) => void | Promise<unknown>): Subscription
Parameters
Option |
Type |
Description |
stream$
|
Observable |
|
respond
|
(data: WritePacket) => void | Promise |
|
Returns
Subscription
|
handleEvent()
|
handleEvent(pattern: string, packet: ReadPacket<any>, context: BaseRpcContext<unknown[]>): Promise<any>
Parameters
Returns
Promise<any>
|
|
transformToObservable<T>(resultOrDeferred: Observable<T> | Promise<T>): Observable<T>
Parameters
Option |
Type |
Description |
resultOrDeferred
|
Observable | Promise |
|
Returns
Observable<T>
|
transformToObservable<T>(resultOrDeferred: T): never extends Observable<ObservedValueOf<T>> ? Observable<T> : Observable<ObservedValueOf<T>>
Parameters
Option |
Type |
Description |
resultOrDeferred
|
T |
|
Returns
never extends Observable<ObservedValueOf<T>> ? Observable<T> : Observable<ObservedValueOf<T>>
|
getOptionsProp()
|
getOptionsProp<Options extends MicroserviceOptions['options'], Attribute extends keyof Options>(obj: Options, prop: Attribute): Options[Attribute]
Parameters
Option |
Type |
Description |
obj
|
Options |
|
prop
|
Attribute |
|
Returns
Options[Attribute]
|
getOptionsProp<Options extends MicroserviceOptions['options'], Attribute extends keyof Options, DefaultValue extends Options[Attribute] = Options[Attribute]>(obj: Options, prop: Attribute, defaultValue: DefaultValue): Required<Options>[Attribute]
Parameters
Option |
Type |
Description |
obj
|
Options |
|
prop
|
Attribute |
|
defaultValue
|
DefaultValue |
|
Returns
Required<Options>[Attribute]
|
handleError()
|
protected handleError(error: string)
Parameters
Option |
Type |
Description |
error
|
string |
|
|
loadPackage()
|
protected loadPackage<T = any>(name: string, ctx: string, loader?: Function): T
Parameters
Option |
Type |
Description |
name
|
string |
|
ctx
|
string |
|
loader
|
Function |
Optional. Default is undefined .
|
Returns
T
|
initializeSerializer()
|
protected initializeSerializer(options: { url?: string; maxSendMessageLength?: number; maxReceiveMessageLength?: number; maxMetadataSize?: number; keepalive?: { keepaliveTimeMs?: number; keepaliveTimeoutMs?: number; keepalivePermitWithoutCalls?: number; http2MaxPingsWithoutData?: number; http2MinTimeBetweenPingsMs?: number; http2MinPingIntervalWithoutData...)
Parameters
Option |
Type |
Description |
options
|
{ url?: string; maxSendMessageLength?: number; maxReceiveMessageLength?: number; maxMetadataSize?: number; keepalive?: { keepaliveTimeMs?: number; keepaliveTimeoutMs?: number; keepalivePermitWithoutCalls?: number; http2MaxPingsWithoutData?: number; http2MinTimeBetweenPingsMs?: number; http2MinPingIntervalWithoutData... |
|
|
initializeDeserializer()
|
protected initializeDeserializer(options: { url?: string; maxSendMessageLength?: number; maxReceiveMessageLength?: number; maxMetadataSize?: number; keepalive?: { keepaliveTimeMs?: number; keepaliveTimeoutMs?: number; keepalivePermitWithoutCalls?: number; http2MaxPingsWithoutData?: number; http2MinTimeBetweenPingsMs?: number; http2MinPingIntervalWithoutData...)
Parameters
Option |
Type |
Description |
options
|
{ url?: string; maxSendMessageLength?: number; maxReceiveMessageLength?: number; maxMetadataSize?: number; keepalive?: { keepaliveTimeMs?: number; keepaliveTimeoutMs?: number; keepalivePermitWithoutCalls?: number; http2MaxPingsWithoutData?: number; http2MinTimeBetweenPingsMs?: number; http2MinPingIntervalWithoutData... |
|
|
getRouteFromPattern()
|
Transforms the server Pattern to valid type and returns a route for him.
|
protected getRouteFromPattern(pattern: string): string
Parameters
Option |
Type |
Description |
pattern
|
string |
server pattern
|
Returns
string string
|
normalizePattern()
|
protected normalizePattern(pattern: MsPattern): string
Parameters
Returns
string
|