android - On publish getting multiple same requests pubnubv4 rails -


i have rails app api based using pub-nub v4. same client side(ios/android) using pub-nub.

here steps doing:

1) on create object subscribing 2 channel's , creating listener.here.at same time on client end subscribing 2 channel's on basis of object id.

2) publish ios end same channels creating multiple requests @ web end.so multiple db entries going create.

here code sample of subscribing , unsubscribing.

$pubnub.add_listener("broadcast_#{broadcast.id.to_s}")  $pubnub.subscribe("broadcast_#{broadcast.id.to_s},broadcastlikes_#{broadcast.id.to_s}")    $pubnub.publish("broadcast_#{self.id.to_s}", { type: "stopbroadcast", text: text }) $pubnub.remove_listener("broadcast_#{self.id.to_s}") $pubnub.unsubscribe("broadcast_#{self.id.to_s}, broadcastlikes_#{self.id.to_s}") 

anyone can me!

a collection of answers comments:

if need send messages clients server, why not post them? doing subscribing server replacing traditional web app post doesn't provide advantage. part should using pubnub other direction: server client.

q: what role of add_listener here? relationship between subscribe , add_listener?

a: listener channel subscribes responses , statuses. create single, global (app level) listener channels. when subscribe channel, messages published channel arrive in listener. when unsubscribe channel, no longer receive messages published channel. can subscribed many channels can control channels subscribed (listening to) desired. when unsubscribe channels, not anymore messages.

q: i have doubt single global listener able handle multiple messages @ same time,is there chances miss. should remove listener or not? if yes when? , per new ruby pubnub v4 not showing more details listener that's why getting confused.

a: single listener design pattern not miss messages. there no current support multiple listeners (at least not out of box) why interested in multiple listener requirement. know single/global listener receive messages published channels app subscribed to.

q: and remove listener, should need this? if yes when. if no there problem? per multiple listeners requirement can separate each listener own event listen reduce load of single global listener. in case multiple callback requests hitting same callback @ time.

a: don't need to removelistener, really. if no done pubnub in app, can call clean out little bit of memory (very little though). , assure you, can use single listener without issues. not overloaded. listener multi-thread/thread-safe, otherwise pubnub not work @ (or in desirable way).


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -