UNPKG

@talema/graphql-azure-servicebus-subscriptions

Version:
52 lines 2.42 kB
import { PubSubEngine } from "graphql-subscriptions"; import { ServiceBusClient } from "@azure/service-bus"; import { IMessageProcessor } from "./MessageProcessor"; export interface ILogger extends Console { } /** * Represents configuration needed to wire up PubSub engine with the ServiceBus topic * @property {string} connectionString - The ServiceBus connection string. This would be the Shared Access Policy connection string. * @property {string} topicName - This would be the topic where all the events will be published. * @property {string} subscriptionName - This would be the ServiceBus topic subscription name. */ export interface IServiceBusOptions { connectionString: string; topicName: string; subscriptionName: string; } /** * An override for the in-memory PubSubEngine which connects to the Azure ServiceBus. */ export declare class ServiceBusPubSub extends PubSubEngine { private client; private sender; private reciever; private subscriptions; private options; private subject; private debugger; private eventNameKey; private subscription; private logger; private messageProcessor; constructor(options: IServiceBusOptions, logger: ILogger, messageProcessor?: IMessageProcessor, client?: ServiceBusClient); createSubscription(): { close(): Promise<void>; }; publish(eventName: string, payload: any): Promise<void>; /** * Subscribe to a specific event updates. The subscribe method would create a ServiceBusReceiver to listen to all the published events. * The method internally would filter out all the received events that are not meant for this subscriber. * @property {eventName | string} - published event name * @property {onMessage | Function} - client handler for processing received events. * @returns {Promise<number>} - returns the created identifier for the created subscription. It would be used to dispose/close any resources while unsubscribing. */ subscribe(eventName: string, onMessage: Function, options?: Object): Promise<number>; /** * Unsubscribe method would close open connection with the ServiceBus for a specific event handler. * @property {subId} - It's a unique identifier for each subscribed client. */ unsubscribe(subId: number): Promise<boolean>; private enrichMessage; } //# sourceMappingURL=ServiceBusPubSub.d.ts.map