@codefresh-io/eventbus

中文文档
4.0.3发布于 2026/11/04ISCCommonJS近 30 天下载 2265
原始使用文档
文档目录3 节
  1. cf eventbus
  2. Graceful shutdown
  3. Running integration tests

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

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.

yarn install
yarn test-integration

版本与发布记录

@codefresh-io/eventbus 共发布 55 个版本,首次发布于 2017/03/12;过去 12 个月发布了 10 个版本。

版本发布日期距今
4.0.3latest2026/11/045 天前
4.0.22026/10/3010 天前
4.0.12026/05/265 个月前
4.0.02026/05/255 个月前
3.0.02026/03/108 个月前
3.0.0-alpha.42026/03/058 个月前

关于 @codefresh-io/eventbus 的常见问题

如何安装 @codefresh-io/eventbus?

在项目目录运行 npm install @codefresh-io/eventbus,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@codefresh-io/cf-telemetry(^4.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@codefresh-io/eventbus 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/codefresh-io__eventbus 是否存在。

@codefresh-io/eventbus 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@codefresh-io/eventbus 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=24。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@codefresh-io/eventbus 可以商用吗?

@codefresh-io/eventbus 使用 ISC 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@codefresh-io/eventbus 的下载量有多少?

根据 npm 官方下载统计,@codefresh-io/eventbus 在 2026/10/10 – 2026/11/08 这 30 天内被下载 2,265 次,日均约 76 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@codefresh-io/eventbus 还在维护吗?

最新版本 4.0.3 发布于 2026/11/04(5 天前);至今共发布 55 个版本,其中过去 12 个月发布了 10 个;首次发布于 2017/03/12。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。