-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Docs: add usage instructions and features description
- Loading branch information
Showing
1 changed file
with
83 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,85 @@ | ||
# Rate-Limited Notification Service | ||
|
||
A Rust project demonstrating a simple 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 | ||
|
||
- [Rate-Limited Notification Service](#rate-limited-notification-service) | ||
- [Table of Contents](#table-of-contents) | ||
- [Features](#features) | ||
- [Usage](#usage) | ||
- [Prerequisites](#prerequisites) | ||
- [Testing](#testing) | ||
- [License](#license) | ||
|
||
## 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 | ||
|
||
- Rust and Cargo are installed on your system. If not, you can install them from [Rust's official website](https://www.rust-lang.org/tools/install). | ||
|
||
1. Clone the repository to your local machine. | ||
|
||
```bash | ||
git clone https://github.com/zejiran/rate-limited-notification-service.git | ||
``` | ||
|
||
2. Build the project. | ||
|
||
```bash | ||
cargo build | ||
``` | ||
|
||
3. Run the application. | ||
|
||
```bash | ||
cargo run | ||
``` | ||
|
||
4. Define Rate Limits | ||
|
||
You can define rate limits for different notification types in the `main.rs` file. For example: | ||
|
||
```rust | ||
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(), | ||
}, | ||
); | ||
``` | ||
|
||
5. 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. | ||
|
||
```rust | ||
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. | ||
|
||
```bash | ||
cargo test | ||
``` | ||
|
||
## License | ||
|
||
[](http://badges.mit-license.org) | ||
|
||
- **[MIT license](LICENSE)** | ||
- Copyright 2023 © Juan Alegría |