mirror of
https://github.com/Noratrieb/haesli.git
synced 2026-01-14 19:55:03 +01:00
improve everything
This commit is contained in:
parent
543e39f129
commit
dbc577abbc
10 changed files with 117 additions and 71 deletions
13
haesli_core/src/exchange.rs
Normal file
13
haesli_core/src/exchange.rs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
pub enum ExchangeType {
|
||||
/// Routes a message to a queue if the routing-keys are equal
|
||||
Direct,
|
||||
/// Always routes the message to a queue
|
||||
Fanout,
|
||||
/// Routes a message to a queue if the routing key matches the pattern
|
||||
Topic,
|
||||
/// Is bound with a table of headers and values, and matches if the message headers
|
||||
/// match up with the binding headers
|
||||
Headers,
|
||||
/// The message is sent to the server system service with the name of the routing-key
|
||||
System,
|
||||
}
|
||||
|
|
@ -3,6 +3,7 @@
|
|||
pub mod connection;
|
||||
pub mod consumer;
|
||||
pub mod error;
|
||||
pub mod exchange;
|
||||
mod macros;
|
||||
pub mod message;
|
||||
pub mod methods;
|
||||
|
|
|
|||
|
|
@ -3,24 +3,24 @@ macro_rules! newtype_id {
|
|||
($(#[$meta:meta])* $vis:vis $name:ident) => {
|
||||
$(#[$meta])*
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
$vis struct $name(::uuid::Uuid);
|
||||
$vis struct $name(uuid::Uuid);
|
||||
|
||||
impl $name {
|
||||
#[must_use]
|
||||
pub fn random() -> Self {
|
||||
::rand::random()
|
||||
rand::random()
|
||||
}
|
||||
}
|
||||
|
||||
impl ::std::fmt::Display for $name {
|
||||
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
|
||||
::std::fmt::Display::fmt(&self.0, f)
|
||||
impl std::fmt::Display for $name {
|
||||
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
std::fmt::Display::fmt(&self.0, f)
|
||||
}
|
||||
}
|
||||
|
||||
impl ::rand::prelude::Distribution<$name> for ::rand::distributions::Standard {
|
||||
fn sample<R: ::rand::Rng + ?Sized>(&self, rng: &mut R) -> $name {
|
||||
$name(::uuid::Uuid::from_bytes(rng.gen()))
|
||||
impl rand::prelude::Distribution<$name> for rand::distributions::Standard {
|
||||
fn sample<R: rand::Rng + ?Sized>(&self, rng: &mut R) -> $name {
|
||||
$name(uuid::Uuid::from_bytes(rng.gen()))
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
@ -58,11 +58,20 @@ macro_rules! newtype {
|
|||
Self(other.into())
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for $name
|
||||
where
|
||||
$ty: std::fmt::Display,
|
||||
{
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
std::fmt::Display::fmt(&self.0, f)
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! haesli_todo {
|
||||
macro_rules! amqp_todo {
|
||||
() => {
|
||||
return Err(::haesli_core::error::ConException::NotImplemented(concat!(
|
||||
file!(),
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use std::{
|
||||
borrow::Borrow,
|
||||
collections::HashMap,
|
||||
fmt::{Debug, Display, Formatter},
|
||||
fmt::{Debug, Formatter},
|
||||
sync::{atomic::AtomicUsize, Arc},
|
||||
};
|
||||
|
||||
|
|
@ -35,22 +35,21 @@ newtype!(
|
|||
|
||||
impl Borrow<str> for QueueName {
|
||||
fn borrow(&self) -> &str {
|
||||
std::borrow::Borrow::borrow(&self.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for QueueName {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
Display::fmt(&self.0, f)
|
||||
Borrow::borrow(&self.0)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct QueueInner {
|
||||
/// Internal ID, might actually be unused
|
||||
pub id: QueueId,
|
||||
/// The visible name of the queue
|
||||
pub name: QueueName,
|
||||
pub messages: haesli_datastructure::MessageQueue<Message>,
|
||||
/// Whether the queue should be kept when the server restarts
|
||||
pub durable: bool,
|
||||
/// To which connection the queue belongs to it will be deleted when the connection closes
|
||||
// todo: connection or channel?
|
||||
pub exclusive: Option<ChannelId>,
|
||||
/// Whether the queue will automatically be deleted when no consumers uses it anymore.
|
||||
/// The queue can always be manually deleted.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue