我如何找出谁连接到 ActionCable? [英] How do I find out who is connected to ActionCable?

查看:61
本文介绍了我如何找出谁连接到 ActionCable?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我见过ActionCable.server.open_connections_statisticsActionCable.server.connections.lengthActionCable.server.connections.map(&:statistics)ActionCable.server.connections.select(&:beat).count 等,但这只是每个进程"(服务器、控制台、服务器工作者等).我如何找出此时订阅 ActionCable 的每个人?这应该在每个环境(开发、暂存、生产)中的任何 Rails 进程中返回相同的值.例如,在开发控制台中,您还可以看到开发服务器上的连接,因为它们理论上使用相同的订阅适配器(redis、async、postgres).

I have seen ActionCable.server.open_connections_statistics, ActionCable.server.connections.length, ActionCable.server.connections.map(&:statistics), ActionCable.server.connections.select(&:beat).count and the like, however this is only "per process" (server, console, server worker, et cetera). How do I find out everyone who is subscribed to ActionCable at this time? This should return the same value on any Rails process in each environment (development, staging, production). So for example, in development console you can also see the connections on the development server since they, in theory, use the same subscription adapter (redis, async, postgres).

Rails 5.0.0.beta3,Ruby 2.3.0

Rails 5.0.0.beta3, Ruby 2.3.0

相关ActionCable - 如何显示已连接用户的数量?

推荐答案

如果使用 redis 你可以看到所有的 pubsub 频道.

If using redis you can see all the pubsub channels.

[2] pry(main)> Redis.new.pubsub("channels", "action_cable/*")
[
    [0] "action_cable/Z2lkOi8vbWFvY290LXByb2plL3QvUmVzcG9uXGVyLzEx",
    [1] "action_cable/Z2lkOi8vbWFvY290LXByb2plL3QvUmVzcG9uXGVyLzI"
]

这将显示所有 Puma 工作人员的所有 websocket 连接.如果您有多个服务器,它可能也会在此处显示.

This will show all websocket connections for all the Puma workers together. And if you have multiple servers it will probably show those here too.

这篇关于我如何找出谁连接到 ActionCable?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆