Skip to content

Latest commit

 

History

History
85 lines (59 loc) · 2.22 KB

File metadata and controls

85 lines (59 loc) · 2.22 KB

Rate-Limited Notification Service

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.

Table of Contents

Features

  • 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.

Usage

Prerequisites

  1. Clone the repository to your local machine.
git clone https://github.com/zejiran/rate-limited-notification-service.git
  1. Build the project.
cargo build
  1. Run the application.
cargo run
  1. 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(),
    },
);
  1. 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),
}

Testing

Unit tests are provided, covering various aspects of the notification service. You can run the tests using Cargo.

cargo test

License

License