克服FCM“MessageTooBig”限制的一些常见行业惯例是什么

时间:2018-03-12 13:30:42

标签: android firebase firebase-cloud-messaging

我知道,如果我通过FCM发送大量数据

headers = {'content-type': 'application/json', 'Authorization': 'key={}'.format(constants.FCM_AUTHORIZATION_KEY)}
r = requests.post('https://fcm.googleapis.com/fcm/send', headers=headers,, json=request_data)

我会得到以下MessageTooBig回复

{"multicast_id":8254676006929147000,"failure":1,"canonical_ids":0,"results":[{"error":"MessageTooBig"}],"success":0}

我注意到是由https://developers.google.com/cloud-messaging/concept-options

中描述的数据有效负载限制引起的
  

对于下游消息传递,GCM提供两种类型的有效负载:   通知和数据。通知是更轻量级的选择,   具有2KB限制和一组预定义的用户可见键。数据   有效负载允许开发人员发送最多4KB的自定义键/值对。   通知消息可以包含可选的数据有效负载   用户点击通知时发送。

我想知道,克服这种限制有哪些常见的行业惯例。我能想到的解决方法是

  1. 将大数据存储在服务器端数据库中。
  2. 使用FCM仅将服务器端数据库中的大数据的引用ID发送给客户端。
  3. 客户端将通过HTTP API调用使用收到的引用ID与服务器通信来检索大数据。
  4. 我想知道,克服FCM MessageTooBig限制是否是常见的行业惯例?我们可以尝试其他更好的替代方式吗?

    FCM上的大数据示例

    {
      "to": "cHpY6qOkvMM:APA91bHemBImwsqSEo_q_ZO4rxkVwoQ3Jba9xIXKDz7QW2EcDkFkeBT7dF3XtPoSWUsHMybggWRspObQcSQ692j56wYJ1nNY-g5MxW8z4EY91-11log-GBI0RN566Lbt8HlNnxB_MtsV",
      "data": {
        "news_alerts": [
          {
            "code": "BABA",
            "description": "Tired of all the crypto-craziness? Consider these three stocks instead.",
            "sentiment": "negative",
            "title": "Forget Bitcoin: You're Better Off Buying These 3 Stocks",
            "score": "-0.512554",
            "link": "https:\/\/finance.yahoo.com\/news\/forget-bitcoin-apos-better-off-002900487.html?.tsrc=rss",
            "time": 1520641740000
          },
          {
            "code": "BABA",
            "description": "Alibaba, Tencent, JD.com, YY and 58.com, highly rated Chinese internet companies, now have proper bases and buy points. Let's look at the stock charts.",
            "sentiment": "positive",
            "title": "Alibaba, Tencent, JD.com Lead 5 Top Chinese Internets That Just Carved New Buy Points",
            "score": "0.587976",
            "link": "http:\/\/finance.yahoo.com\/r\/bb08a470-7ad4-3339-b5b3-64db04c97fe9\/alibaba-tencent-jd-com-lead-5-top-chinese-internets-that-just-carved-new-buy-points?src=A00220&yptr=yahoo&.tsrc=rss",
            "time": 1520686838000
          },
          {
            "code": "BABA",
            "description": "Cloud computing is transforming the way companies across the world do business. But in China , it is playing an even more transformative role: the country\u2019s biggest consumer-oriented companies are increasingly ...",
            "sentiment": "positive",
            "title": "[$$] Cloud pivots Alibaba, Tencent to business market",
            "score": "0.466677",
            "link": "http:\/\/finance.yahoo.com\/r\/30f3ab86-5c1b-3480-bdde-1e85d23ee890\/d5fb8d22-1228-11e8-940e-08320fc2a277,s01=1.html?ftcamp=traffic\/partner\/feed_headline\/us_yahoo\/auddev&yptr=yahoo&.tsrc=rss",
            "time": 1520740918000
          },
          {
            "code": "BP",
            "description": "BP Stock Has Slumped 8% in 1Q18: What's to Blame?",
            "sentiment": "negative",
            "title": "Why Short Interest in BP Rose",
            "score": "-0.897288",
            "link": "http:\/\/finance.yahoo.com\/r\/8871cdd1-bd33-3313-9216-ca964b34a7b5\/why-short-interest-in-bp-rose?utm_source=yahoo&utm_medium=feed&yptr=yahoo&.tsrc=rss",
            "time": 1520523091000
          },
          {
            "code": "BP",
            "description": "A Look at the Energy Sector's Top Movers This Week",
            "sentiment": "positive",
            "title": "Which Integrated Energy Stocks Are Gaining This Week?",
            "score": "0.557677",
            "link": "http:\/\/finance.yahoo.com\/r\/69b7da55-f061-3c88-b11b-a5e1b587bb8d\/which-integrated-energy-stocks-are-gaining-this-week-2?utm_source=yahoo&utm_medium=feed&yptr=yahoo&.tsrc=rss",
            "time": 1520537652000
          },
          {
            "code": "BP",
            "description": "BP, among other oil majors have reported surprise increases in oil production from aging fields",
            "sentiment": "negative",
            "title": "BP Reports Surprise Production Jump At Mature Fields",
            "score": "-0.432939",
            "link": "https:\/\/finance.yahoo.com\/news\/bp-reports-surprise-production-jump-170000453.html?.tsrc=rss",
            "time": 1520614800000
          },
          {
            "code": "KO",
            "description": "Coca-Cola European Partners, the world\u2019s largest independent Coke bottler, has joined the European war on sugar.  The London-based company, formed in 2016 from the merger of Coca-Cola Enterprises and Coke\u2019s bottling operations in Germany and Spain, has emphasized soft drinks such as Coca Cola Zero Sugar, fruit-flavored ViO Bio, and tea.  It has also introduced mini cans of signature Coca-Cola products.",
            "sentiment": "neutral",
            "title": "[$$] A European Coke Bottler Could Offer Bubbly Returns",
            "score": "0.0",
            "link": "http:\/\/finance.yahoo.com\/r\/a68a7bd5-00e3-3824-a135-b88cba0be129\/a-european-coke-bottler-could-offer-bubbly-returns-1520648871?mod=yahoobarrons&ru=yahoo&yptr=yahoo&.tsrc=rss",
            "time": 1520658060000
          },
          {
            "code": "KO",
            "description": "Which of these consumer-goods leaders is the smarter stock pick?",
            "sentiment": "positive",
            "title": "Better Buy: Altria Group vs. Coca-Cola",
            "score": "0.531775",
            "link": "https:\/\/finance.yahoo.com\/news\/better-buy-altria-group-vs-164800637.html?.tsrc=rss",
            "time": 1520700480000
          },
          {
            "code": "KO",
            "description": "The company will launch its first ever fizzy adult beverage in Japan.",
            "sentiment": "positive",
            "title": "Coca-Cola Dips a Toe Into the Alcohol Market",
            "score": "0.672059",
            "link": "https:\/\/finance.yahoo.com\/news\/coca-cola-dips-toe-alcohol-183000170.html?.tsrc=rss",
            "time": 1520706600000
          },
          {
            "code": "MMM",
            "description": "Analysts\u2019 consensus indicates a target price of $245.90, which implies a return potential of 3.1% over the closing price as of March 7, 2018.  Analysts\u2019 consensus target price for 3M increased from $219.50 to the current price in three months, which indicates bullishness in the stock.  3M reported strong 4Q17 earnings and exceeded analysts\u2019 estimates.",
            "sentiment": "positive",
            "title": "3M: An Update on Analysts\u2019 View",
            "score": "0.731176",
            "link": "http:\/\/finance.yahoo.com\/r\/85233127-bc66-32e3-a5b1-a437689b4aab\/3m-an-update-on-analysts-view?utm_source=yahoo&utm_medium=feed&yptr=yahoo&.tsrc=rss",
            "time": 1520621702000
          },
          {
            "code": "MMM",
            "description": "Warren Buffett once said that \"successful investing takes time.\" Here are three companies to make the wait easier.",
            "sentiment": "neutral",
            "title": "3 Stocks to Buy and Hold for Decades",
            "score": "0.0",
            "link": "https:\/\/finance.yahoo.com\/news\/3-stocks-buy-hold-decades-211100753.html?.tsrc=rss",
            "time": 1520629860000
          },
          {
            "code": "MMM",
            "description": "The market will go down eventually, and these three companies are well prepared for it.",
            "sentiment": "positive",
            "title": "3 Dividend Stocks That Thrive in Both Bull and Bear Markets",
            "score": "0.541903",
            "link": "https:\/\/finance.yahoo.com\/news\/3-dividend-stocks-thrive-both-121500321.html?.tsrc=rss",
            "time": 1520684100000
          }
        ]
      }
    }
    

0 个答案:

没有答案