README
- 📨 Extensive predictable logging
- ☔ Covered with integration tests
- 🐇 Supports Google Pub/Sub and RabbitMQ
- 🤡 Mock implementation for your tests
- 💙 Typesafe message and attributes
- 🚦 Automatic message acknowlidgement
- 💓 Check heartbeat if connection is alive
- ⛔ Configurable consumer flow control
- 🐛 Debuggable with
DEBUG:*
Getting started
npm install fuqu
// Create instance
const fuQu = fuQuRabbit<{ hello: string }>(connection, 'my-queue');
// Subscribe handler
fuQu.subscribe(msg => {
console.log('Got this:', msg);
});
// Publish message
fuQu.publish({ hello: 'FuQu!' });
- Handler may be async
- Messages are automatically acknowledged. If there is an error, they are
nack
ed instead.
Create instance
import { connect } from 'amqplib';
import { PubSub } from '@google-cloud/pubsub';
import { fuQuPubSub, fuQuRabbit } from 'fuqu';
// RabbitMQ
const connection = await connect('amqp://localhost');
const fuQu1 = fuQuRabbit(connection, 'my-queue');
// Pub/Sub
const pubSub = new PubSub({/*...*/})
const fuQu1 = fuQuPubSub(pubSub, 'my-queue');
Options
const fuQu = fuQuRabbit(connection, 'my-queue', {
// Throttle your consumers
maxMessages: 1,
// Log all events (typesafe, check for shapes!)
eventLogger: event => {
if (event.action !== 'hc') {
console.log(`FuQu [${event.topicName}] (${event.action})`, event)
}
},
// Mock with in-memory mock for your tests
useMock: process.env.NODE_ENV === 'test',
// Adapter specific options
assertQueueOptions: {/* ... */}
});
- Mock implements all general FuQu options. Accessing underlying message is unsafe and adapter specific options are ignored
eventLogger
is for application logging, if no handler is passed, logging is disabled- For debug purposes, you can also enable logging via
DEBUG:*
,DEBUG:fuqu:*
orDEBUG:fuqu:my-topic:*
maxMessages
is transformed into specific options for each adapter, using custom adapter options might overwrite the behavior
Rude mode
If you want to have optimal FuQu expirience, use imports from fuqu/dist/real
.
Testing
For running tests, start the following containers 🐳
docker-compose up --build
License
This project is licensed under MIT.