Faye Websocket 错误 Rails 2.2.2(生产)
Posted
技术标签:
【中文标题】Faye Websocket 错误 Rails 2.2.2(生产)【英文标题】:Faye Websocket Error Rails 2.2.2 (production) 【发布时间】:2015-08-09 17:42:19 【问题描述】:我一直在 2.1.3 上使用 Faye 没有问题,但是升级到 2.2.2 后我只能让本地实例工作。生产 websocket 失败。 我用 blahblahserver.com 替换了实际的服务器名称
Faye 上架
require 'faye'
app = Faye::RackAdapter.new(:mount => '/faye', :timeout => 25)
Faye::WebSocket.load_adapter('thin')
run app
Application.html.erb
<%= javascript_include_tag "application",params[:controller],'http://app-server1.blahblahserver.com:9292/faye/faye.js','data-turbolinks-track' => true %>
助手(发送功能)
def broadcast(channel, &block)
message = :channel => channel, :data => capture(&block)
uri = URI.parse("http://localhost:9292/faye")
Net::HTTP.post_form(uri, :message => message.to_json)
end
在 Rails 控制器中
gon.env = Rails.env
监听器(咖啡脚本)
$ ->
# required when faye listener is present to keep from having hard env changes
# parallel gon.env = Rails.env in controller must be present
server_name = undefined
switch gon.env
when "production"
server_name = 'app-server1.blahblahserver.com'
when "staging"
server_name = 'si-staging.blahblahserver.com'
when "development"
server_name = 'localhost'
address = 'http://' + server_name + ':9292/faye'
# Listener for this page locally
faye = new (Faye.Client)(address)
faye.subscribe ('/logs/'+gon.property_id+ '/new'), (data) ->
if getParameterByName('all_open') == "true"
window.location.href = window.location.href
else if gon.today == gon.display_date
ready(data)
else window.location.href = window.location.href
return
faye.subscribe ('/logs/'+gon.property_id+ '/alert'), (data) ->
console.log('pre-ajax')
$.ajax 'load_customer_messages' ,
type: "GET",
dataType: "JSON",
asnyc: false,
success: (data2) ->
$('#ajax').click()
return
return
ready = (data) ->
eval data
【问题讨论】:
【参考方案1】:所以问题出在Faye的升级上。现在开始的语法如下:
rackup --host [服务器ip地址] faye.ru -s thin -E production -D 现在需要添加 --host [ip address],因为 rackup 不再在没有 ip 地址的情况下从外部侦听。
6 天的挫败感,faye 网站上没有任何文档!
【讨论】:
以上是关于Faye Websocket 错误 Rails 2.2.2(生产)的主要内容,如果未能解决你的问题,请参考以下文章
如何使用 faye-websocket-ruby 向 websocket 客户端发送拒绝连接
尝试使用代理在 Apache 上运行 Faye websocket