This code aims to have an example on how we can use channel_groups
to have one
bot connected to a lot of channels with just 1 connection.
Each channel_group
can hold up to 2K channels and a server can subscribe to up
to 10 channe_groups
within the same connection, this means we can listen to 20K
channels with just one TCP connection.
git clone git@gist.github.com:f2ec831e6203c62d2d54.git pubchat
cd pubchat && npm install
The clients will need to add the channel into a channel group but still publish to the channel (and subscribe to the channel).
We make clients add the channel to the group because they will be the ones getting the channel and group names from the API.
The server will subscribe to a channel group and will get messages from all the channels belonging to that group.
The channel
that a message was sent to can be retrieved from the parameters
sent to the subscribe
function.
Make sure you install everything with npm install
.
To run the test make sure you have a .env
file with everything you need, look
at .env.example
to know what's needed.
Once you have your env set up, run:
forego start
That will run 1 server and 1 client. If you have multiple clients you can run:
forego start -c all=1,client=60