mirror of
https://github.com/Noratrieb/haesli.git
synced 2026-01-16 12:45:04 +01:00
improve tracing
This commit is contained in:
parent
bd5d4c03c5
commit
08fa9163b8
14 changed files with 273 additions and 150 deletions
|
|
@ -1,14 +1,14 @@
|
|||
use crate::Result;
|
||||
use amqp_core::{
|
||||
amqp_todo,
|
||||
connection::{Channel, ConnectionEvent},
|
||||
connection::Channel,
|
||||
error::{ChannelException, ConException},
|
||||
message::Message,
|
||||
methods::{BasicDeliver, Method},
|
||||
queue::QueueEvent,
|
||||
};
|
||||
use tracing::debug;
|
||||
use tracing::{debug, error};
|
||||
|
||||
pub async fn publish(channel_handle: Channel, message: Message) -> Result<()> {
|
||||
pub fn publish(channel_handle: Channel, message: Message) -> Result<()> {
|
||||
debug!(?message, "Publishing message");
|
||||
|
||||
let global_data = channel_handle.global_data.clone();
|
||||
|
|
@ -19,38 +19,20 @@ pub async fn publish(channel_handle: Channel, message: Message) -> Result<()> {
|
|||
amqp_todo!();
|
||||
}
|
||||
|
||||
let mut global_data = global_data.lock();
|
||||
let global_data = global_data.lock();
|
||||
|
||||
let queue = global_data
|
||||
.queues
|
||||
.get_mut(routing.routing_key.as_str())
|
||||
.get(routing.routing_key.as_str())
|
||||
.ok_or(ChannelException::NotFound)?;
|
||||
|
||||
{
|
||||
// todo: we just send it to the consumer directly and ignore it if the consumer doesn't exist
|
||||
// consuming is hard, but this should work *for now*
|
||||
let consumers = queue.consumers.lock();
|
||||
if let Some(consumer) = consumers.values().next() {
|
||||
let method = Box::new(Method::BasicDeliver(BasicDeliver {
|
||||
consumer_tag: consumer.tag.clone(),
|
||||
delivery_tag: 0,
|
||||
redelivered: false,
|
||||
exchange: routing.exchange.clone(),
|
||||
routing_key: routing.routing_key.clone(),
|
||||
}));
|
||||
|
||||
consumer
|
||||
.channel
|
||||
.event_sender
|
||||
.try_send(ConnectionEvent::MethodContent(
|
||||
consumer.channel.num,
|
||||
method,
|
||||
message.header.clone(),
|
||||
message.content.clone(),
|
||||
))
|
||||
.map_err(|_| ConException::InternalError)?;
|
||||
}
|
||||
}
|
||||
queue
|
||||
.event_send
|
||||
.try_send(QueueEvent::PublishMessage(message))
|
||||
.map_err(|err| {
|
||||
error!(?err, "Failed to send message to queue event queue");
|
||||
ConException::InternalError
|
||||
})?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue