The publish callback in PubNub API returns with a message like below -
[1,"Sent","13729639808030640"]
But this does not give any indication as to for which message this callback is for. In case of publish error, the first value in the return array will be 0. But how do you find out which message to re-publish?
The publisher can be publishing messages at a high rate and not waiting to receive the callback before publishing another message. So when the callback is invoked the publisher might have already published 10 more messages.
PubNub REST API provide JSONP format as well. You can create map of "callback function" identifiers to actual messages and when processing completed, you can obtain reference on original message using "callback function" identifier from response.
For example:
https://pubsub.pubnub.com/publish/demo/demo/0/iosdev/m_2c453/%22Hello%20world2%22
As you can see, there is m_2c453
in URI, it will be used by server in response:
m_2c453([1,"Sent","14034711347326358"])
And here we know, that m_2c453
has been used to send "Hello world"
message.
But, I think platform dependent PubNub SDK should handle all this for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With