import { Receiver } from '../receiver'; import { ContainerAdapter } from '../container'; import { CustomResolver, Handler } from '../handler'; import { HandlerDefinition, MessageBase } from '../handler/handler'; import { LoggerFactory } from '../logger'; import { RetryStrategy } from '../retry-strategy'; import { Serializer } from '../serialization'; import { Transport, TransportMessage } from '../transport'; import { ClassConstructor, Middleware } from '../util'; import { Persistence, Workflow, WorkflowState } from '../workflow'; import { BusInstance } from './bus-instance'; export interface BusInitializeOptions { /** * If true, will initialize the bus in send only mode. * This will provide a bus instance that is capable of sending/publishing * messages only and won't handle incoming messages or workflows * @default false */ sendOnly: boolean; } export declare class BusConfiguration { private configuredTransport; private concurrency; private busInstance; private container; private workflowRegistry; private handlerRegistry; private loggerFactory; private serializer; private persistence; private messageReadMiddlewares; private retryStrategy; private sendOnly; private interruptSignals; private receiver; /** * Constructs an instance of a bus from the configuration */ build(): BusInstance; /** * Configure the bus to only send messages and not receive them. No queues or subscriptions will be created for * this service. */ asSendOnly(): this; /** * Register a handler for a specific message type. When Bus is initialized it will configure * the transport to subscribe to this type of message and upon receipt will forward the message * through to the provided message handler * @param messageType Which message will be subscribed to and routed to the handler * @param messageHandler A callback that will be invoked when the message is received * @param customResolver Subscribe to a topic that's created and maintained outside of the application */ withHandler(...classHandler: ClassConstructor[]): this; withHandler(...functionHandler: { messageType: ClassConstructor; messageHandler: HandlerDefinition; }[]): this; /** * Registers a custom handler that receives messages from external systems, or messages that don't implement the * Message interface from @node-ts/bus-messages * @param messageHandler A handler that receives the custom message * @param customResolver A discriminator that determines if an incoming message should be mapped to this handler. */ withCustomHandler(messageHandler: HandlerDefinition, customResolver: CustomResolver): this; /** * Register a workflow definition so that all of the messages it depends on will be subscribed to * and forwarded to the handlers inside the workflow */ withWorkflow(...workflow: ClassConstructor>[]): this; /** * Configures Bus to use a different transport than the default MemoryQueue */ withTransport(transportConfiguration: Transport): this; /** * Configures Bus to use a different logging provider than the default console logger */ withLogger(loggerFactory: LoggerFactory): this; /** * Configures Bus to use a different serialization provider. The provider is responsible for * transforming messages to/from a serialized representation, as well as ensuring all object * properties are a strong type */ withSerializer(serializer: Serializer): this; /** * Configures Bus to use a different persistence provider than the default InMemoryPersistence provider. * This is used to persist workflow data and is unused if not using workflows. */ withPersistence(persistence: Persistence): this; /** * Sets the message handling concurrency beyond the default value of 1, which will increase the number of messages * handled in parallel. */ withConcurrency(concurrency: number): this; /** * Use a local dependency injection/IoC container to resolve handlers * and workflows. * @param container An adapter to an existing DI container to fetch class instances from */ withContainer(container: ContainerAdapter): this; /** * Register optional middlewares that will run for each message that is polled from the transport * Note these middlewares only run when polling successfully pulls a message off the Transports queue * After all the user defined middlewares have registered. */ withMessageReadMiddleware(messageReadMiddleware: Middleware>): this; /** * Configure @node-ts/bus to use a different retry strategy that determines delays between * retrying failed messages. * @default DefaultRetryStrategy */ withRetryStrategy(retryStrategy: RetryStrategy): this; /** * Register additional signals that will cause the bus to gracefully shutdown * @default [SIGINT, SIGTERM] */ withAdditionalInterruptSignal(...signals: NodeJS.Signals[]): this; /** * Register a receiving mechanism that will be used to receive messages and deliver * them to the dispatcher. * * Usually the bus will connect to a transport and receive messages directly. However * a different receiver plugin can be used that will become responsible for this instead. * * Once the bus is configured, messages can be received by passing the received message into bus.receive(). * * @param receiver The receiver mechanism to use, or `undefined` to use the default behaviour */ withReceiver(receiver: Receiver | undefined): this; }