stock-bot/libs/event-bus
2025-06-04 12:26:55 -04:00
..
src changed types around 2025-06-03 17:52:02 -04:00
package.json added initial integration tests with bun 2025-06-04 12:26:55 -04:00
README.md changed types around 2025-06-03 17:52:02 -04:00
tsconfig.json updated files 2025-06-03 18:02:15 -04:00

Event Bus Library

A Redis-based event bus implementation for inter-service communication in the stock-bot project.

Features

  • Publish/subscribe pattern for asynchronous messaging
  • Support for typed events based on @stock-bot/types
  • Reliable message delivery
  • Channel-based subscriptions

Usage

import { createEventBus } from '@stock-bot/event-bus';
import { MarketDataEvent } from '@stock-bot/types';

// Create an event bus instance
const eventBus = createEventBus({
  redisHost: 'localhost',
  redisPort: 6379
});

// Subscribe to market data events
eventBus.subscribe('market.data', async (event: MarketDataEvent) => {
  console.log(`Received price update for ${event.data.symbol}: ${event.data.price}`);
});

// Publish an event
await eventBus.publish('market.data', {
  type: 'MARKET_DATA',
  data: {
    symbol: 'AAPL',
    price: 150.25,
    bid: 150.20,
    ask: 150.30,
    volume: 1000000,
    timestamp: new Date()
  },
  timestamp: new Date()
});