- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我目前正在尝试替换 actioncable用一个小 Phoenix 应用程序。我需要做的是从 redis 获取信息 channel 并将其流式传输到 ember客户。我一直在尝试使用 Redis.PuSub 和 Phoenix Redis 适配器,但未能完全涵盖我们目前拥有的功能。
当前的功能是这样的:
我们的服务器接收到来自用户的请求并将一些输出记录到 Redis channel 。该 channel 的名称是字符串和键的组合。然后,Ember 客户端使用相同的 key 向 action-cable 发出请求。然后,Action-cable 从具有相同名称的 Redis channel 流式传输记录的信息。我需要知道的是如何在用户发出请求时开始收听具有给定名称的 Redis channel 并将该信息连续流式传输到客户端。我已经设法得到一个或另一个,但不是两个。
我已经为此苦思了一天多了,所以非常感谢任何帮助。
干杯
最佳答案
所以为了解决这个问题,我做了以下事情。
首先,我根据 docs 将 Redix.PubSub 设置为依赖项.然后在 channel 中我做了:
defmodule MyApp.ChannelName do
use Phoenix.Channel
def join(stream_name, _message, socket) do
# Open a link to the redis server
{:ok, pubsub} = Redix.PubSub.start_link()
# Subscribe to the users stream
Redix.PubSub.subscribe(pubsub, stream_name, self())
{:ok, socket}
end
# Avoid throwing an error when a subscribed message enters the channel
def handle_info({:redix_pubsub, redix_pid, :subscribed, _}, socket) do
{:noreply, socket}
end
# Handle the message coming from the Redis PubSub channel
def handle_info({:redix_pubsub, redix_pid, :message, %{channel: channel, payload: message}}, socket) do
# Push the message back to the user
push socket, "#{channel}", %{message: message}
{:noreply, socket}
end
end
在我的例子中,我要求用户注册一个具有某个名称的 channel ,例如channel_my_api_key
。然后我会开始监听 redis channel channel_my_api_key
并通过 push
函数将信息流式传输回用户。注意广播可以代替推送。
还要感谢来自 Elixir 论坛的 Alex Garibay,他帮助我找到了解决方案。您可以找到线程 here .
关于redis - 通过 phoenix channel 从 redis channel 流式传输,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39875068/
我正在尝试从模板中的列表( )中提取值,但出现此错误: lists in Phoenix.HTML and templates may only contain integers represent
我正在阅读 Programming Phoenix 这本书,一切都很好,直到第 44 页要求我重新启动 Phoenix 服务器。 我用双 Ctrl + C 杀死了当前服务器,但是当我尝试再次运行 mi
我的应用程序和 api json 请求以及常规 html 都可以工作。我的路由器.ex defmodule MyApp.Router do use MyApp.Web, :router pip
我想在模板中将对象呈现为 JSON。我试过: 但是我得到一个错误 protocol Phoenix.HTML.Safe not implemented for %Ecto.Changeset{...
在 phoenix 框架的 View 中,在 div 元素内生成两个 span 元素的方法是什么? 最佳答案 为了做到这一点,可以只使用一个数组并将其作为 div 标签的值传递给内部,如下所示: de
我从 Rails 迁移,并希望这能在我的模板中工作? hello world 似乎没有一个条件得到呈现。如何实现这一目标? 谢
完成示例指南。本章中详细介绍的内容在我的应用程序中不起作用。看起来很简单的事情。我有一个视频模型: defmodule Rumbl.Video do use Rumbl.Web, :model
完成示例指南。本章中详细介绍的内容在我的应用程序中不起作用。看起来很简单的事情。我有一个视频模型: defmodule Rumbl.Video do use Rumbl.Web, :model
通过可选“inputs_for”输入的 Phoenix 嵌套表单导致 Controller 中的 map 无法通过验证。例如,一个帖子有评论。如果我想在创建帖子时为帖子添加评论,嵌套表单将如下所示:
我正在尝试在应用程序中实现不同的语言。所以我所做的是在 Session 的 db 中创建了 lang 变量,它保留了当前选择的语言。 问题是我正在通过更新操作调用和更新值: def update(co
我想在我的网站上实现一个典型的“记住我”功能,它需要一种方法来创建在遥远的 future 过期的 cookie。有没有办法在 Phoenix Framework 中创建它们? 最佳答案 只要给 coo
我正在制作一个多站点应用程序。我想在测试 Controller 之前在连接上设置请求主机。在 Rails 中,我们可以使用 before :each do request.env["HTTP_RE
我知道我可以通过包含以下内容来更新实时取景: if connected?(socket), do: :timer.send_interval(10000, self(), :click) 但是,有没有
Ruby on Rails 带有终端命令 rake routes . Phoenix 有类似的吗? 最佳答案 命令是 $ mix phoenix.routes 关于phoenix-framework
我正在尝试使用 addict包以在我的项目中进行身份验证,但是每当我尝试执行操作(注册、登录...)时,我的 POST 都会出现 CrossDomain 错误。 我已经尝试添加 cors_plug包来
我在 Phoenix 项目,和mix ecto.create , mix ecto.migrate , 和 mix ecto.drop都发出相同的错误: $ mix ecto.drop ==> tzd
在我的帖子模型上,我实现了一个简单的验证 def changeset(model, params \\ :empty) do model |> cast(params, @requ
这主要是为了测试目的,但是我怎样才能在 Heroku 上实现与 mix ecto.reset 相同的效果。这样的命令导致 FATAL: permission denied for database "
我们的 Web 应用程序目前在 C# 中运行在 Windows 和 IIS 上。我们严重依赖此环境中包含的 Windows 身份验证方案。启用 Windows 身份验证后,我们可以检测连接用户的身份,
在我的 Phoenix 应用程序中,我想对单个记录运行 get_by() Ecto 查询 - 但是,我要搜索的字段之一应该评估为 nil ,但 Phoenix/Ecto 禁止使用 nil 作为比较运算
我是一名优秀的程序员,十分优秀!