cf eventbus
const eventbus = require('cf-eventbus');
eventbus.init({
bus: {
url: 'amqp://codefresh.dev',
reconnectInterval: 5
},
store: {
host: 'codefresh.dev',
database: 'postgres',
user: 'postgres',
password: 'postgres'
},
microServiceName: 'service-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();
await eventbus.quit();
} catch (err) {
}
});