mirror of
https://github.com/Noratrieb/haesli.git
synced 2026-01-14 19:55:03 +01:00
queue declare
This commit is contained in:
parent
606438f301
commit
8532d454c3
13 changed files with 255 additions and 71 deletions
|
|
@ -7,5 +7,7 @@ edition = "2021"
|
|||
|
||||
[dependencies]
|
||||
amqp_core = { path = "../amqp_core" }
|
||||
parking_lot = "0.12.0"
|
||||
tracing = "0.1.31"
|
||||
tokio = { version = "1.17.0", features = ["full"] }
|
||||
tokio = { version = "1.17.0", features = ["full"] }
|
||||
uuid = "0.8.2"
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
use amqp_core::error::{ConException, ProtocolError};
|
||||
use amqp_core::message::Message;
|
||||
use amqp_core::methods::Method;
|
||||
use amqp_core::ChannelHandle;
|
||||
use tracing::{debug, info};
|
||||
|
||||
pub async fn handle_basic_publish(_channel_handle: ChannelHandle, message: Message) {
|
||||
info!(
|
||||
?message,
|
||||
"Someone has summoned the almighty Basic.Publish handler"
|
||||
);
|
||||
}
|
||||
|
||||
pub async fn handle_method(
|
||||
_channel_handle: ChannelHandle,
|
||||
method: Method,
|
||||
) -> Result<(), ProtocolError> {
|
||||
match method {
|
||||
Method::ExchangeDeclare { .. } => Err(ConException::NotImplemented.into()),
|
||||
Method::ExchangeDeclareOk => Err(ConException::NotImplemented.into()),
|
||||
Method::ExchangeDelete { .. } => Err(ConException::NotImplemented.into()),
|
||||
Method::ExchangeDeleteOk => Err(ConException::NotImplemented.into()),
|
||||
Method::QueueDeclare { .. } => Err(ConException::NotImplemented.into()),
|
||||
Method::QueueDeclareOk { .. } => Err(ConException::NotImplemented.into()),
|
||||
Method::QueueBind { .. } => Err(ConException::NotImplemented.into()),
|
||||
Method::QueueBindOk => Err(ConException::NotImplemented.into()),
|
||||
Method::QueueUnbind { .. } => Err(ConException::NotImplemented.into()),
|
||||
Method::QueueUnbindOk => Err(ConException::NotImplemented.into()),
|
||||
Method::QueuePurge { .. } => Err(ConException::NotImplemented.into()),
|
||||
Method::QueuePurgeOk { .. } => Err(ConException::NotImplemented.into()),
|
||||
Method::QueueDelete { .. } => Err(ConException::NotImplemented.into()),
|
||||
Method::QueueDeleteOk { .. } => Err(ConException::NotImplemented.into()),
|
||||
Method::BasicQos { .. } => Err(ConException::NotImplemented.into()),
|
||||
Method::BasicQosOk => Err(ConException::NotImplemented.into()),
|
||||
Method::BasicConsume { .. } => Err(ConException::NotImplemented.into()),
|
||||
Method::BasicConsumeOk { .. } => Err(ConException::NotImplemented.into()),
|
||||
Method::BasicCancel { .. } => Err(ConException::NotImplemented.into()),
|
||||
Method::BasicCancelOk { .. } => Err(ConException::NotImplemented.into()),
|
||||
Method::BasicReturn { .. } => Err(ConException::NotImplemented.into()),
|
||||
Method::BasicDeliver { .. } => Err(ConException::NotImplemented.into()),
|
||||
Method::BasicGet { .. } => Err(ConException::NotImplemented.into()),
|
||||
Method::BasicGetOk { .. } => Err(ConException::NotImplemented.into()),
|
||||
Method::BasicGetEmpty { .. } => Err(ConException::NotImplemented.into()),
|
||||
Method::BasicAck { .. } => Err(ConException::NotImplemented.into()),
|
||||
Method::BasicReject { .. } => Err(ConException::NotImplemented.into()),
|
||||
Method::BasicRecoverAsync { .. } => Err(ConException::NotImplemented.into()),
|
||||
Method::BasicRecover { .. } => Err(ConException::NotImplemented.into()),
|
||||
Method::BasicRecoverOk => Err(ConException::NotImplemented.into()),
|
||||
Method::TxSelect
|
||||
| Method::TxSelectOk
|
||||
| Method::TxCommit
|
||||
| Method::TxCommitOk
|
||||
| Method::TxRollback
|
||||
| Method::TxRollbackOk => Err(ConException::NotImplemented.into()),
|
||||
Method::BasicPublish { .. } => {
|
||||
unreachable!("Basic.Publish is handled somewhere else because it has a body")
|
||||
}
|
||||
_ => unreachable!("Method handled by transport layer"),
|
||||
}
|
||||
}
|
||||
17
amqp_messaging/src/methods/consume.rs
Normal file
17
amqp_messaging/src/methods/consume.rs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
use amqp_core::error::ProtocolError;
|
||||
use amqp_core::methods::{Bit, ConsumerTag, NoAck, NoLocal, NoWait, QueueName, Table};
|
||||
use amqp_core::ChannelHandle;
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub async fn consume(
|
||||
_channel_handle: ChannelHandle,
|
||||
_queue: QueueName,
|
||||
_consumer_tag: ConsumerTag,
|
||||
_no_local: NoLocal,
|
||||
_no_ack: NoAck,
|
||||
_exclusive: Bit,
|
||||
_no_wait: NoWait,
|
||||
_arguments: Table,
|
||||
) -> Result<(), ProtocolError> {
|
||||
Ok(())
|
||||
}
|
||||
125
amqp_messaging/src/methods/mod.rs
Normal file
125
amqp_messaging/src/methods/mod.rs
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
mod consume;
|
||||
mod queue;
|
||||
|
||||
use amqp_core::amqp_todo;
|
||||
use amqp_core::error::ProtocolError;
|
||||
use amqp_core::message::Message;
|
||||
use amqp_core::methods::Method;
|
||||
use amqp_core::ChannelHandle;
|
||||
use tracing::info;
|
||||
|
||||
pub async fn handle_basic_publish(_channel_handle: ChannelHandle, message: Message) {
|
||||
info!(
|
||||
?message,
|
||||
"Someone has summoned the almighty Basic.Publish handler"
|
||||
);
|
||||
}
|
||||
|
||||
pub async fn handle_method(
|
||||
channel_handle: ChannelHandle,
|
||||
method: Method,
|
||||
) -> Result<(), ProtocolError> {
|
||||
info!(?method, "Handling method");
|
||||
|
||||
match method {
|
||||
Method::ExchangeDeclare { .. } => amqp_todo!(),
|
||||
Method::ExchangeDeclareOk => amqp_todo!(),
|
||||
Method::ExchangeDelete { .. } => amqp_todo!(),
|
||||
Method::ExchangeDeleteOk => amqp_todo!(),
|
||||
Method::QueueDeclare {
|
||||
queue,
|
||||
passive,
|
||||
durable,
|
||||
exclusive,
|
||||
auto_delete,
|
||||
no_wait,
|
||||
arguments,
|
||||
..
|
||||
} => {
|
||||
queue::declare(
|
||||
channel_handle,
|
||||
queue,
|
||||
passive,
|
||||
durable,
|
||||
exclusive,
|
||||
auto_delete,
|
||||
no_wait,
|
||||
arguments,
|
||||
)
|
||||
.await
|
||||
}
|
||||
Method::QueueDeclareOk { .. } => amqp_todo!(),
|
||||
Method::QueueBind {
|
||||
queue,
|
||||
exchange,
|
||||
routing_key,
|
||||
no_wait,
|
||||
arguments,
|
||||
..
|
||||
} => {
|
||||
queue::bind(
|
||||
channel_handle,
|
||||
queue,
|
||||
exchange,
|
||||
routing_key,
|
||||
no_wait,
|
||||
arguments,
|
||||
)
|
||||
.await
|
||||
}
|
||||
Method::QueueBindOk => amqp_todo!(),
|
||||
Method::QueueUnbind { .. } => amqp_todo!(),
|
||||
Method::QueueUnbindOk => amqp_todo!(),
|
||||
Method::QueuePurge { .. } => amqp_todo!(),
|
||||
Method::QueuePurgeOk { .. } => amqp_todo!(),
|
||||
Method::QueueDelete { .. } => amqp_todo!(),
|
||||
Method::QueueDeleteOk { .. } => amqp_todo!(),
|
||||
Method::BasicQos { .. } => amqp_todo!(),
|
||||
Method::BasicQosOk => amqp_todo!(),
|
||||
Method::BasicConsume {
|
||||
queue,
|
||||
consumer_tag,
|
||||
no_local,
|
||||
no_ack,
|
||||
exclusive,
|
||||
no_wait,
|
||||
arguments,
|
||||
..
|
||||
} => {
|
||||
consume::consume(
|
||||
channel_handle,
|
||||
queue,
|
||||
consumer_tag,
|
||||
no_local,
|
||||
no_ack,
|
||||
exclusive,
|
||||
no_wait,
|
||||
arguments,
|
||||
)
|
||||
.await
|
||||
}
|
||||
Method::BasicConsumeOk { .. } => amqp_todo!(),
|
||||
Method::BasicCancel { .. } => amqp_todo!(),
|
||||
Method::BasicCancelOk { .. } => amqp_todo!(),
|
||||
Method::BasicReturn { .. } => amqp_todo!(),
|
||||
Method::BasicDeliver { .. } => amqp_todo!(),
|
||||
Method::BasicGet { .. } => amqp_todo!(),
|
||||
Method::BasicGetOk { .. } => amqp_todo!(),
|
||||
Method::BasicGetEmpty { .. } => amqp_todo!(),
|
||||
Method::BasicAck { .. } => amqp_todo!(),
|
||||
Method::BasicReject { .. } => amqp_todo!(),
|
||||
Method::BasicRecoverAsync { .. } => amqp_todo!(),
|
||||
Method::BasicRecover { .. } => amqp_todo!(),
|
||||
Method::BasicRecoverOk => amqp_todo!(),
|
||||
Method::TxSelect
|
||||
| Method::TxSelectOk
|
||||
| Method::TxCommit
|
||||
| Method::TxCommitOk
|
||||
| Method::TxRollback
|
||||
| Method::TxRollbackOk => amqp_todo!(),
|
||||
Method::BasicPublish { .. } => {
|
||||
unreachable!("Basic.Publish is handled somewhere else because it has a body")
|
||||
}
|
||||
_ => unreachable!("Method handled by transport layer"),
|
||||
}
|
||||
}
|
||||
80
amqp_messaging/src/methods/queue.rs
Normal file
80
amqp_messaging/src/methods/queue.rs
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
#![deny(clippy::future_not_send)]
|
||||
|
||||
use amqp_core::error::{ConException, ProtocolError};
|
||||
use amqp_core::methods::{Bit, ExchangeName, NoWait, QueueName, Shortstr, Table};
|
||||
use amqp_core::queue::{QueueDeletion, RawQueue};
|
||||
use amqp_core::ChannelHandle;
|
||||
use amqp_core::{amqp_todo, GlobalData};
|
||||
use parking_lot::Mutex;
|
||||
use std::sync::atomic::AtomicUsize;
|
||||
use std::sync::Arc;
|
||||
use uuid::Uuid;
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub async fn declare(
|
||||
channel_handle: ChannelHandle,
|
||||
queue_name: QueueName,
|
||||
passive: Bit,
|
||||
durable: Bit,
|
||||
exclusive: Bit,
|
||||
auto_delete: Bit,
|
||||
no_wait: NoWait,
|
||||
arguments: Table,
|
||||
) -> Result<(), ProtocolError> {
|
||||
if !arguments.is_empty() {
|
||||
return Err(ConException::Todo.into());
|
||||
}
|
||||
|
||||
let (global_data, id) = {
|
||||
let channel = channel_handle.lock();
|
||||
|
||||
if passive || no_wait {
|
||||
amqp_todo!();
|
||||
}
|
||||
|
||||
let id = amqp_core::gen_uuid();
|
||||
let queue = Arc::new(RawQueue {
|
||||
id,
|
||||
name: queue_name.clone(),
|
||||
messages: Mutex::default(),
|
||||
durable,
|
||||
exclusive: exclusive.then(|| channel.id),
|
||||
deletion: if auto_delete {
|
||||
QueueDeletion::Auto(AtomicUsize::default())
|
||||
} else {
|
||||
QueueDeletion::Manual
|
||||
},
|
||||
});
|
||||
|
||||
let global_data = channel.global_data.clone();
|
||||
|
||||
{
|
||||
let mut global_data_lock = global_data.lock();
|
||||
global_data_lock.queues.insert(id, queue);
|
||||
}
|
||||
|
||||
(global_data, id)
|
||||
};
|
||||
|
||||
bind_queue(global_data, id, (), queue_name).await
|
||||
}
|
||||
|
||||
pub async fn bind(
|
||||
_channel_handle: ChannelHandle,
|
||||
_queue: QueueName,
|
||||
_exchange: ExchangeName,
|
||||
_routing_key: Shortstr,
|
||||
_no_wait: NoWait,
|
||||
_arguments: Table,
|
||||
) -> Result<(), ProtocolError> {
|
||||
amqp_todo!();
|
||||
}
|
||||
|
||||
async fn bind_queue(
|
||||
_global_data: GlobalData,
|
||||
_queue: Uuid,
|
||||
_exchange: (),
|
||||
_routing_key: String,
|
||||
) -> Result<(), ProtocolError> {
|
||||
amqp_todo!();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue