Skip to content

@meshqljs/pubsub (@meshql/pubsub)

Pub/sub backends for MeshQL real-time subscriptions (v0.9.0).

Terminal window
npm install @meshqljs/pubsub
Terminal window
npx jsr add @meshql/pubsub

Published on npm as @meshqljs/pubsub and JSR as @meshql/pubsub.

BackendImportUse case
In-memory@meshql/pubsubDev, single-node
Redis@meshql/pubsub/redisProduction, multi-node
Postgres@meshql/pubsub/postgresZero extra infra (LISTEN/NOTIFY)
import {
InMemoryPubSubStore,
entityRecordChannel,
notifyEntityUpdate,
} from "@meshqljs/pubsub";
const pubsub = new InMemoryPubSubStore();
pubsub.subscribe(entityRecordChannel("post", 1), (message) => {
console.log("update", message.payload);
});
notifyEntityUpdate(pubsub, "post", 1);
import {
InMemoryPubSubStore,
entityRecordChannel,
notifyEntityUpdate,
} from "@meshql/pubsub";
const pubsub = new InMemoryPubSubStore();
pubsub.subscribe(entityRecordChannel("post", 1), (message) => {
console.log("update", message.payload);
});
notifyEntityUpdate(pubsub, "post", 1);
import { createRedisPubSubStore } from "@meshqljs/pubsub/redis";
const pubsub = createRedisPubSubStore({
url: process.env.REDIS_URL!,
});
import { createRedisPubSubStore } from "@meshql/pubsub/redis";
const pubsub = createRedisPubSubStore({
url: process.env.REDIS_URL!,
});
import { Pool } from "pg";
import { createPostgresPubSubStore } from "@meshqljs/pubsub/postgres";
const pool = new Pool({ connectionString: process.env.DATABASE_URL });
const pubsub = createPostgresPubSubStore({ pool });
import { Pool } from "pg";
import { createPostgresPubSubStore } from "@meshql/pubsub/postgres";
const pool = new Pool({ connectionString: process.env.DATABASE_URL });
const pubsub = createPostgresPubSubStore({ pool });

Pairs with @meshql/sse for browser subscriptions. See From GraphQL — Subscriptions.