Interface Publisher

Connection#createPublisher()

The underlying Channel is lazily created the first time a message is published.

const pub = rabbit.createPublisher({
confirm: true,
exchanges: [{exchange: 'user', type: 'topic'}]
})

await pub.send({exchange: 'user', routingKey: 'user.create'}, userInfo)

await pub.close()
interface Publisher {
    close(): Promise<void>;
    on(name: "basic.return", cb: ((msg: ReturnedMessage) => void)): this;
    on(name: "retry", cb: ((err: any, envelope: Envelope, body: any) => void)): this;
    send(envelope: Envelope, body: any): Promise<void>;
    send(queue: string, body: any): Promise<void>;
}

Hierarchy

  • EventEmitter
    • Publisher

Methods

Methods

  • Close the underlying channel

    Returns Promise<void>

  • An undeliverable message was published with the "immediate" flag set, or an unroutable message published with the "mandatory" flag set. The reply code and text provide information about the reason that the message was undeliverable.

    Parameters

    Returns this

  • See maxAttempts. Emitted each time a failed publish will be retried.

    Parameters

    • name: "retry"
    • cb: ((err: any, envelope: Envelope, body: any) => void)
        • (err, envelope, body): void
        • Parameters

          Returns void

    Returns this

  • This method publishes a message to a specific exchange. The message will be routed to queues as defined by the exchange configuration.

    If the body is a string then it will be serialized with contentType='text/plain'. If body is an object then it will be serialized with contentType='application/json'. Buffer objects are unchanged.

    If publisher-confirms are enabled, then this will resolve when the acknowledgement is received. Otherwise this will resolve after writing to the TCP socket, which is usually immediate. Note that if you keep publishing while the connection is blocked (see :BLOCKED | Connection#on('connection.blocked')) then the TCP socket buffer will eventually fill and this method will no longer resolve immediately.

    Parameters

    Returns Promise<void>

  • Send directly to a queue. Same as send({routingKey: queue}, body)

    Parameters

    • queue: string
    • body: any

    Returns Promise<void>