Mongoose connector for ResilientMQ, enabling seamless integration with MongoDB using Mongoose. Handles event storage, status tracking, and serializer support out-of-the-box.
- 📦 Installation
- 📚 Purpose
- 🧩 Main Concepts
- 🔧 Config: MongooseConnectorConfig
- 🧩 Custom Event Storage Format
- 🚀 Example: Consumer
- 🚀 Example: Publisher
- 🧪 Tests
- Docs
- LICENSE
npm install @resilientmq/mongoose-connectorThis package acts as a wrapper for the ResilientMQ core logic and provides MongoDB-backed event persistence.
- Automatically injects Mongoose-based
EventStore - Manages a singleton DB connection
- Allows full schema customization via serializer
| Feature | Description |
|---|---|
setEnvironment(config) |
Initializes Mongo + RabbitMQ settings |
consume() |
Starts consumer with Mongo-backed storage |
publish(event) |
Publishes using resilient pattern |
serializer |
Transforms event ↔ DB formats |
singleton |
Keeps one shared MongoDB connection |
| Property | Type | Required | Description |
|---|---|---|---|
mongo.uri |
string |
✅ | MongoDB URI |
mongo.options |
ConnectOptions |
❌ | Optional connection opts |
rabbit.consumer |
Omit<ResilientConsumerConfig, 'store'> |
❌ | Consumer settings |
rabbit.consumer.model |
Model |
❌ | Custom Mongoose model |
rabbit.consumer.serializer |
EventSerializer |
❌ | Custom serializer |
rabbit.publisher |
Omit<ResilientPublisherConfig, 'store'> |
❌ | Publisher settings |
rabbit.publisher.model |
Model |
❌ | Custom Mongoose model |
rabbit.publisher.serializer |
EventSerializer |
❌ | Custom serializer |
logLevel |
'none' | 'warn' | 'info' | 'error' |
❌ | Logger verbosity |
Supports pluggable serializers to convert the event to your preferred DB structure.
const serializer = {
toStorageFormat(event) {
return {
_id: event.id,
body: event.payload,
customStatus: event.status
};
},
fromStorageFormat(doc) {
return {
id: doc._id,
messageId: doc._id,
payload: doc.body,
status: doc.customStatus,
type: 'custom.type'
};
},
getStatusField() {
return 'customStatus';
}
};import { setEnvironment, consume } from '@resilientmq/mongoose-connector';
await setEnvironment({
mongo: {
uri: 'mongodb://localhost:27017/events'
},
rabbit: {
consumer: {
connection: 'amqp://localhost',
consumeQueue: {
queue: 'my.queue',
options: { durable: true }
},
eventsToProcess: [
{ type: 'my.event', handler: async (payload) => console.log(payload) }
]
},
publisher: {
connection: 'amqp://localhost'
}
}
});
await consume();import { publish } from '@resilientmq/mongoose-connector';
await publish({
id: 'evt-1',
messageId: 'msg-1',
type: 'user.created',
payload: { name: 'Alice' },
status: 'PENDING_PUBLICATION'
});- ✅ Unit tested
- ✅ Uses Jest + mocks
- ✅ Compatible with
jest --coverage
|
Hector L. Arrechea 💻 📖 🚇 |