ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

ruby-on-rails-4-EventController对ActionController :: Live的调用

2019-11-21 05:10:12  阅读:180  来源: 互联网

标签:puma nginx ruby-on-rails-4


我目前正在一个具有以下功能的网站上工作:

>即时聊天
>一些统计
>一些形式

我正在使用:Rails 4 Puma Nginx

我正在使用ActionController :: Live并创建了一个事件动作,该事件动作在页面加载时被调用,并且绑定了侦听器,以监听聊天消息或更改统计信息.

def events
response.headers["Content-Type"] = "text/event-stream"

sse   = ServerEvent.new(response.stream)
redis = Redis.new

# the safe_write method is the implementation of a workaround for the problem stated on
# http://evaleverything.com/2013/09/07/response-streams-with-rails-4-and-redis
sse.safe_write do
  redis.psubscribe("redis-foobar-key*") do |on|
    on.pmessage do |pattern, event, data|
      sse.write(data, { event: event})
    end
  end
end
rescue IOError
  puts "Stream Closed"
ensure
  puts "closing all threads and connections\n"
  redis.quit
  sse.close
end

我面临的问题是:加载页面时,有时一切正常,我可以启动事件源并正确处理事件,但有时事件源请求保持待处理状态,并且不返回任何错误.

我已通过以下方式成功尝试:

>镀铬窗户
> chrome macosx(计算机A)
> firefox macosx(计算机A)

并通过以下方式进行了不成功的尝试:

> chrome ubuntu(在代理之后)
> firefox ubuntu(在代理之后)
> chrome-macosx(计算机B)
> firefox macosx(计算机B)

我正在使用nginx,但是不要以为是问题,这是我的配置

upstream bar {
  server foo.com:9292;
}

server {
  listen 80;
  server_name foo.com megafoo.com;
  root /(...)/public;

  location / {
    proxy_pass http://bar;


    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

    proxy_set_header Connection '';
    proxy_http_version 1.1;
    chunked_transfer_encoding off;

    proxy_buffering off;
    proxy_cache off;

    if (-f $request_filename) {
     break;
    }
  }

  location ~* ^/assets/ {
    # Per RFC2616 - 1 year maximum expiry
    expires 1y;
    add_header Cache-Control public;

    # Some browsers still send conditional-GET requests if there's a
    # Last-Modified header or an ETag header even if they haven't
    # reached the expiry date sent in the Expires header.
    add_header Last-Modified "";
    add_header ETag "";
    break;
  }
}

解决方法:

看起来杀毒软件阻止了连接,不允许其成功完成

标签:puma,nginx,ruby-on-rails-4
来源: https://codeday.me/bug/20191121/2049404.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有