
rainforest
Real-Time Phoenix: use PubSub with implementation of Phoenix.Socket.Transport rather than channels (page 37)
Hi, I’ve got a question about the implementation of PubSub when using a Phoenix.Socket.Transport behaviour rather than channels.
Before reading the book, I wrote a websocket server in Elixir using the Phoenix.Socket.Transport behaviour.
Since I’d like to use the PubSub to broadcast over multiple servers (using pg2 and libcluster to deliver messages also to remote nodes that are not in the same LAN), do I have to switch to channels to do that?
I ask it since in the book is not mentioned if you can build something like that also without channels.
Thanks in advance.
Andrea
First Post!

sb8244
You will probably be successful with calling PubSub.subscribe
inside of your Transport process. This will receive a handle_info callback whenever an event is received over PubSub. You must subscribe to specific topics, which the book goes into detail about.
Think of PubSub as a layer that Phoenix provides. It sits below Channels, and Channels are built on top of it. If you don’t use Channels you can still benefit from PubSub because it’s a completely separate layer. You just need to call the right functions to use it.
Popular Prag Prog topics










Other popular topics










Latest in PragProg
Latest (all)
Categories:
Popular Portals
- /elixir
- /rust
- /wasm
- /ruby
- /erlang
- /phoenix
- /keyboards
- /js
- /rails
- /python
- /security
- /go
- /swift
- /vim
- /clojure
- /java
- /haskell
- /emacs
- /svelte
- /onivim
- /typescript
- /crystal
- /c-plus-plus
- /tailwind
- /kotlin
- /gleam
- /react
- /flutter
- /elm
- /ocaml
- /vscode
- /opensuse
- /ash
- /centos
- /php
- /deepseek
- /scala
- /zig
- /html
- /debian
- /nixos
- /lisp
- /agda
- /textmate
- /react-native
- /sublime-text
- /kubuntu
- /arch-linux
- /revery
- /ubuntu
- /manjaro
- /spring
- /django
- /diversity
- /nodejs
- /lua
- /slackware
- /c
- /julia
- /neovim