mirror of
https://github.com/Noratrieb/haesli.git
synced 2026-01-14 19:55:03 +01:00
add exchanges to internal model
This commit is contained in:
parent
504757b324
commit
58de7f1e2d
15 changed files with 169 additions and 40 deletions
30
haesli_messaging/src/routing.rs
Normal file
30
haesli_messaging/src/routing.rs
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
use haesli_core::{
|
||||
exchange::{Exchange, ExchangeType},
|
||||
queue::Queue,
|
||||
};
|
||||
|
||||
pub fn bind(exchange: &mut Exchange, routing_key: String, queue: Queue) {
|
||||
match &mut exchange.kind {
|
||||
ExchangeType::Direct { bindings } => {
|
||||
bindings.insert(routing_key, queue);
|
||||
}
|
||||
ExchangeType::Fanout { bindings } => bindings.push(queue),
|
||||
ExchangeType::Topic { bindings } => bindings.push((routing_key, queue)),
|
||||
ExchangeType::Headers => {} // unsupported
|
||||
ExchangeType::System => {} // unsupported
|
||||
}
|
||||
}
|
||||
|
||||
/// Route a message to a queue. Returns the queue to send it to, or `None` if it can't be matched
|
||||
pub fn route_message(exchange: &Exchange, routing_key: &str) -> Option<Queue> {
|
||||
match &exchange.kind {
|
||||
ExchangeType::Direct { bindings } => {
|
||||
// 3.1.3.1 - routing-key = routing-key
|
||||
bindings.get(routing_key).cloned()
|
||||
}
|
||||
ExchangeType::Fanout { .. } => None,
|
||||
ExchangeType::Topic { .. } => None,
|
||||
ExchangeType::Headers => None, // unsupported
|
||||
ExchangeType::System => None, // unsupported
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue