pluv.io is in preview! Please wait for a v1.0.0 stable release before using this in production.

PubSub

Note: Currently PubSub's are supported for Node.js only.

You may want to run a single room across multiple servers to horizontally scale your API. For that a PubSub will be necessary to share the events, and Persistance will be necessary for syncing storage state across servers.

Usage Example

Let's step through how we'd setup a pubsub to our pluv.io API.

Installation

Install your PubSub and Persistance of your choosing:

1# For the server
2npm install @pluv/pubsub-redis @pluv/persistance-redis
3# Peer-dependencies
4npm install ioredis

Setup your PubSub and Persistance

Create your pluv.io instance with your selected PubSub and Persistance:

1// server/io.ts
2
3import { createIO } from "@pluv/io";
4import { platformNode } from "@pluv/platform-node";
5import { PubSubRedis } from "@pluv/pubsub-redis";
6import { PersistanceRedis } from "@pluv/persistance-redis";
7import { Redis } from "ioredis";
8
9// Setup redis. You can also use a Redis Cluster
10const redis = new Redis({
11 /* redis config here */
12});
13
14export const io = createIO({
15 platform: platformNode({
16 persistance: new PersistanceRedis({ client: redis }),
17 pubSub: new PubSubRedis({
18 publisher: redis,
19 subscriber: redis,
20 }),
21 }),
22});

Available Libraries

Below are the available pubsubs and libraries written for pluv.io. Check the roadmap to see what other providers are to be supported in the future.

PubSubs

Persistances