Setu-TS
    Preparing search index...

    Interface IMessageBroker

    Message broker for cross-service integration events.

    const broker = ctx.services.get<IMessageBroker>(CAPABILITIES.MESSAGING);
    await broker.publish('user.created', { userId: user.id });

    0.1.0

    interface IMessageBroker {
        connect(): Promise<void>;
        disconnect(): Promise<void>;
        isHealthy?(): Promise<boolean>;
        publish<T>(
            topic: string,
            message: T,
            options?: PublishOptions,
        ): Promise<void>;
        request<TReq, TRes>(
            topic: string,
            message: TReq,
            options?: RequestOptions,
        ): Promise<TRes>;
        respond<TReq, TRes>(
            topic: string,
            handler: RequestHandler<TReq, TRes>,
            options?: SubscribeOptions,
        ): Promise<ISubscription>;
        subscribe<T>(
            topic: string,
            handler: MessageHandler<T>,
            options?: SubscribeOptions,
        ): Promise<ISubscription>;
    }

    Implemented by

    Index
    • Reports whether the broker's backend is reachable right now, for the plugin's health indicator.

      Optional: a broker with no meaningful liveness check omits it, and the indicator then reports only the lifecycle state (isReady).

      This answers a fact (reachability), not a policy: the indicator that consumes it owns the up/down mapping.

      Returns Promise<boolean>

      true when the backend is reachable

      0.1.0

    • Publishes a message to a topic.

      Type Parameters

      • T

        The payload type

      Parameters

      • topic: string

        Destination topic

      • message: T

        The payload (serialized by the broker adapter)

      • Optionaloptions: PublishOptions

        Ordering, de-duplication and header options; an option the broker has no native primitive for is carried as a transport header

      Returns Promise<void>

    • Sends a request to a topic and awaits a single correlated reply, providing brokered request-reply (RPC) over the message broker.

      A responder registered with respond on the same topic returns the reply. The call rejects with a RequestTimeoutError when no reply arrives within options.timeoutMs, and with a RemoteHandlerError when the responder throws.

      Request traffic rides a channel derived from topic, disjoint from plain publish/subscribe on that same topic — a pub/sub consumer never observes an RPC request, and vice versa.

      Type Parameters

      • TReq

        The request payload type

      • TRes

        The reply payload type

      Parameters

      • topic: string

        Destination topic the responder is listening on

      • message: TReq

        The request payload (serialized by the broker adapter)

      • Optionaloptions: RequestOptions

        Reply timeout behavior

      Returns Promise<TRes>

      The reply payload