pub type Config = HashMap<String, Route>;Expand description
The top-level configuration is a map of named routes. The key is the route name (e.g., “kafka_to_nats”).
§Examples
Deserializing a complex configuration from YAML:
use mq_bridge::models::{Config, EndpointType, Middleware};
let yaml = r#"
kafka_to_nats:
concurrency: 10
input:
middlewares:
- deduplication:
sled_path: "/tmp/mq-bridge/dedup_db"
ttl_seconds: 3600
- metrics: {}
- retry:
max_attempts: 5
initial_interval_ms: 200
- random_panic:
mode: nack
- dlq:
endpoint:
nats:
subject: "dlq-subject"
url: "nats://localhost:4222"
kafka:
topic: "input-topic"
url: "localhost:9092"
group_id: "my-consumer-group"
tls:
required: true
ca_file: "/path_to_ca"
cert_file: "/path_to_cert"
key_file: "/path_to_key"
cert_password: "password"
accept_invalid_certs: true
output:
middlewares:
- metrics: {}
- dlq:
endpoint:
file:
path: "error.out"
nats:
subject: "output-subject"
url: "nats://localhost:4222"
"#;
let config: Config = serde_yaml_ng::from_str(yaml).unwrap();
let route = config.get("kafka_to_nats").unwrap();
assert_eq!(route.options.concurrency, 10);
// Check input middleware
assert!(route.input.middlewares.iter().any(|m| matches!(m, Middleware::Deduplication(_))));
// Check output endpoint
assert!(matches!(route.output.endpoint_type, EndpointType::Nats(_)));Aliased Type§
pub struct Config { /* private fields */ }