High performance typesafe message bus server for pub/sub pattern, key-value storage, and central atomic app locks.
A highly configurable message broker written in and for TypeScript.
Type-safe key/value storage.
The data is serialized using a very fast binary encoding and stored on the server using efficient ArrayBuffers.
import {BrokerClient} from '@deepkit/broker'; import {t} from '@deepkit/type'; const client = new BrokerClient(); const userLogins = client.key('logins/123', t.number); await userLogins.set(123); const logins = await userLogins.get(); await userLogins.delete();
Type-safe key/value storage.
import {BrokerClient} from '@deepkit/broker'; const client = new BrokerClient(); client.increment('logins/user1', +1); const v = client.increment('logins/user1', -1); expect(v).toBe(0); client.delete('logins/user1');
Type-safe key/value storage.
import {t} from '@deepkit/type'; import {BrokerClient} from '@deepkit/broker'; const client = new BrokerClient(); const messageSchema1 = t.schema({ value: t.number }); const channel1 = client.channel('channel1', messageSchema1); await channel1.subscribe(v => (message) => { console.log('got message', message); })); await channel1.publish({ value: 1345 });
For critical region locking
import {BrokerClient} from '@deepkit/broker'; const client = new BrokerClient(); if (await client.isLocked('lock1')) { // lock in place already. } // blocks until lock acquired. const lock1 = await client.lock('lock1'); try { // do critical work. } finally { await lock1.unsubscribe(); }
You can implement custom actions on the broker using TypeScript by simply extending the BrokerClient and BrokerKernel. In contrast to other solutions like Redis you are not limited.
The server being regular TypeScript code makes it very easy to deploy your own server wherever you want.
You can deploy Deepkit Broker as WebSocket server as well and access it directly from your frontend application.
import {BrokerKernel} from '@deepkit/broker'; import {TcpServer} from '@deepkit/rpc-tcp'; const server = new TcpServer( new BrokerKernel, process.env.BROKER_HOST || 'localhost:8081' ); server.start();
A carefully optimized binary protocol, serializer and decoder for the v8 engine as well as light abstraction makes Deepkit Broker very fast.