Skip to content

Instantly share code, notes, and snippets.

@mcfiredrill
Created October 7, 2019 10:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcfiredrill/748e8582580429581716a15d254add21 to your computer and use it in GitHub Desktop.
Save mcfiredrill/748e8582580429581716a15d254add21 to your computer and use it in GitHub Desktop.
[error] GenServer #PID<0.664.0> terminating
** (FunctionClauseError) no function clause matching in Chat.MetadataChannel.handle_info/2
(chat) web/channels/metadata_channel.ex:13: Chat.MetadataChannel.handle_info({:redix_pubsub, #PID<0.665.0>, #Reference<0.3467860231.2808610818.72062>, :subscribed, %{channel: "metadata"}}, %Phoenix.Socket{assigns: %{}, channel: Chat.MetadataChannel, channel_pid: #PID<0.664.0>, endpoint: Chat.Endpoint, handler: Chat.UserSocket, id: nil, join_ref: "138", joined: true, private: %{log_handle_in: :debug, log_join: :info}, pubsub_server: Chat.PubSub, ref: nil, serializer: Phoenix.Socket.V1.JSONSerializer, topic: "metadata", transport: :websocket, transport_pid: #PID<0.394.0>})
(phoenix) lib/phoenix/channel/server.ex:304: Phoenix.Channel.Server.handle_info/2
(stdlib) gen_server.erl:637: :gen_server.try_dispatch/4
(stdlib) gen_server.erl:711: :gen_server.handle_msg/6
(stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
Last message: {:redix_pubsub, #PID<0.665.0>, #Reference<0.3467860231.2808610818.72062>, :subscribed, %{channel: "metadata"}}
State: %Phoenix.Socket{assigns: %{}, channel: Chat.MetadataChannel, channel_pid: #PID<0.664.0>, endpoint: Chat.Endpoint, handler: Chat.UserSocket, id: nil, join_ref: "138", joined: true, private: %{log_handle_in: :debug, log_join: :info}, pubsub_server: Chat.PubSub, ref: nil, serializer: Phoenix.Socket.V1.JSONSerializer, topic: "metadata", transport: :websocket, transport_pid: #PID<0.394.0>}
defmodule Chat.MetadataChannel do
use Phoenix.Channel
def join("metadata", message, socket) do
{:ok, pubsub} = Redix.PubSub.start_link()
Redix.PubSub.subscribe(pubsub, "metadata", self())
{:ok, socket}
end
# Handle the message coming from the Redis PubSub channel
def handle_info({:redix_pubsub, :message, message, redis_channel}, socket) do
# do something with the message
# Push the message back to the user over the channel topic
# This assumes the message is already in a map
broadcast! socket, "live_log_#{redis_channel}", message
{:no_reply, socket}
end
def handle_info({:redix_pubsub, pid, ref, :subscribed, channel}, socket) do
# do something with the message
# Push the message back to the user over the channel topic
# This assumes the message is already in a map
broadcast! socket, "live_log_#{redis_channel}", message
{:no_reply, socket}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment