为什么不重新发送邮件? [英] Why the message doesn't to be redelivered?

查看:100
本文介绍了为什么不重新发送邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

确认截止时间为10秒.当我使用异步拉方式处理消息时,我不调用message.ack()message.nack(),而是等待消息确认截止日期,并期望Pub/Sub重新传递此消息.

The Acknowledgment Deadline is 10 seconds. When I use asynchronous-pull way to process the message, I don't call message.ack() and message.nack(), wait for the message ack deadline and expect Pub/Sub redeliver this message.

等待10秒钟后,订阅者不再收到该消息.这是我的代码:

After waiting over 10 seconds, the subscriber doesn't receive the message again. Here is my code:

subscriber:

import { pubsubClient, IMessage, parseMessageData } from '../../googlePubsub';
import { logger } from '../../utils';

const topicName = 'asynchronous-pull-test';
const subName = 'asynchronous-pull-test';
const subscription = pubsubClient.topic(topicName).subscription(subName);
const onMessage = (message: IMessage) => {
  const { data, ...rest } = message;
  const jsonData = parseMessageData(data);
  logger.debug('received message', { arguments: { ...rest, data: jsonData } });

  const publishTime = new Date(message.publishTime).getTime();
  const republishTimestamp = Date.now() - 5 * 1000;

  if (publishTime < republishTimestamp) {
    logger.info('message acked');
    message.ack();
  } else {
    logger.info('push message back to MQ');
  }
};
logger.info('subscribe the MQ');
subscription.on('message', onMessage).on('error', (err: Error) => logger.error(err));

publisher:

const topicName = 'asynchronous-pull-test';

async function main() {
  const messagePayload = { email: faker.internet.email(), campaignId: '1' };
  await pub(topicName, messagePayload);
}

main();

我正在使用"@google-cloud/pubsub": "^0.19.0",

我希望订户将在10秒钟后的确认截止日期再次收到该消息.这意味着我的订户每10秒钟接收和处理一次消息.我错了吗?

I expect the subscriber will receive the message again at the ack deadline 10 seconds later. Which means my subscriber receives and processes the message every 10 seconds. Am I wrong?

推荐答案

Google Cloud Pub/Sub客户端库自动调用 maxExtension 属性:

The Google Cloud Pub/Sub client libraries automatically call modifyAckDeadline for messages that are neither acked or nacked for a configurable period of time. In node.js, this is configured via the maxExtension property:

const options = {
  flowControl: {
    maxExtension: 60, // Specified in seconds
  },
};

const subscription = pubsubClient.topic(topicName).subscription(subName, options);

通常,不确认/不确认消息不是延迟重新发送邮件的一种好习惯.这将导致该消息仍会计入流控制最大未完成邮件数,这意味着在原始接收的邮件被确认或拒绝之前,它可能会阻止将来的邮件传递.目前,Cloud Pub/Sub尚无延迟消息重新交付的方法,但正在考虑中.

In general, it is not a good practice to not ack/nack a message as a means to delay its redelivery. This will result in the message still counting against the flow control max outstanding messages, meaning it could prevent the delivery of future messages until the originally received messages are acked or nacked. At this time, Cloud Pub/Sub does not have a means by which to delay message redelivery, but it is something under consideration.

这篇关于为什么不重新发送邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆