NixBus 是一个基于 HTTP 的事件总线,旨在简化事件驱动开发并赋能微服务架构。它提供安全、稳健且高效的服务间通信,帮助开发者解耦应用服务,遵循 SOLID 原则,同时避免传统事件总线系统的复杂度。
主要能力
- 通过 HTTP 实现事件总线,支持服务的解耦与事件驱动架构。
- 提供 npm 包
@nixbus/event-bus,便于在 Node.js 项目中集成。 - 支持订阅事件、发布事件,并可配置重试次数、超时和并发数。
- 提供令牌(token)与密码短语(passphrase)进行安全认证。
- 可选区域存储(如伦敦、洛杉矶,更多区域即将推出),以降低延迟并加快处理。
使用方式
- 安装依赖:
npm install @nixbus/event-bus --save -E - 创建事件总线文件(如
event-bus.ts),获取 HTTP 事件总线实例,传入 token 和 passphrase,订阅事件并运行:
import { getNixBusHttp } from '@nixbus/event-bus'
async function main() {
const nixbus = getNixBusHttp({
token: 'your_token',
passphrase: 'your_passphrase',
})
await nixbus.subscribe('event_type', {
id: 'subscriber_id',
action: async (event) => {
console.log('subscriber_id:', event)
},
config: {
maxRetries: 3,
timeout: 10,
concurrency: 5,
},
})
nixbus.run()
}
main().catch(console.error)
- 在应用任意位置发布事件(如
app.ts):
import { getNixBusHttp } from '@nixbus/event-bus'
async function runYourApp() {
const nixbus = getNixBusHttp({
token: 'your_token',
passphrase: 'your_passphrase',
})
await nixbus.publish({
type: 'event_type',
payload: { welcome: 'to the event bus 0' },
})
// Simulate a delay before publishing another event
await new Promise((resolve) => setTimeout(resolve, 2000))
await nixbus.publish({
type: 'event_type',
payload: { welcome: 'to the event bus 1' },
})
}
runYourApp().catch(console.error)
- 运行事件总线:
tsx event-bus.ts - 运行应用:
tsx app.ts
适用场景
- 微服务架构中的服务解耦与事件驱动通信。
- 需要轻量级、基于 HTTP 的事件总线,避免传统系统的运维开销。
- 需要快速集成、按需扩展事件处理能力的 Node.js 应用。
限制与说明
- 官方文本未提供具体的收费价格、性能指标、支持的编程语言(仅示例为 TypeScript/Node.js)或与其他系统的集成细节,这些暂未提供。
- 具体服务等级与配额信息(如标准访问、事件储备、保留期、订阅者数量等)在官方文本中有所提及,但未给出对应价格,因此价格暂未提供。
- 无信用卡即可开始发送事件,具体试用限制暂未提供。