AWS 简单队列服务 (SQS) 可见性超时 - 设置最大重试次数?
AWS Simple Queue Service (SQS) visibility timeout - set max retries count?
我们有一个使用包含消息的 amazon SQS 的队列。
我们有多个从该队列读取的工作人员,这些工作人员是无状态的,这意味着他们不记得每条消息有多少次重试,除非我们用重试计数更新消息。
目前,如果一个worker无法处理一条消息,消息将在我们设置的X秒后return进入队列,因为我们不删除它,我们设置VisisiblityTimeout
参数这意味着如果消息未被工作人员删除,则该消息将 return 在 X 设置秒后进入队列。
SQS 队列或消息设置中是否有创建重试计数的选项,例如,如果消息return进入队列的次数超过或等于 3 次,它将被删除队列?
public async pollMessage(queueName: string): Promise<QueueMessagePollResponse> {
const parameters = {
VisibilityTimeout: this.configService.queueVisibilityTimeoutSec,
QueueUrl: this.buildQueueUrl(queueName),
};
return new Promise<QueueMessagePollResponse>((resolve, reject) => {
this.sqs.receiveMessage(parameters, (error, data) => {
if (error) {
this.logger.error(`Failed polling from queue with error: ${error.message}`);
reject(error);
}
if (!data.Messages) {
return resolve(null);
}
resolve({
messageDeletionId: data.Messages[0].ReceiptHandle,
data: data.Messages[0].Body,
});
});
});
}
You can use A DLQ (Dead-Letter Queue). Set the redrive policy of SQS
to no. of tries you want, like
我们有一个使用包含消息的 amazon SQS 的队列。
我们有多个从该队列读取的工作人员,这些工作人员是无状态的,这意味着他们不记得每条消息有多少次重试,除非我们用重试计数更新消息。
目前,如果一个worker无法处理一条消息,消息将在我们设置的X秒后return进入队列,因为我们不删除它,我们设置VisisiblityTimeout
参数这意味着如果消息未被工作人员删除,则该消息将 return 在 X 设置秒后进入队列。
SQS 队列或消息设置中是否有创建重试计数的选项,例如,如果消息return进入队列的次数超过或等于 3 次,它将被删除队列?
public async pollMessage(queueName: string): Promise<QueueMessagePollResponse> {
const parameters = {
VisibilityTimeout: this.configService.queueVisibilityTimeoutSec,
QueueUrl: this.buildQueueUrl(queueName),
};
return new Promise<QueueMessagePollResponse>((resolve, reject) => {
this.sqs.receiveMessage(parameters, (error, data) => {
if (error) {
this.logger.error(`Failed polling from queue with error: ${error.message}`);
reject(error);
}
if (!data.Messages) {
return resolve(null);
}
resolve({
messageDeletionId: data.Messages[0].ReceiptHandle,
data: data.Messages[0].Body,
});
});
});
}
You can use A DLQ (Dead-Letter Queue). Set the redrive policy of SQS to no. of tries you want, like