The options for the consumer.

interface ConsumerOptions {
    accountId: string;
    queueId: string;
    alwaysAcknowledge?: boolean;
    batchSize?: number;
    handleMessageTimeout?: number;
    pollingWaitTimeMs?: number;
    retryMessageDelay?: number;
    retryMessagesOnError?: boolean;
    shouldDeleteMessages?: boolean;
    visibilityTimeoutMs?: number;
    handleMessage?(message: Message): Promise<void | Message>;
    handleMessageBatch?(messages: Message[]): Promise<void | Message[]>;
    postReceiveMessageCallback?(): Promise<void>;
    preReceiveMessageCallback?(): Promise<void>;
}

Properties

accountId: string

You Cloudflare account id

queueId: string

The ID of the queue you want to receive messages from.

alwaysAcknowledge?: boolean

By default, the consumer will treat an empty object or array from either of the handlers as a acknowledgement of no messages and will not delete those messages as a result. Set this to true to always acknowledge all messages no matter the returned value.

false

batchSize?: number

The number of messages to request from Cloudflare when polling (default 10).

10

handleMessageTimeout?: number

Time in ms to wait for handleMessage to process a message before timing out.

Emits timeout_error on timeout. By default, if handleMessage times out, the unprocessed message returns to the end of the queue.

pollingWaitTimeMs?: number

The duration (in milliseconds) to wait before repolling the queue. (Note: As Cloudflare uses short polling, you probably shouldn't set this too low)

1000

retryMessageDelay?: number

The amount of time to delay a message for before retrying (in seconds)

10

retryMessagesOnError?: boolean

If the Consumer should trigger the message(s) to be retired on

false

shouldDeleteMessages?: boolean

If the consumer should delete messages after they have been processed.

true

visibilityTimeoutMs?: number

The duration (in milliseconds) that the received messages are hidden from subsequent retrieve requests after being retrieved by a ReceiveMessage request.

1000

Methods

  • An async function (or function that returns a Promise) to be called whenever a message is received.

    In the case that you need to acknowledge the message, return an object containing the MessageId that you'd like to acknowledge.

    Parameters

    Returns Promise<void | Message>

  • An async function (or function that returns a Promise) to be called whenever a batch of messages is received. Similar to handleMessage but will receive the list of messages, not each message individually, this is preferred to reduce API rate limits.

    If both are set, handleMessageBatch overrides handleMessage.

    In the case that you need to ack only some of the messages, return an array with the successful messages only.

    Parameters

    Returns Promise<void | Message[]>

  • An async function (or function that returns a Promise) to be called right after the consumer sends a receive message command.

    Returns Promise<void>

  • An async function (or function that returns a Promise) to be called right before the consumer sends a receive message command.

    Returns Promise<void>