API reference / @node-ts/bus-sqs-lambda / BusSqsLambdaReceiver
Class: BusSqsLambdaReceiver
Defined in: bus-sqs-lambda-receiver.ts:26
Receives messages from an SQS event that's triggered a lambda function, and converts them into a TransportMessage ready to be dispatched. A message that fails, or that a handler returns with bus.returnMessage(), is retried by Lambda: either on its own (reportBatchItemFailures) or with the whole batch.
Example
const bus = Bus.configure()
.withTransport(sqsTransport)
.withReceiver(new BusSqsLambdaReceiver({ reportBatchItemFailures: true }))
.build()
export const handler: SQSHandler = event => bus.receive<SQSBatchResponse>(event)Implements
Receiver<SQSEvent,TransportMessage<SqsLambdaRecord>,SQSBatchResponse|void>
Constructors
Constructor
new BusSqsLambdaReceiver(configuration?): BusSqsLambdaReceiver;Defined in: bus-sqs-lambda-receiver.ts:34
Parameters
| Parameter | Type | Description |
|---|---|---|
configuration | BusSqsLambdaReceiverConfiguration | Options for how the outcome of a batch is reported back to Lambda |
Returns
BusSqsLambdaReceiver
Methods
receive()
receive(receivedMessage, messageSerializer): Promise<TransportMessage<SqsLambdaRecord>[]>;Defined in: bus-sqs-lambda-receiver.ts:38
Invoked when a message is received by the application and needs to be converted into a transport message so that it can be passed to the dispatcher and send to handlers.
Parameters
| Parameter | Type | Description |
|---|---|---|
receivedMessage | SQSEvent | The message received by the app |
messageSerializer | MessageSerializer | The configured serializer, which can be used to deserialize the incoming message |
Returns
Promise<TransportMessage<SqsLambdaRecord>[]>
Implementation of
toReceiveResult()
toReceiveResult(failures): void | SQSBatchResponse;Defined in: bus-sqs-lambda-receiver.ts:63
Reports the records that failed back to Lambda once the whole batch has been handled.
Parameters
| Parameter | Type | Description |
|---|---|---|
failures | ReceivedMessageFailure<TransportMessage<SqsLambdaRecord>>[] | The records that failed to be handled |
Returns
void | SQSBatchResponse
An SQSBatchResponse of the failed records when reportBatchItemFailures is enabled
Throws
the first failure's error when reportBatchItemFailures is disabled, so Lambda retries the whole batch