## cf eventbus

```TS
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.

```TS
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:

```TS
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) {
        // ...
    }
});
```

## Running integration tests

Integration tests start the containers up RabbitMQ and PostgreSQL via Docker Compose, run `test/integration.js` against them, and then shut the containers down. Docker (with the `docker compose` plugin) must be running locally.
```sh
yarn install
```
```sh
yarn test-integration
```
