Brokher is a simple adapter to manage message brokers in your applications.
When you need to change your current message broker for other, you may need to change some code in your application. The General Ideia of use brokher is simple change your .env and voila.
You can find Brokher on npm or yarn simple using:
$ npm install brokher
// or
$ yarn add brokher
After install Brokher you need to install your base Brokher lib, in this example I will use RabbitMQ with amqlib
, so install this lib with
$ npm install amqplib
After installing the lib, you need to config Brokher to use your prefered contract, like bellow:
const Brokher = require('brokher');
async function main () {
const brokher = Brokher.setup('rabbit');
/* for pushing some information */
await brokher
.setConnection({ uri: 'rabbitmq_credentials' }) // guest:guest@localhost:5672
.setChannel('topic', { durable: null })
.setExchange('logs')
.setRoutingKey('normal')
.publish({ message: 'Hello, from Brokher');
/* for listing some information */
await brokher
.setConnection({ uri: 'rabbitmq_credentials' })
.setExchange('logs')
.setChannel('topic', { durable: false })
.setRoutingKey('normal')
.subscribe('normal', (message) => {
console.log(message);
})
}
Brokher implements the same contract to every supported Broker, so the principal ideia is don't change your code
Only subscribe
and publish
returns Promise
. The Brokher methods follow chain pattern and builder pattern, so you can use as you like
If you use some brokher that is not Exchange Basead, it's Okay, will me ignorated
The subscribe method receive key that they will listing and callbackFunction that will be trigger when message was received
- RabbitMQ
- Apache Kafka
- Redis
- Amazon SNS
- Amazon sqs
- IBM MQ
- Microsoft BizTalk
- Mule ESB
- Google Cloud Pub/Sub ...
Acidiney Dias
MIT