route topics

This commit is contained in:
nora 2022-03-20 18:31:41 +01:00
parent 58de7f1e2d
commit 43d0ce05dc
10 changed files with 98 additions and 49 deletions

View file

@ -1,3 +1,5 @@
use std::sync::Arc;
use haesli_core::{
amqp_todo,
connection::Channel,
@ -29,16 +31,17 @@ pub fn publish(channel_handle: Channel, message: Message) -> Result<()> {
.get(exchange.as_str())
.ok_or(ChannelException::NotFound)?;
let queue = routing::route_message(exchange, &message.routing.routing_key)
.ok_or(ChannelException::NotFound)?;
queue
.event_send
.try_send(QueueEvent::PublishMessage(message))
.map_err(|err| {
error!(?err, "Failed to send message to queue event queue");
ConException::InternalError
})?;
let queues = routing::route_message(exchange, &message.routing.routing_key)
.ok_or(ChannelException::NotFound)?; // todo this isn't really correct but the tests pass ✔️
for queue in queues {
queue
.event_send
.try_send(QueueEvent::PublishMessage(Arc::clone(&message)))
.map_err(|err| {
error!(?err, "Failed to send message to queue event queue");
ConException::InternalError
})?;
}
Ok(())
}