-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start to refactor server client channel
- Loading branch information
1 parent
b96e732
commit c8425bd
Showing
12 changed files
with
292 additions
and
204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
use metalmq_codec::{ | ||
codec::Frame, | ||
frame::{self, ContentBodyFrame, ContentHeaderFrame}, | ||
}; | ||
use tokio::sync::mpsc; | ||
|
||
use crate::{queue::handler as queue_handler, ErrorScope, Result, RuntimeError}; | ||
|
||
pub mod open_close; | ||
|
||
#[derive(Debug)] | ||
pub enum ChannelError { | ||
ContentTooLarge = 311, | ||
NoRoute = 312, | ||
NoConsumers = 313, | ||
AccessRefused = 403, | ||
NotFound = 404, | ||
ResourceLocked = 405, | ||
PreconditionFailed = 406, | ||
} | ||
|
||
/// Queues consumed by the connection with Basic.Consume | ||
#[derive(Debug)] | ||
pub struct ActivelyConsumedQueue { | ||
pub queue_name: String, | ||
pub consumer_tag: String, | ||
pub queue_sink: queue_handler::QueueCommandSink, | ||
} | ||
|
||
/// Queues consumed by the connection with Basic.Get | ||
#[derive(Debug)] | ||
pub struct PassivelyConsumedQueue { | ||
pub queue_name: String, | ||
pub consumer_tag: String, | ||
pub delivery_tag: u64, | ||
pub queue_sink: queue_handler::QueueCommandSink, | ||
} | ||
|
||
#[derive(Debug, Default)] | ||
pub struct PublishedContent { | ||
pub source_connection: String, | ||
pub channel: u16, | ||
pub exchange: String, | ||
pub routing_key: String, | ||
pub mandatory: bool, | ||
pub immediate: bool, | ||
/// The method frame class id which initiated the sending of the content. | ||
pub method_frame_class_id: u32, | ||
pub content_header: ContentHeaderFrame, | ||
pub content_bodies: Vec<ContentBodyFrame>, | ||
pub body_size: usize, | ||
} | ||
|
||
/// Represents a channel | ||
#[derive(Debug)] | ||
pub struct Channel { | ||
pub number: u16, | ||
pub consumed_queue: Option<ActivelyConsumedQueue>, | ||
pub in_flight_content: Option<PublishedContent>, | ||
pub confirm_mode: bool, | ||
pub next_confirm_delivery_tag: u64, | ||
pub outgoing: mpsc::Sender<Frame>, | ||
} | ||
|
||
/// Helper to create channel error frames. | ||
pub fn channel_error<T>(channel: u16, cm: u32, code: ChannelError, text: &str) -> Result<T> { | ||
Err(Box::new(RuntimeError { | ||
scope: ErrorScope::Channel, | ||
channel, | ||
code: code as u16, | ||
text: text.to_owned(), | ||
class_method: cm, | ||
})) | ||
} | ||
|
||
pub fn runtime_error_to_frame(rte: &RuntimeError) -> Frame { | ||
let amqp_frame = match rte.scope { | ||
ErrorScope::Connection => frame::connection_close(rte.code, &rte.text, rte.class_method), | ||
ErrorScope::Channel => frame::channel_close(rte.channel, rte.code, &rte.text, rte.class_method), | ||
}; | ||
|
||
Frame::Frame(amqp_frame) | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use metalmq_codec::codec::Frame; | ||
|
||
use crate::{ErrorScope, Result, RuntimeError}; | ||
|
||
// TODO here goes the connection related business logic | ||
#[derive(Debug)] | ||
pub enum ConnectionError { | ||
ConnectionForced = 320, | ||
InvalidPath = 402, | ||
AccessRefused = 403, | ||
FrameError = 501, | ||
SyntaxError = 502, | ||
CommandInvalid = 503, | ||
ChannelError = 504, | ||
UnexpectedFrame = 505, | ||
ResourceError = 506, | ||
NotAllowed = 530, | ||
NotImplemented = 540, | ||
InternalError = 541, | ||
} | ||
|
||
/// Helper to create connection error frames. | ||
pub fn connection_error<T>(cm: u32, code: ConnectionError, text: &str) -> Result<T> { | ||
Err(Box::new(RuntimeError { | ||
scope: ErrorScope::Connection, | ||
channel: 0, | ||
code: code as u16, | ||
text: text.to_owned(), | ||
class_method: cm, | ||
})) | ||
} | ||
|
||
/// Convert ConnectionError to connection close frame. | ||
pub fn connection_error_frame(cm: u32, code: ConnectionError, text: &str) -> Frame { | ||
metalmq_codec::codec::Frame::Frame(metalmq_codec::frame::connection_close(code as u16, text, cm)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.