簡體   English   中英

Kafka消費者onmessage-api調用對每條消息進行多次調用?

[英]Kafka consumer onmessage - api call makes multiple calls on each message?

考慮以下:

      const cached = this.cache.get(somekey);
      // console.log(!cached);
      if (!cached) {
        console.log(cached);
        return requestRetry({
          url: fullUri,
          json: true,
          maxAttempts: 3,   // (default) try 5 times
          retryDelay: 2000,  // (default) wait for 5s before trying again
          retryStrategy: requestRetry.RetryStrategies.HTTPOrNetworkError,
          fullResponse: true
        }).then((result) => {
           //do something with the result and return result
            this.cache.set(somekey, data);
            return result;
        }
     } else {
         //return cached result
     }

在kafka流使用者的onmessage方法中調用了以上代碼。 我面臨的問題是,如果結果不是並且未定義緩存,它將為傳入的每個kafka消息多次調用url。

如何做到這樣,只對傳入的第一條消息進行一次調用,它設置了緩存,然后在下一條消息中,它進入else部分並從緩存中檢索數據。

只需將requestRetry結果承諾放在緩存中即可。
解決后,緩存將更新為准確的結果。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM