Pubnub publishes publication

I am trying to post a message to a pubnub channel but not posting it on the server. However, his work is absolutely beautiful on the local machine. Any idea where I am doing this wrong?

class Message < ActiveRecord::Base after_create :send_message_to_driver def send_message_to_ABC $pubnub.publish( channel: "chat_ABC", message: message ) do |env| puts env.parsed_response end end end 

$ pubnub is initialized globally for the application.

+5
source share
1 answer

Good with some research and debugging. I can fix this problem. This problem occurred because, by default, Ruby operations are asynchronous. Therefore, the script is completed before the publication is complete. Fortunately, we have the http_sync option for this pubnub publishing method. By setting it to true, make sure that this thread is not completed before the publication is complete. So the new code

 $pubnub.publish( http_sync: true, channel: "chat_ABC", message: message ) do |env| puts env.parsed_response end 
+6
source

Source: https://habr.com/ru/post/1232703/


All Articles