UNPKG

@vercel/sqs-consumer

Version:

Build SQS-based Node applications without the boilerplate

90 lines (89 loc) 3.15 kB
/// <reference types="node" /> import * as SQS from 'aws-sdk/clients/sqs'; import { EventEmitter } from 'events'; export declare type SQSMessage = SQS.Types.Message; export interface ConsumerOptions { queueUrl?: string; attributeNames?: string[]; messageAttributeNames?: string[]; stopped?: boolean; batchSize?: number; visibilityTimeout?: number; waitTimeSeconds?: number; authenticationErrorTimeout?: number; pollingWaitTimeMs?: number; terminateVisibilityTimeout?: boolean | ((message: SQSMessage) => number); heartbeatInterval?: number; sqs?: SQS; region?: string; handleMessageTimeout?: number; handleMessage?(message: SQSMessage): Promise<void>; handleMessageBatch?(messages: SQSMessage[]): Promise<void>; /** * An `async` function (or function that returns a `Promise`) to be called right * before the SQS Client sends a receive message command. * * This function is usefull if SQS Client module exports have been modified, for * example to add middlewares. */ preReceiveMessageCallback?(): Promise<void>; /** * An `async` function (or function that returns a `Promise`) to be called right * after the SQS Client sends a receive message command. * * This function is usefull if SQS Client module exports have been modified, for * example to add middlewares. */ postReceiveMessageCallback?(): Promise<void>; } interface Events { 'response_processed': []; 'empty': []; 'message_received': [SQSMessage]; 'message_processed': [SQSMessage]; 'error': [Error, void | SQSMessage | SQSMessage[]]; 'timeout_error': [Error, SQSMessage]; 'processing_error': [Error, SQSMessage]; 'stopped': []; } export declare class Consumer extends EventEmitter { private queueUrl; private handleMessage; private handleMessageBatch; private handleMessageTimeout; private attributeNames; private messageAttributeNames; private stopped; private batchSize; private visibilityTimeout; private waitTimeSeconds; private authenticationErrorTimeout; private pollingWaitTimeMs; private terminateVisibilityTimeout; private heartbeatInterval; private sqs; private preReceiveMessageCallback?; private postReceiveMessageCallback?; constructor(options: ConsumerOptions); emit<T extends keyof Events>(event: T, ...args: Events[T]): boolean; on<T extends keyof Events>(event: T, listener: (...args: Events[T]) => void): this; once<T extends keyof Events>(event: T, listener: (...args: Events[T]) => void): this; get isRunning(): boolean; static create(options: ConsumerOptions): Consumer; start(): void; stop(): void; private handleSqsResponse; private processMessage; private receiveMessage; private deleteMessage; private executeHandler; private changeVisibilityTimeout; private emitError; private poll; private processMessageBatch; private deleteMessageBatch; private executeBatchHandler; private changeVisibilityTimeoutBatch; private startHeartbeat; } export {};