Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use PubNub publish callback to find out which message to re-publish in case of an error

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.

like image 608
user1935449 Avatar asked Jul 04 '13 19:07

user1935449


1 Answers

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.

like image 57
Serhii Mamontov Avatar answered Oct 15 '22 11:10

Serhii Mamontov