acalinica
Dynamic channel topics with Phoenix
Hi all,
I’m having a problem which I cannot manage to solve on my own with phoenix channels. Specifically about channels with dynamic topics.
Given that I have the following channel setup:
channel "organization:*", TestWeb.OrganizationChannel
I want to connect on different channels based on dynamic ids passed as topics from the client. Based on a solution I found on an older post I did the following bit:
@impl true
def join(
"organization:" <> organization_id,
params,
socket
) do
# some logic here
Logger.debug("ORG ID -> ", organization_id)
send(self(), :after_join)
{:ok, socket}
end
Everytime I connect to this channel with a topic string that looks like organization:4f1665fa-05d2-450a-bfbd-d105ebb00ede I receive the following error:
** (Protocol.UndefinedError) protocol Enumerable not implemented for "4f1665fa-05d2-450a-bfbd-d105ebb00ede" of type BitString
If I just run in iex “organization:” <> id = “organization:123”, the pattern matches ok. What am I missing here? Is there something special with the join handler?
Thanks in advance and I’m happy to join your community.
Marked As Solved
benwilson512
Hey @acalinica the issue relatively straightforwardly is your Logger.debug call. Logger — Logger v1.20.2 The arguments to Logger.debug are msg and opts so you’re passing in organization_id where it expects options.
To fix simply:
Logger.debug("ORG ID -> #{inspect(organization_id)}")
For me personally when I’m just doing this sort of development logging I just use Kernel — Elixir v1.20.2 so you can just dbg(organization_id)
Also Liked
dimitarvp
You beat me by 10 seconds. Kudos. Or I am getting old.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








