Fully decoupled microservices using event-driven communication with RabbitMQ message broker and event sourcing.
- Fast synchronous event processing
- Development and testing
- Located:
databases/event-patterns/EventBus.ts
- Asynchronous event processing
- Persistent message queues
- Production-ready with retry logic
- Located:
databases/event-patterns/MessageBroker.ts
- Event sourcing for audit trails
- State reconstruction capability
- Located:
databases/event-patterns/EventStore.ts
- Retry logic with exponential backoff
- Dead letter queue for failed events
- Located:
databases/event-patterns/AsyncEventProcessor.ts
Service A → Publish Event → [EventBus + MessageBroker]
↓
Event Handlers
↓
[Notification, Billing, Analytics Services]
payment.success- Payment completed successfullypayment.failed- Payment failed
bill.created- New bill generatedbill.paid- Bill marked as paid
user.created- New user registereduser.updated- User profile updated
notification.sent- Notification delivered
document.uploaded- Document uploaded
- Listen:
payment.success,payment.failed,bill.created - Action: Send email/SMS notifications
- Listen:
payment.success,payment.failed - Action: Update bill status
- Listen: All events (
*) - Action: Track for analytics and reporting
npm run messaging:start- URL: http://localhost:15672
- User: admin
- Pass: admin
Event handlers auto-initialize when services start.
import EventBus from './databases/event-patterns/EventBus';
import MessageBroker from './databases/event-patterns/MessageBroker';
import { createPaymentSuccessEvent } from './databases/event-patterns/events';
const event = createPaymentSuccessEvent(paymentId, billId, userId, amount);
// In-memory (fast)
EventBus.publish(event);
// Persistent queue (reliable)
await MessageBroker.publish(event);import EventBus from './databases/event-patterns/EventBus';
EventBus.subscribe('payment.success', async (event) => {
// Handle event
console.log('Payment successful:', event.payload);
});import EventStore from './databases/event-patterns/EventStore';
import { analyticsClient } from './databases/clients';
const eventStore = new EventStore({ client: analyticsClient });
// Append event
await eventStore.append(event);
// Get all events for aggregate
const events = await eventStore.getEvents(aggregateId);
// Replay events
await eventStore.replay(aggregateId, async (event) => {
// Reconstruct state
});✅ Decoupled Services - Services don't directly depend on each other ✅ Async Processing - Non-blocking event handling ✅ Fault Tolerance - Retry logic and dead letter queues ✅ Audit Trail - Complete event history via event sourcing ✅ Scalability - Independent event consumers ✅ Real-time Sync - Automatic data propagation across services
- Queue depth
- Message rates
- Consumer count
- Failed deliveries
- Events published per type
- Processing latency
- Retry counts
- DLQ size
RABBITMQ_URL=amqp://localhost
RABBITMQ_USER=admin
RABBITMQ_PASS=admin
REDIS_URL=redis://localhost:6379