@nestjs/microservices
Version:
Microservices for NestJS: message and event handlers over Kafka, RabbitMQ, NATS, Redis, MQTT, gRPC or TCP.
74 lines (73 loc) • 3.59 kB
TypeScript
import { Observable } from 'rxjs';
import { MqttEvents, MqttStatus } from '../events/mqtt.events.js';
import { MqttOptions, PacketMetadata, ReadPacket, WritePacket } from '../interfaces/index.js';
import { MqttRecordOptions } from '../record-builders/mqtt.record-builder.js';
import { ClientProxy } from './client-proxy.js';
import { Logger } from '@nestjs/common';
type MqttClient = any;
/**
* @publicApi
*/
export declare class ClientMqtt extends ClientProxy<MqttEvents, MqttStatus> {
protected readonly options: Required<MqttOptions>['options'];
protected readonly logger: Logger;
protected readonly subscriptionsCount: Map<string, number>;
protected readonly url: string;
protected mqttClient: MqttClient | null;
protected connectionPromise: Promise<any> | null;
private closeCount;
protected isInitialConnection: boolean;
protected isReconnecting: boolean;
protected pendingEventListeners: Array<{
event: keyof MqttEvents;
callback: MqttEvents[keyof MqttEvents];
}>;
constructor(options: Required<MqttOptions>['options']);
getRequestPattern(pattern: string): string;
getResponsePattern(pattern: string): string;
close(): Promise<void>;
handleClose(): void;
connect(): Promise<any>;
/**
* Drops `client` when it is still the current one, so the next `connect()`
* call starts over with a new client. Events a dropped client emits from now
* on are ignored.
*/
private discardClient;
mergeCloseEvent<T = any>(instance: MqttClient, source$: Observable<T>): Observable<T>;
createClient(): MqttClient;
registerErrorListener(client: MqttClient): void;
registerOfflineListener(client: MqttClient): void;
registerReconnectListener(client: MqttClient): void;
registerDisconnectListener(client: MqttClient): void;
registerCloseListener(client: MqttClient): void;
registerConnectListener(client: MqttClient): void;
on<EventKey extends keyof MqttEvents = keyof MqttEvents, EventCallback extends MqttEvents[EventKey] = MqttEvents[EventKey]>(event: EventKey, callback: EventCallback): void;
unwrap<T>(): T;
createResponseCallback(): (channel: string, buffer: Buffer) => any;
protected publish(partialPacket: ReadPacket, callback: (packet: WritePacket) => any): () => void;
protected dispatchEvent(packet: ReadPacket): Promise<any>;
protected unsubscribeFromChannel(channel: string): void;
/**
* Keeps only the channels that requests wait on. Patterns can be built from
* request data (e.g., one per device), so a channel nobody waits on any
* longer must not leave an entry behind.
*/
private setSubscriptionsCount;
/**
* A topic's length is encoded in two bytes. mqtt.js only fails on a longer
* topic once it has written the start of the packet, so the broker would
* read the packets sent after it as the rest of that packet.
*/
protected assertTopicLength(topic: string): void;
/**
* A topic name cannot hold the wildcards of topic filters, nor U+0000.
* mqtt.js only checks the filters it subscribes to, so it would publish
* such a topic, and the broker would close the connection that every
* request of this client shares. A pattern can be built from request data.
*/
protected assertTopicName(topic: string): void;
protected initializeSerializer(options: MqttOptions['options']): void;
protected mergePacketOptions(requestOptions?: MqttRecordOptions, metadata?: PacketMetadata): MqttRecordOptions | undefined;
}
export {};