This package is now deprecated and will no longer receive updates. We recommend migrating to official solutions for your pub/sub and messaging needs.
After careful consideration, we've decided to deprecate fuqu
because:
- Modern official pub/sub libraries and messaging solutions now provide excellent native functionality
- Maintaining an abstraction layer over these services adds unnecessary complexity to codebases
- Direct usage of official SDKs offers better type safety, up-to-date features, and comprehensive documentation
We recommend migrating to official solutions based on your specific needs:
- Google Cloud Pub/Sub: Official Client Libraries
- AWS SNS/SQS: AWS SDK
- Azure Service Bus: Azure SDK
We want to thank all contributors and users who have supported this package. While fuqu
served its purpose during its active period, we believe pointing users toward official solutions will provide a better developer experience in the long run.
This repository will remain available for reference, but we encourage all users to migrate to the recommended alternatives. No new features or bug fixes will be implemented.
- 📨 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:*
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.
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');
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
If you want to have optimal FuQu expirience, use imports from fuqu/dist/real
.
For running tests, start the following containers 🐳
docker-compose up --build
This project is licensed under MIT.