Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Sender

Package version

The Sender class can be used to send messages, schedule messages to be sent at a later time and cancel such scheduled messages. Use the createSender function on the QueueClient or TopicClient to instantiate a Sender. The Sender class is an abstraction over the underlying AMQP sender link.

Hierarchy

  • Sender

Index

Accessors

isClosed

  • get isClosed(): boolean

Methods

cancelScheduledMessage

  • cancelScheduledMessage(sequenceNumber: Long): Promise<void>
  • Cancels a message that was scheduled to appear on a ServiceBus Queue/Subscription.

    throws

    Error if the underlying connection, client or sender is closed.

    throws

    MessagingError if the service returns an error while canceling a scheduled message.

    Parameters

    • sequenceNumber: Long

      The sequence number of the message to be cancelled.

    Returns Promise<void>

    Promise

cancelScheduledMessages

  • cancelScheduledMessages(sequenceNumbers: Long[]): Promise<void>
  • Cancels multiple messages that were scheduled to appear on a ServiceBus Queue/Subscription.

    throws

    Error if the underlying connection, client or sender is closed.

    throws

    MessagingError if the service returns an error while canceling scheduled messages.

    Parameters

    • sequenceNumbers: Long[]

      An Array of sequence numbers of the messages to be cancelled.

    Returns Promise<void>

    Promise

close

  • close(): Promise<void>

open

  • open(): Promise<void>
  • Opens the AMQP link to Azure Service Bus from the sender.

    It is not necessary to call this method in order to use the sender. It is recommended to call this before your first send() or sendBatch() call if you want to front load the work of setting up the AMQP link to the service.

    Returns Promise<void>

scheduleMessage

  • Schedules given message to appear on Service Bus Queue/Subscription at a later time.

    Please note that you need to explicitly encode the message body if you intend to receive the message using a tool or library other than this library. For example:

    1. Import DefaultDataTransformer and instantiate.
         const dt = new DefaultDataTransformer();
    2. Use the encode method on the transformer to encode the message body before calling the scheduleMessage() method
         message.body = dt.encode(message.body);
    throws

    Error if the underlying connection, client or sender is closed.

    throws

    MessagingError if the service returns an error while scheduling a message.

    Parameters

    • scheduledEnqueueTimeUtc: Date

      The UTC time at which the message should be enqueued.

    • message: SendableMessageInfo

      The message that needs to be scheduled.

    Returns Promise<Long>

    Promise - The sequence number of the message that was scheduled. You will need the sequence number if you intend to cancel the scheduling of the message. Save the Long type as-is in your application without converting to number. Since JavaScript only supports 53 bit numbers, converting the Long to number will cause loss in precision.

scheduleMessages

  • Schedules given messages to appear on Service Bus Queue/Subscription at a later time.

    Please note that you need to explicitly encode the message body if you intend to receive the message using a tool or library other than this library. For example:

    1. Import DefaultDataTransformer and instantiate.
         const dt = new DefaultDataTransformer();
    2. Use the encode method on the transformer to encode the message body before calling the scheduleMessage() method
         message.body = dt.encode(message.body);
    throws

    Error if the underlying connection, client or sender is closed.

    throws

    MessagingError if the service returns an error while scheduling messages.

    Parameters

    • scheduledEnqueueTimeUtc: Date

      The UTC time at which the messages should be enqueued.

    • messages: SendableMessageInfo[]

      Array of Messages that need to be scheduled.

    Returns Promise<Long[]>

    Promise<Long[]> - The sequence numbers of messages that were scheduled. You will need the sequence number if you intend to cancel the scheduling of the messages. Save the Long type as-is in your application without converting to number. Since JavaScript only supports 53 bit numbers, converting the Long to number will cause loss in precision.

send

  • Sends the given message after creating an AMQP Sender link if it doesnt already exists.

    To send a message to a session and/or partition enabled Queue/Topic, set the sessionId and/or partitionKey properties respectively on the message.

    throws

    Error if the underlying connection, client or sender is closed.

    throws

    MessagingError if the service returns an error while sending messages to the service.

    Parameters

    Returns Promise<void>

    Promise

sendBatch

  • Sends the given messages in a single batch i.e. in a single AMQP message after creating an AMQP Sender link if it doesnt already exists.

    • To send messages to a session and/or partition enabled Queue/Topic, set the sessionId and/or partitionKey properties respectively on the messages.
    • When doing so, all messages in the batch should have the same sessionId (if using sessions) and the same partitionKey (if using partitions).
    throws

    Error if the underlying connection, client or sender is closed.

    throws

    MessagingError if the service returns an error while sending messages to the service.

    Parameters

    • messages: SendableMessageInfo[]

      An array of SendableMessageInfo objects to be sent in a Batch message.

    Returns Promise<void>

    Promise

Generated using TypeDoc