Struct lapin_async::connection::Connection
source · pub struct Connection {Show 14 fields
pub state: ConnectionState,
pub channels: HashMap<u16, Channel>,
pub configuration: Configuration,
pub vhost: String,
pub channel_index: u16,
pub channel_id_lock: Arc<Mutex<()>>,
pub prefetch_size: u32,
pub prefetch_count: u16,
pub frame_queue: VecDeque<AMQPFrame>,
pub request_index: RequestId,
pub finished_reqs: HashMap<RequestId, bool>,
pub finished_get_reqs: HashMap<RequestId, bool>,
pub generated_names: HashMap<RequestId, String>,
pub credentials: Option<Credentials>,
}
Fields
state: ConnectionState
current state of the connection. In normal use it should always be ConnectionState::Connected
channels: HashMap<u16, Channel>
configuration: Configuration
vhost: String
channel_index: u16
channel_id_lock: Arc<Mutex<()>>
prefetch_size: u32
prefetch_count: u16
frame_queue: VecDeque<AMQPFrame>
list of message to send
request_index: RequestId
next request id
finished_reqs: HashMap<RequestId, bool>
list of finished requests value is true if the request returned something or false otherwise
finished_get_reqs: HashMap<RequestId, bool>
list of finished basic get requests value is true if the request returned something or false otherwise
generated_names: HashMap<RequestId, String>
list of generated names (e.g. when supplying empty string for consumer tag or queue name)
credentials: Option<Credentials>
credentials are stored in an option to remove them from memory once they are used
Implementations
sourceimpl Connection
impl Connection
sourcepub fn run<T>(
&mut self,
stream: &mut T,
send_buffer: &mut Buffer,
receive_buffer: &mut Buffer
) -> Result<ConnectionState>where
T: Read + Write,
pub fn run<T>(
&mut self,
stream: &mut T,
send_buffer: &mut Buffer,
receive_buffer: &mut Buffer
) -> Result<ConnectionState>where
T: Read + Write,
helper function to handle reading and writing repeatedly from the network until there’s no more state to update
sourcepub fn can_write(&self, send_buffer: &Buffer) -> bool
pub fn can_write(&self, send_buffer: &Buffer) -> bool
tests whether we can write to the send buffer
sourcepub fn can_read(&self, receive_buffer: &Buffer) -> bool
pub fn can_read(&self, receive_buffer: &Buffer) -> bool
tests whether we can read from the receive buffer
sourcepub fn can_parse(&self, receive_buffer: &Buffer) -> bool
pub fn can_parse(&self, receive_buffer: &Buffer) -> bool
tests whether we can parse data from the receive buffer
sourcepub fn write_to_stream(
&mut self,
writer: &mut dyn Write,
send_buffer: &mut Buffer
) -> Result<(usize, ConnectionState)>
pub fn write_to_stream(
&mut self,
writer: &mut dyn Write,
send_buffer: &mut Buffer
) -> Result<(usize, ConnectionState)>
serializes frames to the send buffer then to the writer (if possible)
sourcepub fn read_from_stream(
&mut self,
reader: &mut dyn Read,
receive_buffer: &mut Buffer
) -> Result<(usize, ConnectionState)>
pub fn read_from_stream(
&mut self,
reader: &mut dyn Read,
receive_buffer: &mut Buffer
) -> Result<(usize, ConnectionState)>
read data from the network into the receive buffer
sourceimpl Connection
impl Connection
sourcepub fn new() -> Connection
pub fn new() -> Connection
creates a Connection
object in initial state
pub fn set_credentials(&mut self, username: &str, password: &str)
pub fn set_vhost(&mut self, vhost: &str)
pub fn set_heartbeat(&mut self, heartbeat: u16)
pub fn set_channel_max(&mut self, channel_max: u16)
pub fn set_frame_max(&mut self, frame_max: u32)
sourcepub fn create_channel(&mut self) -> Option<u16>
pub fn create_channel(&mut self) -> Option<u16>
creates a Channel
object in initial state
returns a u16
channel id
The channel will not be usable until channel_open
is called with the channel id
pub fn set_channel_state(&mut self, channel_id: u16, new_state: ChannelState)
sourcepub fn check_state(
&self,
channel_id: u16,
state: ChannelState
) -> Result<(), Error>
pub fn check_state(
&self,
channel_id: u16,
state: ChannelState
) -> Result<(), Error>
verifies if the channel’s state is the one passed as argument
returns a Option of the result. None in the case the channel does not exists
sourcepub fn get_state(&self, channel_id: u16) -> Option<ChannelState>
pub fn get_state(&self, channel_id: u16) -> Option<ChannelState>
returns the channel’s state
returns a Option of the state. Non in the case the channel does not exists
sourcepub fn is_connected(&self, channel_id: u16) -> bool
pub fn is_connected(&self, channel_id: u16) -> bool
verifies if the channel is connecyed
sourcepub fn get_generated_name(&mut self, id: RequestId) -> Option<String>
pub fn get_generated_name(&mut self, id: RequestId) -> Option<String>
Get the name generated by the server for a given RequestId
this method can only be called once per request id, as it will be removed from the list afterwards
sourcepub fn is_finished(&mut self, id: RequestId) -> Option<bool>
pub fn is_finished(&mut self, id: RequestId) -> Option<bool>
verifies if the request identified with the RequestId
is finished
this method can only be called once per request id, as it will be removed from the list afterwards
sourcepub fn finished_get_result(&mut self, id: RequestId) -> Option<bool>
pub fn finished_get_result(&mut self, id: RequestId) -> Option<bool>
verifies if the get request identified with the RequestId
is finished
this method can only be called once per request id, as it will be removed from the list afterwards
sourcepub fn next_basic_get_message(
&mut self,
channel_id: u16,
queue_name: &str
) -> Option<BasicGetMessage>
pub fn next_basic_get_message(
&mut self,
channel_id: u16,
queue_name: &str
) -> Option<BasicGetMessage>
gets the next message corresponding to a channel and queue, in response to a basic.get
if the channel id and queue have no link, the method will return None. If there is no message, the method will return None
sourcepub fn connect(&mut self) -> Result<ConnectionState>
pub fn connect(&mut self) -> Result<ConnectionState>
starts the process of connecting to the server
this will set up the state machine and generates the required messages.
The messages will not be sent until calls to serialize
to write the messages to a buffer, or calls to next_frame
to obtain the next message to send
sourcepub fn next_frame(&mut self) -> Option<AMQPFrame>
pub fn next_frame(&mut self) -> Option<AMQPFrame>
next message to send to the network
returns None if there’s no message to send
sourcepub fn serialize(
&mut self,
send_buffer: &mut [u8]
) -> Result<(usize, ConnectionState)>
pub fn serialize(
&mut self,
send_buffer: &mut [u8]
) -> Result<(usize, ConnectionState)>
writes the next message to a mutable byte slice
returns how many bytes were written and the current state. this method can be called repeatedly until the buffer is full or there are no more frames to send
sourcepub fn parse(&mut self, data: &[u8]) -> Result<(usize, ConnectionState)>
pub fn parse(&mut self, data: &[u8]) -> Result<(usize, ConnectionState)>
parses a frame from a byte slice
returns how many bytes were consumed and the current state.
This method will update the state machine according to the ReceivedStart
frame with handle_frame
sourcepub fn handle_frame(&mut self, f: AMQPFrame) -> Result<(), Error>
pub fn handle_frame(&mut self, f: AMQPFrame) -> Result<(), Error>
updates the current state with a new received frame
sourcepub fn send_content_frames(
&mut self,
channel_id: u16,
class_id: u16,
slice: &[u8],
properties: BasicProperties
)
pub fn send_content_frames(
&mut self,
channel_id: u16,
class_id: u16,
slice: &[u8],
properties: BasicProperties
)
generates the content header and content frames for a payload
the frames will be stored in the frame queue until they’re written to the network.