mirror of
https://github.com/Noratrieb/haesli.git
synced 2026-01-14 19:55:03 +01:00
route topics
This commit is contained in:
parent
58de7f1e2d
commit
43d0ce05dc
10 changed files with 98 additions and 49 deletions
|
|
@ -10,7 +10,7 @@ haesli_datastructure = { path = "../haesli_datastructure" }
|
|||
bytes = "1.1.0"
|
||||
parking_lot = "0.12.0"
|
||||
rand = "0.8.5"
|
||||
tinyvec = { version = "1.5.1", features = ["alloc", "rustc_1_55"] }
|
||||
smallvec = { version = "1.8.0", features = ["union"] }
|
||||
thiserror = "1.0.30"
|
||||
tokio = { version = "1.17.0", features = ["sync"] }
|
||||
uuid = "0.8.2"
|
||||
|
|
|
|||
|
|
@ -7,13 +7,12 @@ use std::{
|
|||
|
||||
use bytes::Bytes;
|
||||
use parking_lot::Mutex;
|
||||
use tinyvec::TinyVec;
|
||||
use tokio::sync::mpsc;
|
||||
|
||||
use crate::{
|
||||
consumer::Consumer,
|
||||
methods::{self, Method},
|
||||
newtype_id, GlobalData, Queue,
|
||||
newtype_id, GlobalData, Queue, SingleVec,
|
||||
};
|
||||
|
||||
newtype_id!(pub ConnectionId);
|
||||
|
|
@ -67,7 +66,7 @@ pub struct ConnectionInner {
|
|||
pub enum ConnectionEvent {
|
||||
Shutdown,
|
||||
Method(ChannelNum, Box<Method>),
|
||||
MethodContent(ChannelNum, Box<Method>, ContentHeader, TinyVec<[Bytes; 1]>),
|
||||
MethodContent(ChannelNum, Box<Method>, ContentHeader, SingleVec<Bytes>),
|
||||
}
|
||||
|
||||
pub type ConEventSender = mpsc::Sender<ConnectionEvent>;
|
||||
|
|
|
|||
|
|
@ -2,6 +2,13 @@ use std::{borrow::Borrow, collections::HashMap, sync::Arc};
|
|||
|
||||
use crate::{newtype, Queue};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum TopicSegment {
|
||||
Word(String),
|
||||
SingleWildcard,
|
||||
MultiWildcard,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum ExchangeType {
|
||||
/// Routes a message to a queue if the routing-keys are equal
|
||||
|
|
@ -9,7 +16,7 @@ pub enum ExchangeType {
|
|||
/// Always routes the message to a queue
|
||||
Fanout { bindings: Vec<Queue> },
|
||||
/// Routes a message to a queue if the routing key matches the pattern
|
||||
Topic { bindings: Vec<(String, Queue)> },
|
||||
Topic { bindings: Vec<(Vec<TopicSegment>, Queue)> },
|
||||
/// Is bound with a table of headers and values, and matches if the message headers
|
||||
/// match up with the binding headers
|
||||
///
|
||||
|
|
|
|||
|
|
@ -25,6 +25,8 @@ use crate::{
|
|||
queue::{Queue, QueueName},
|
||||
};
|
||||
|
||||
pub type SingleVec<T> = smallvec::SmallVec<[T; 1]>;
|
||||
|
||||
#[derive(Clone)]
|
||||
// todo: what if this was downstream?
|
||||
pub struct GlobalData {
|
||||
|
|
|
|||
|
|
@ -1,9 +1,8 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use bytes::Bytes;
|
||||
use tinyvec::TinyVec;
|
||||
|
||||
use crate::{connection::ContentHeader, newtype_id};
|
||||
use crate::{connection::ContentHeader, newtype_id, SingleVec};
|
||||
|
||||
pub type Message = Arc<MessageInner>;
|
||||
|
||||
|
|
@ -14,7 +13,7 @@ pub struct MessageInner {
|
|||
pub id: MessageId,
|
||||
pub header: ContentHeader,
|
||||
pub routing: RoutingInformation,
|
||||
pub content: TinyVec<[Bytes; 1]>,
|
||||
pub content: SingleVec<Bytes>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue