Firebase Admin Node.JS SDK支持指数退避吗?

huangapple go评论65阅读模式
英文:

Does the Firebase Admin Node.JS SDK support exponential back off?

问题

我正在寻求建立一个简单的Node.JS服务器,该服务器将监听我正在构建的应用程序的请求,并从中构建一个“发送消息”请求到Firebase Cloud Messaging(如此处所述:https://firebase.google.com/docs/cloud-messaging/send-message),以便向相关的客户端应用程序发送推送通知。为了实现这一点,需要使用Firebase Admin SDK。

在Google的Firebase Cloud Messaging文档的“服务器环境”(https://firebase.google.com/docs/cloud-messaging/server)部分中,提到运行Firebase Admin SDK需要一个能够处理请求并使用指数退避进行重新发送的服务器环境。在这种情况下,我猜使用指数退避意味着必须使用指数退避算法重试“发送消息”请求到Firebase Cloud Messaging。

然而,文档中没有说明Node.JS Firebase Admin SDK是否已经支持这种指数退避功能,还是在使用Admin SDK的某些方面时我需要自行实现它。

根据早期的Stack Overflow帖子(https://stackoverflow.com/q/57962587/5646862),Java SDK确实支持指数退避,但我不确定Node.JS是否也支持。

英文:

I'm looking to set up a simple Node.JS server which will listen for requests from an app I'm building and from it build a "send message" request to Firebase Cloud Messaging (as stated here: https://firebase.google.com/docs/cloud-messaging/send-message) so that a push notification is sent out to relevant client-side apps. In order to do this one needs to make use of the Firebase Admin SDK.

On Google's Firebase Cloud Messaging documentation under "Server Environments" (https://firebase.google.com/docs/cloud-messaging/server), it's said that running the Firebase Admin SDK requires a server environment which is able to handle requests and resend them using exponential back off. In this case I guess using exponential back off means that the "send message" request to Firebase Cloud Messaging must be retried using an exponential back off algorithm.

It's not said in the documentation however if the Node.JS Firebase Admin SDK already supports such exponential back off functionality or if I have to implement it on my own when using aspects of the Admin SDK.

According to an earlier Stack overflow post (https://stackoverflow.com/q/57962587/5646862) the Java SDK does support exponential back off, but I'm not sure whether the Node.JS one does.

答案1

得分: 3

firebaser here

Firebase Admin Node.js SDK中的默认重试配置会在连接重置、超时和HTTP 503错误时自动重试最多4次。如果错误响应包含Retry-After头部,默认重试配置也会尊重它

在默认配置中,backOffFactor设置为0.5。这导致指数重试模式为0秒、1秒、2秒和4秒。

/**
 * HTTP请求的默认重试配置。在连接重置、超时错误以及HTTP 503错误时最多重试4次。
 * 作为函数暴露,以确保每个HttpClient都获得自己的RetryConfig实例。
 */
export function defaultRetryConfig(): RetryConfig {
  return {
    maxRetries: 4,
    statusCodes: [503],
    ioErrorCodes: ['ECONNRESET', 'ETIMEDOUT'],
    backOffFactor: 0.5,
    maxDelayInMillis: 60 * 1000,
  };
}

文档中的代码参考

英文:

firebaser here

The default retry configuration in the Firebase Admin Node.js SDK automatically retries up to 4 times on connection reset, timeout, and HTTP 503 errors. If the error response contains Retry-After header, the default retry config respects that, too.

In the default config, the backOffFactor is set to 0.5. This results in the exponential retry pattern of 0s, 1s, 2s, and 4s.

/**
 * Default retry configuration for HTTP requests. Retries up to 4 times on connection reset and timeout errors
 * as well as HTTP 503 errors. Exposed as a function to ensure that every HttpClient gets its own RetryConfig
 * instance.
 */
export function defaultRetryConfig(): RetryConfig {
  return {
    maxRetries: 4,
    statusCodes: [503],
    ioErrorCodes: ['ECONNRESET', 'ETIMEDOUT'],
    backOffFactor: 0.5,
    maxDelayInMillis: 60 * 1000,
  };
}

Reference to code in documentation

huangapple
  • 本文由 发表于 2023年1月9日 08:14:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/75052209.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定