abstract class Server {
protected messageHandlers: Map<string, MessageHandler>
protected logger: LoggerService
protected serializer: ConsumerSerializer
protected deserializer: ConsumerDeserializer
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>) => unknown): Subscription
handleEvent(pattern: string, packet: ReadPacket<any>, context: BaseRpcContext<unknown[]>): Promise<any>
transformToObservable(resultOrDeferred: any)
getOptionsProp<T extends MicroserviceOptions['options'], K extends keyof T>(obj: T, prop: K, defaultValue: T[K] = undefined)
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
}
Methods
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>) => unknown): Subscription
Parameters
Option |
Type |
Description |
stream$
|
Observable |
|
respond
|
(data: WritePacket) => unknown |
|
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<T extends MicroserviceOptions['options'], K extends keyof T>(obj: T, prop: K, defaultValue: T[K] = undefined)
Parameters
Option |
Type |
Description |
obj
|
T |
|
prop
|
K |
|
defaultValue
|
T[K] |
Optional. Default is undefined .
|
|
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
|