A simple pub/sub service to send and receive messages between clients.
- Node.js v16 or higher
- Redis server
REDIS_HOST=localhost
REDIS_PORT=6379 (optional, will default to redis default port)
docker build . -t pubsub
docker run -e REDIS_HOST=localhost -e REDIS_PORT=6379 -p 8102:8102 -t pubsub
git clone https://github.com/Almiro-Studios/pubsub.git
cd pubsub
npm install
npm run build
npm start
or
npm run dev
npm i --save @almiro-studios/pubsub
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!');
});