@codefresh-io/eventbus
v3.0.0-alpha.3
Published
```TS const eventbus = require('cf-eventbus');
Downloads
654
Maintainers
Keywords
Readme
cf eventbus
const eventbus = require('cf-eventbus');
eventbus.init({
bus: {
url: 'amqp://codefresh.dev', // rabbitmq server
reconnectInterval: 5
},
store: {
host: 'codefresh.dev', // postgres host
database: 'postgres', // postgres database
user: 'postgres', // postgres user
password: 'postgres' // postgres password
},
microServiceName: 'service-name' // client name
});Graceful shutdown
quit() method can be used to gracefully terminate the bus connection by cancelling all consumers, waiting for all consumers in progress to finish, and then closing the connection.
If it's not desired, use quit({ force: true }) to terminate the connection immediately.
const eventbus = require('cf-eventbus');
process.on('SIGTERM', async () => {
try {
await eventbus.quit();
// ...
} catch (err) {
// ...
}
});It's may be required to perform some additional cleanup after all consumers are cancelled and before the connection is closed. In that case, use the following pattern:
const eventbus = require('cf-eventbus');
process.on('SIGTERM', async () => {
try {
await eventbus.cancelAllConsumers();
await eventbus.waitForConsumersToFinish();
// perform additional cleanup here, such as waiting for HTTP requests to finish
await eventbus.quit();
// ...
} catch (err) {
// ...
}
});