| Crates.io | scoutquest-rust |
| lib.rs | scoutquest-rust |
| version | 1.4.0 |
| created_at | 2025-09-20 10:51:56.790719+00 |
| updated_at | 2025-09-22 09:00:10.795163+00 |
| description | Rust SDK for ScoutQuest Service Discovery - Universal service discovery for microservices architectures |
| homepage | https://github.com/RomainDECOSTER/scoutquest#readme |
| repository | https://github.com/RomainDECOSTER/scoutquest |
| max_upload_size | |
| id | 1847639 |
| size | 130,807 |
Rust SDK for ScoutQuest Service Discovery - Universal service discovery for microservices architectures.
Add this to your Cargo.toml:
[dependencies]
scoutquest-rust = "1.0.0"
use scoutquest_rust::*;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create client
let client = ServiceDiscoveryClient::new("http://localhost:8080")?;
// Register a service
let options = ServiceRegistrationOptions::new()
.with_tags(vec!["api".to_string(), "v1".to_string()])
.with_metadata({
let mut metadata = std::collections::HashMap::new();
metadata.insert("version".to_string(), "1.2.3".to_string());
metadata
});
client.register_service("user-service", "localhost", 3000, Some(options)).await?;
// Discover services
let instances = client.discover_service("payment-service", None).await?;
// Make HTTP calls to discovered services
let response: serde_json::Value = client.get("payment-service", "/api/balance").await?;
// Graceful shutdown
client.deregister().await?;
Ok(())
}
use scoutquest_rust::*;
let client = ServiceDiscoveryClient::new("http://localhost:8080")?;
// Service discovery returns a ready-to-use service instance
let instance = client.discover_service("api-service", None).await?;
// Use the instance to make HTTP calls
let response = client.get(&instance, "/users", None).await?;
let discovery_options = ServiceDiscoveryOptions::new()
.with_healthy_only(true)
.with_tags(vec!["production".to_string(), "api".to_string()])
.with_limit(5);
let instances = client.discover_service("user-service", Some(discovery_options)).await?;
// GET request
let users: serde_json::Value = client.get("user-service", "/api/users").await?;
// POST request
let new_user = serde_json::json!({
"name": "John Doe",
"email": "john@example.com"
});
let response: serde_json::Value = client.post("user-service", "/api/users", new_user).await?;
// Custom request with specific load balancing
let response: serde_json::Value = client.call_service(
"user-service",
"/api/health",
reqwest::Method::GET,
None,
LoadBalancingStrategy::HealthyOnly
).await?;
use scoutquest_rust::*;
let health_check = HealthCheck {
url: "/health".to_string(),
interval_seconds: 30,
timeout_seconds: 5,
method: "GET".to_string(),
expected_status: 200,
headers: None,
};
let options = ServiceRegistrationOptions::new()
.with_health_check(health_check);
client.register_service("api-service", "localhost", 8080, Some(options)).await?;
Create a client with custom configuration:
use std::time::Duration;
let client = ServiceDiscoveryClient::with_config(
"http://localhost:8080",
Duration::from_secs(30), // HTTP timeout
3, // Retry attempts
Duration::from_secs(1), // Retry delay
)?;
See the examples/ directory for complete examples:
examples/basic_usage.rsexamples/http_client.rsexamples/load_balancing.rsRun examples with:
cargo run --example basic_usage
cargo run --example http_client
cargo run --example load_balancing
The SDK provides comprehensive error types:
use scoutquest_rust::ScoutQuestError;
match client.discover_service("unknown-service", None).await {
Ok(instances) => println!("Found {} instances", instances.len()),
Err(ScoutQuestError::ServiceNotFound { service_name }) => {
println!("Service {} not found", service_name);
}
Err(ScoutQuestError::NetworkError(e)) => {
println!("Network error: {}", e);
}
Err(e) => println!("Other error: {}", e),
}
Run the test suite:
# Unit tests
cargo test
# Integration tests
cargo test --test integration_tests
# All tests with output
cargo test -- --nocapture
Run performance benchmarks:
cargo bench
This will benchmark load balancing strategies and other performance-critical operations.
git checkout -b feature/amazing-feature)git commit -m 'Add some amazing feature')git push origin feature/amazing-feature)This project is licensed under the MIT License - see the LICENSE file for details.