@tbrul/tellthem

0.0.5 • Public • Published


TellThem is an asynchronous communication library for Node.js.

Features

  • 🗄️ Support PubSub and Point to Point
  • 💡 Simple and easy to use
  • 🚀 Many drivers (Redis, In-memory, AMQP, MQTT)
  • 🔁 Retry queue
  • ✅ Typesafe channels
  • 📖 Well documented
  • 🧩 Easily extendable with your own encoders and drivers

See documentation at tellthem.tbrul.dev

Why TellThem ?

I wanted a simple driver based and typesafe library to communicate with my services. Since I'm using AdonisJS for most of my projects, I initially created a library for this framework called adonis6-amqp. But when I wanted to use it in a standalone project, I realized that I needed a more generic library. I found out that there is a perfect library for this purpose called @boringnode/bus, but it's not typesafe , so I decided to create my own that combine the best of both worlds.

Installation

npm install @tbrul/tellthem

Quick start

The library use a manager you need to use to register buses.

import { TellThem } from '@tbrul/tellthem';
import { memory } from '@tbrul/tellthem/drivers/memory';
import { redis } from '@tbrul/tellthem/drivers/redis';

const tellThem = new TellThem({
  default: 'memory',
  buses: {
    memory: {
      driver: memory()
    },
    redis: {
      driver: redis({
        host: 'localhost',
        port: 6379,
      })
    }
  }
});

Once you created your manager, you will use it to create a channel.

import { jsonEncoder } from '@tbrul/tellthem/encoders/json';

const channel = tellThem.channel({
  name: 'my-channel',
  defaultBus: 'memory',
  encoder: jsonEncoder()
})

Then you can use the created channel to publish and subscribe to messages.

channel.publish('hello world');

channel.subscribe((message) => {
  console.log(message);
});

Typesafe channels

Channels are typed using the encoder you used to create them. For example if you want to validate your messages using Zod, you can use the zodJsonEncoder from @tbrul/tellthem/encoders.

const channel = tellThem.channel({
  name: 'my-channel',
  defaultBus: 'memory',
  encoder: zodJsonEncoder({
    schema: z.object({
      myData: z.string(),
    })
  })
})

channel.subscribe((message) => {
  console.log(message.myData); // ✅ Typed
  console.log(message.myOtherData); // ❌ Not typed
});

channel.publish({
  myData: 'hello world', // ✅ Typed
  myOtherData: 'hello world' // ❌ Not typed
})

Credits

This library is inspired by @boringnode/bus.

Package Sidebar

Install

npm i @tbrul/tellthem

Weekly Downloads

1

Version

0.0.5

License

MIT

Unpacked Size

77.1 kB

Total Files

81

Last publish

Collaborators

  • tombrulin