Struct lapin::Connection
source · pub struct Connection { /* private fields */ }
Expand description
A TCP connection to the AMQP server.
To connect to the server, one of the connect
methods has to be called.
Afterwards, create a Channel
by calling create_channel
.
Also see the RabbitMQ documentation on connections.
Implementations§
source§impl Connection
impl Connection
sourcepub async fn connect(
uri: &str,
options: ConnectionProperties
) -> Result<Connection>
pub async fn connect( uri: &str, options: ConnectionProperties ) -> Result<Connection>
Connect to an AMQP Server.
The URI must be in the following format:
amqp://127.0.0.1:5672
will connect to the default virtual host/
.amqp://127.0.0.1:5672/
will connect to the virtual host""
(empty string).amqp://127.0.0.1:5672/%2f
will connect to the default virtual host/
.
Note that the virtual host has to be escaped with URL encoding.
sourcepub async fn connect_with_config(
uri: &str,
options: ConnectionProperties,
config: OwnedTLSConfig
) -> Result<Connection>
pub async fn connect_with_config( uri: &str, options: ConnectionProperties, config: OwnedTLSConfig ) -> Result<Connection>
Connect to an AMQP Server.
sourcepub async fn connect_uri(
uri: AMQPUri,
options: ConnectionProperties
) -> Result<Connection>
pub async fn connect_uri( uri: AMQPUri, options: ConnectionProperties ) -> Result<Connection>
Connect to an AMQP Server.
sourcepub async fn connect_uri_with_config(
uri: AMQPUri,
options: ConnectionProperties,
config: OwnedTLSConfig
) -> Result<Connection>
pub async fn connect_uri_with_config( uri: AMQPUri, options: ConnectionProperties, config: OwnedTLSConfig ) -> Result<Connection>
Connect to an AMQP Server
sourcepub async fn create_channel(&self) -> Result<Channel>
pub async fn create_channel(&self) -> Result<Channel>
Creates a new Channel
on this connection.
This method is only successful if the client is connected.
Otherwise, InvalidConnectionState
error is returned.
sourcepub async fn restore(
&self,
topology: TopologyDefinition
) -> Result<RestoredTopology>
pub async fn restore( &self, topology: TopologyDefinition ) -> Result<RestoredTopology>
Restore the specified topology
sourcepub fn run(self) -> Result<()>
pub fn run(self) -> Result<()>
Block current thread while the connection is still active. This is useful when you only have a consumer and nothing else keeping your application “alive”.
pub fn on_error<E: FnMut(Error) + Send + 'static>(&self, handler: E)
pub fn configuration(&self) -> &Configuration
pub fn status(&self) -> &ConnectionStatus
sourcepub async fn close(&self, reply_code: ReplyCode, reply_text: &str) -> Result<()>
pub async fn close(&self, reply_code: ReplyCode, reply_text: &str) -> Result<()>
Request a connection close.
This method is only successful if the connection is in the connected state,
otherwise an InvalidConnectionState
error is returned.
sourcepub async fn block(&self, reason: &str) -> Result<()>
pub async fn block(&self, reason: &str) -> Result<()>
Block all consumers and publishers on this connection
sourcepub async fn unblock(&self) -> Result<()>
pub async fn unblock(&self) -> Result<()>
Unblock all consumers and publishers on this connection
sourcepub async fn update_secret(&self, new_secret: &str, reason: &str) -> Result<()>
pub async fn update_secret(&self, new_secret: &str, reason: &str) -> Result<()>
Update the secret used by some authentication module such as OAuth2
pub async fn connector( uri: AMQPUri, connect: Box<dyn FnOnce(&AMQPUri) -> HandshakeResult + Send + Sync>, options: ConnectionProperties ) -> Result<Connection>
sourcepub fn topology(&self) -> TopologyDefinition
pub fn topology(&self) -> TopologyDefinition
Get the current topology
This includes exchanges, queues, bindings and consumers declared by this Connection