Rust-based application that provides rate limiting for sending notifications to recipients. This service allows you to control the rate at which notifications can be sent based on the notification type, recipient, and a predefined rate limit.
- Rate limiting for various notification types.
- Customizable rate limits for each notification type.
- Rate limits are enforced per recipient.
- Logs notification attempts and rate-limit violations.
- Rust and Cargo are installed on your system. If not, you can install them from Rust's official website.
- Clone the repository to your local machine.
git clone https://github.com/zejiran/rate-limited-notification-service.git
- Build the project.
cargo build
- Run the application.
cargo run
- Define Rate Limits
You can define rate limits for different notification types in the main.rs
file. For example:
service.rate_limits.insert(
"status".to_string(),
notification_service::RateLimit {
max_requests: 2,
per_duration: Duration::from_secs(60), // 2 per minute
recipient_counters: HashMap::new(),
},
);
- Send Notifications
You can send notifications using the send
method in the NotificationService
struct. The service will enforce rate limits based on the configuration you set.
match service.send("status", "user123", "This is a status update") {
Ok(()) => println!("Notification sent successfully."),
Err(err) => println!("Failed to send notification: {}", err),
}
Unit tests are provided, covering various aspects of the notification service. You can run the tests using Cargo.
cargo test
- MIT license
- Copyright 2023 © Juan AlegrÃa