UNPKG

@phnq/message

Version:

Asynchronous, incremental messaging client and server

64 lines (63 loc) 2.07 kB
import { ConnectionOptions, NatsConnection, SubscriptionOptions } from 'nats'; import { MessageTransport, RequestMessage, ResponseMessage } from '../MessageTransport'; export interface NATSTransportConnectionOptions extends ConnectionOptions { monitorUrl?: string; /** * Sets the maximum count of per-server initial connect attempts before giving up * and throwing an error. * Set to `-1` to never give up. * * @default 1 */ maxConnectAttempts?: number; /** * Set the number of millisecods between initial connect attempts. * * @default 2000 millis */ connectTimeWait?: number; } interface NATSConnection { name?: string; lang: string; version: string; subscriptions: number; uptime: string; ip: string; cid: number; port: number; rtt: string; } type SubjectResolver<T, R> = (message: RequestMessage<T> | ResponseMessage<R>) => string; interface NATSTransportOptions<T, R> { subscriptions: (string | { subject: string; options: SubscriptionOptions; })[]; publishSubject: string | SubjectResolver<T, R>; } export declare class NATSTransport<T, R> implements MessageTransport<T, R> { static create<T, R>(config: NATSTransportConnectionOptions, options: NATSTransportOptions<T, R>): Promise<NATSTransport<T, R>>; private config; readonly nc: NatsConnection; private options; private maxPayload; private receiveHandler?; private subjectById; private chunkedMessages; private constructor(); close(): Promise<void>; getConnections(): Promise<NATSConnection[]>; send(message: RequestMessage<T> | ResponseMessage<R>): Promise<void>; onReceive(receiveHandler: (message: RequestMessage<T> | ResponseMessage<R>) => void): void; private marshall; private unmarshall; private initialize; /** * |----- ? bytes -----|| 16 || 1 || 1 | * [CHUNK_HEADER_PREFIX][uuid][index][total] */ private sendMessageInChunks; private receiveMessageChunk; } export {};