Firebase云消息传递 - 两次收到上游消息

时间:2016-11-18 22:37:16

标签: firebase google-cloud-messaging xmpp firebase-cloud-messaging

我们的应用程序通过FCM Upstream向我们的服务器发送一些消息。我们有两台服务器作为客户端连接。

最近,我们注意到很多邮件(> 50%)都会收到两次。通常在不同的服务器上,但有时在同一台服务器上。

不确定从哪里开始。

接收两条消息的日志如下:

Fri, 18 Nov 2016 21:39:17 GMT xmpp:connection receive: 
  <message to="xxxx@gcm.googleapis.com" from="devices@gcm.googleapis.com" type="normal">
    <gcm xmlns="google:mobile:data">
      {"data":
        {"userInfo":"{}",
         "path":"v1\/patient\/checkIn\/usage",
         "method":"POST",
         "body":"{}",
         "dest":"https:\/\/api.stg.triggrhealth.com\/api\/v1"
        },
       "time_to_live":43200,
       "from":"f5LDS516Eu8:APA91bGEkzwXlmXRpfui6T01QM6V3pOY8p3nSkZMUfYkDYjRxu6Xa64Bh0Boc3so8X8royBA1v4PaGjPcUW6JI0pcZL7UK9P4LEqgVThfNQKGW8DZMhTEM-JDodDvUPjGpbPA-zdYYQb",
       "message_id":"1479505157658",
       "category":"com.triggrhealth.prototype.stage"
      }
    </gcm>
  </message>
Fri, 18 Nov 2016 21:39:17 GMT xmpp:connection send: 
  <gcm xmlns="google:mobile:data">
    {"to":"f5LDS516Eu8:APA91bGEkzwXlmXRpfui6T01QM6V3pOY8p3nSkZMUfYkDYjRxu6Xa64Bh0Boc3so8X8royBA1v4PaGjPcUW6JI0pcZL7UK9P4LEqgVThfNQKGW8DZMhTEM-JDodDvUPjGpbPA-zdYYQb",
     "message_id":"1479505157658",
     "message_type":"ack"
    }
  </gcm>
Fri, 18 Nov 2016 21:42:28 GMT xmpp:connection receive: 
  <message to="xxxx@gcm.googleapis.com" from="devices@gcm.googleapis.com" type="normal">
    <gcm xmlns="google:mobile:data">
      {"data":
        {"userInfo":"{}",
         "path":"v1\/patient\/checkIn\/usage",
         "method":"POST",
         "body":"{}",
         "dest":"https:\/\/api.stg.triggrhealth.com\/api\/v1"
        },
       "time_to_live":43200,
       "from":"f5LDS516Eu8:APA91bGEkzwXlmXRpfui6T01QM6V3pOY8p3nSkZMUfYkDYjRxu6Xa64Bh0Boc3so8X8royBA1v4PaGjPcUW6JI0pcZL7UK9P4LEqgVThfNQKGW8DZMhTEM-JDodDvUPjGpbPA-zdYYQb",
       "message_id":"1479505157658",
       "category":"com.triggrhealth.prototype.stage"
      }
    </gcm>
  </message>
Fri, 18 Nov 2016 21:42:28 GMT xmpp:connection send: 
  <gcm xmlns="google:mobile:data">
    {"to":"f5LDS516Eu8:APA91bGEkzwXlmXRpfui6T01QM6V3pOY8p3nSkZMUfYkDYjRxu6Xa64Bh0Boc3so8X8royBA1v4PaGjPcUW6JI0pcZL7UK9P4LEqgVThfNQKGW8DZMhTEM-JDodDvUPjGpbPA-zdYYQb",
     "message_id":"1479505157658",
     "message_type":"ack"
    }
  </gcm>

1 个答案:

答案 0 :(得分:-1)

您可能需要查看并尝试sending an ACK message。如上所述,

  

响应上游消息,应用服务器必须使用相同的连接发送包含唯一消息ID的ACK消息。 如果GCM未收到确认,则可能会重试将消息发送至应用服务器

以下是示例代码:

<message id="">
  <gcm xmlns="google:mobile:data">
  {
      "to":"REGID",
      "message_id":"m-123"
      "message_type":"ack"
  }
  </gcm>
</message>

最后,另请参阅XMPP Connection Server Reference以获取有关上游消息语法的更多信息。