【问题标题】:Pubnub publish not publishingPubnub 发布不发布
【发布时间】:2015-10-01 11:04:52
【问题描述】:

我正在尝试将消息发布到 pubnub 频道,但未在服务器上发布。但是它在本地机器上工作得很好。知道我哪里做错了吗?

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 ruby-on-rails-4 activerecord pubnub


    【解决方案1】:

    好的,通过一些研究和调试,我能够解决这个问题。发生此问题是因为默认情况下 Ruby 操作是异步的。因此脚本在发布完成之前终止。幸运的是,我们为此 pubnub 的发布方法提供了一个选项 http_sync。将其设置为 true 可确保在发布完成之前不会终止该流程。所以新代码是

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-22
      • 1970-01-01
      相关资源
      最近更新 更多