Pulses
Pulses is a robust and flexible background job processing library for Rust. It is designed to be modular, allowing for pluggable brokers (currently supporting Redis Streams) and providing a type-safe way to define message handlers.
Features
- Pluggable Architecture: Support for different message brokers. Currently ships with a Redis Streams implementation.
- Type-Safe Handlers: Define handlers using Rust traits with compile-time checks.
- Concurrency Control: Fine-grained control over worker counts and max-in-flight messages per handler.
- Reliability: Built-in mechanisms for message acknowledgement, automatic retries, and reclaiming pending messages from crashed consumers.
- Graceful Shutdown: Integrated with
tokio's cancellation tokens for clean shutdown sequences.
Installation
Add pulses to your Cargo.toml. Since this is currently a library within your workspace or a local path, you might reference it like this:
[]
= { = "0.1.0" } # Or git repository
= { = "1", = ["full"] }
Usage
Here is a simple example of how to create a handler and run the application using the Redis broker.
1. Define a Handler
Implement the Handler trait for your logic. You can specify which streams to listen to and how many concurrent workers to run.
use Arc;
use ;
use RedisBroker;
;
2. Run the Application
Initialize the broker, configure the subscription (consumer group settings), register your handlers, and run the app.
use App;
use ;
use CancellationToken;
async
Architecture
- App: The main entry point that ties the broker, subscription, and handlers together.
- Broker: A trait abstracting the underlying message queue (e.g., Redis, Kafka).
- Handler: User-defined logic for processing messages.
- Runtime: Handles the loop of polling, dispatching to handlers, managing retries, and reclaiming stuck messages.
License
[License information here]