mirror of
https://github.com/Noratrieb/haesli.git
synced 2026-01-14 19:55:03 +01:00
more
This commit is contained in:
parent
08ba799d23
commit
f860714b2b
9 changed files with 64 additions and 24 deletions
|
|
@ -34,18 +34,21 @@ pub fn consume(channel: Channel, basic_consume: BasicConsume) -> Result<Method>
|
|||
|
||||
let mut global_data = global_data.lock();
|
||||
|
||||
let consumer = Consumer {
|
||||
id: ConsumerId::random(),
|
||||
tag: consumer_tag.clone(),
|
||||
channel: Arc::clone(&channel),
|
||||
};
|
||||
|
||||
let queue = global_data
|
||||
.queues
|
||||
.get_mut(queue_name.as_str())
|
||||
.ok_or(ChannelException::NotFound)?;
|
||||
|
||||
queue.consumers.lock().push(consumer);
|
||||
let consumer = Consumer {
|
||||
id: ConsumerId::random(),
|
||||
tag: consumer_tag.clone(),
|
||||
channel: Arc::clone(&channel),
|
||||
queue: Arc::clone(queue),
|
||||
};
|
||||
|
||||
queue.consumers.lock().insert(consumer.id, consumer.clone());
|
||||
|
||||
channel.connection.consuming.lock().push(consumer);
|
||||
|
||||
info!(%queue_name, %consumer_tag, "Consumer started consuming");
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use crate::Result;
|
|||
use amqp_core::{
|
||||
amqp_todo,
|
||||
connection::{Channel, ConnectionEvent},
|
||||
error::ChannelException,
|
||||
error::{ChannelException, ConException, ProtocolError},
|
||||
message::Message,
|
||||
methods::{BasicDeliver, Method},
|
||||
};
|
||||
|
|
@ -30,7 +30,7 @@ pub async fn publish(channel_handle: Channel, message: Message) -> Result<()> {
|
|||
// 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.first() {
|
||||
if let Some(consumer) = consumers.values().next() {
|
||||
let method = Box::new(Method::BasicDeliver(BasicDeliver {
|
||||
consumer_tag: consumer.tag.clone(),
|
||||
delivery_tag: 0,
|
||||
|
|
@ -48,7 +48,7 @@ pub async fn publish(channel_handle: Channel, message: Message) -> Result<()> {
|
|||
message.header.clone(),
|
||||
message.content.clone(),
|
||||
))
|
||||
.unwrap();
|
||||
.map_err(|_| ConException::InternalError)?;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -53,7 +53,11 @@ pub fn declare(channel: Channel, queue_declare: QueueDeclare) -> Result<Method>
|
|||
|
||||
{
|
||||
let mut global_data_lock = global_data.lock();
|
||||
global_data_lock.queues.insert(queue_name.clone(), queue);
|
||||
|
||||
global_data_lock
|
||||
.queues
|
||||
.entry(queue_name.clone())
|
||||
.or_insert(queue);
|
||||
}
|
||||
|
||||
global_data
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue