sqs-consumer
Version:
Build SQS-based Node applications without the boilerplate
141 lines (140 loc) • 4.67 kB
TypeScript
import type { ConsumerOptions, StopOptions, UpdatableOptions } from "./types.js";
import { TypedEventEmitter } from "./emitter.js";
/**
* [Usage](https://bbc.github.io/sqs-consumer/index.html#usage)
*/
export declare class Consumer extends TypedEventEmitter {
private pollingTimeoutId;
private stopped;
protected queueUrl: string;
private isFifoQueue;
private suppressFifoWarning;
private handleMessage;
private handleMessageBatch;
private preReceiveMessageCallback?;
private postReceiveMessageCallback?;
private sqs;
private handleMessageTimeout;
private attributeNames;
private messageAttributeNames;
private messageSystemAttributeNames;
private shouldDeleteMessages;
private alwaysAcknowledge;
private batchSize;
private visibilityTimeout;
private terminateVisibilityTimeout;
private waitTimeSeconds;
private authenticationErrorTimeout;
private pollingWaitTimeMs;
private pollingCompleteWaitTimeMs;
private heartbeatInterval;
private isPolling;
private stopRequestedAtTimestamp;
abortController: AbortController;
private extendedAWSErrors;
constructor(options: ConsumerOptions);
/**
* Creates a new SQS consumer.
*/
static create(options: ConsumerOptions): Consumer;
/**
* Start polling the queue for messages.
*/
start(): void;
/**
* A reusable options object for sqs.send that's used to avoid duplication.
*/
private get sqsSendOptions();
/**
* Stop polling the queue for messages (pre existing requests will still be made until concluded).
*/
stop(options?: StopOptions): void;
/**
* Wait for final poll and in flight messages to complete.
* @private
*/
private waitForPollingToComplete;
/**
* Returns the current status of the consumer.
* This includes whether it is running or currently polling.
*/
get status(): {
isRunning: boolean;
isPolling: boolean;
};
/**
* Validates and then updates the provided option to the provided value.
* @param option The option to validate and then update
* @param value The value to set the provided option to
*/
updateOption(option: UpdatableOptions, value: ConsumerOptions[UpdatableOptions]): void;
/**
* Emit one of the consumer's error events depending on the error received.
* @param err The error object to forward on
* @param message The message that the error occurred on
*/
private emitError;
/**
* Poll for new messages from SQS
*/
private poll;
/**
* Send a request to SQS to retrieve messages
* @param params The required params to receive messages from SQS
*/
private receiveMessage;
/**
* Handles the response from AWS SQS, determining if we should proceed to
* the message handler.
* @param response The output from AWS SQS
*/
private handleSqsResponse;
/**
* Process a message that has been received from SQS. This will execute the message
* handler and delete the message once complete.
* @param message The message that was delivered from SQS
*/
private processMessage;
/**
* Process a batch of messages from the SQS queue.
* @param messages The messages that were delivered from SQS
*/
private processMessageBatch;
/**
* Trigger a function on a set interval
* @param heartbeatFn The function that should be triggered
*/
private startHeartbeat;
/**
* Change the visibility timeout on a message
* @param message The message to change the value of
* @param timeout The new timeout that should be set
*/
private changeVisibilityTimeout;
/**
* Change the visibility timeout on a batch of messages
* @param messages The messages to change the value of
* @param timeout The new timeout that should be set
*/
private changeVisibilityTimeoutBatch;
/**
* Trigger the applications handleMessage function
* @param message The message that was received from SQS
*/
private executeHandler;
/**
* Execute the application's message batch handler
* @param messages The messages that should be forwarded from the SQS queue
*/
private executeBatchHandler;
/**
* Delete a single message from SQS
* @param message The message to delete from the SQS queue
*/
private deleteMessage;
/**
* Delete a batch of messages from the SQS queue.
* @param messages The messages that should be deleted from SQS
*/
private deleteMessageBatch;
}