Skip to content

Almiro-Studios/pubsub

Repository files navigation

Almiro Studios Pub/Sub Service + Library

Description

A simple pub/sub service to send and receive messages between clients.

Requirements

  • Node.js v16 or higher
  • Redis server

Server usage

Environment variables used

REDIS_HOST=localhost
REDIS_PORT=6379 (optional, will default to redis default port)

Docker usage

docker build . -t pubsub
docker run -e REDIS_HOST=localhost -e REDIS_PORT=6379 -p 8102:8102 -t pubsub

Installation

git clone https://github.com/Almiro-Studios/pubsub.git
cd pubsub
npm install

Build

npm run build

Run

npm start

or

npm run dev

Library usage

Installation

npm i --save @almiro-studios/pubsub

Usage

const PubSub = require('@almiro-studios/pubsub');

PubSub.connect('http://localhost:8102');

PubSub.subscribeToTopic('myTopic', (message) => {
  console.log(message);
});

pubsub.on('connect', () => {
  console.log('Connected to server')

  PubSub.sendMessageToTopic('myTopic', 'Hello, world!');
});

About

Almiro Studios Public PubSub service and library

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages