Receiving and Sending messages based on a pattern (Phoenix topics)

In RabbitMQ it is possible to create topics using patterns
https://www.rabbitmq.com/tutorials/tutorial-five-elixir.html. For example:

a.b.c
a.*.c
a.b.*
*.b.*
*.*.c

Is it possible to do the same with Phoenix Channel?
For example, if I have a room “elixir: *” and users “elixir: user_123”, “elixir: user1234”. I would like to send messages to the user “user_123” specifically and at another moment for all users of the room “elixir”

Sending it sent to specific processes, which could be distributed. So as far as I know there is no way to do that with a single call as it is, however it wouldn’t be hard to make such a call yourself, a simple registry of names, although you’d want to optimize it well so it’s not just a linear lookup or so.

However I would not recommend it, this is backwards from the Phoenix way. Instead a listen channel should listen to multiple topics, such as both an elixir:user and elixir:user:123 or so. Then you send on whichever. A single process/actor can listen to many topics at the same time. This will be pretty perfectly efficient for the system.

2 Likes