| .. | ||
| src | ||
| package.json | ||
| README.md | ||
| tsconfig.json | ||
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()
});