我正在尝试向 pubnub channel 发布消息,但它未在服务器上发布。然而它在本地机器上工作得绝对正常。知道我哪里做错了吗?
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 正在为应用程序进行全局初始化。
最佳答案
好的,通过一些研究和调试,我能够解决这个问题。出现此问题的原因是,默认情况下,Ruby 操作是异步的。因此脚本在发布完成之前终止。幸运的是,我们为这个 pubnub 的发布方法提供了一个选项 http_sync。将其设置为 true 可确保该流程在发布完成之前不会终止。所以新代码是
$pubnub.publish(
http_sync: true,
channel: "chat_ABC",
message: message
) do |env|
puts env.parsed_response
end
关于ruby - pubnub 发布不发布,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32886003/