Crate lapin_futures_tls_internal
source ·Expand description
lapin-futures-openssl
This library offers a nice integration of openssl
with the lapin-futures
library.
It uses amq-protocol
URI parsing feature and adds the connect
and connect_cancellable
methods to AMQPUri
which will provide you with a lapin_futures::client::Client
and
optionally a lapin_futures::client::HeartbeatHandle
wrapped in a Future
.
It autodetects whether you’re using amqp
or amqps
and opens either a raw TcpStream
or a TlsStream
.
Connecting and opening a channel
extern crate env_logger;
extern crate futures;
extern crate lapin_futures_tls_internal;
extern crate native_tls;
extern crate tokio;
extern crate tokio_tls;
use lapin_futures_tls_internal::{error, lapin};
use futures::future::Future;
use lapin::channel::ConfirmSelectOptions;
use lapin_futures_tls_internal::AMQPConnectionTlsExt;
use tokio_tls::TlsConnector;
use std::io;
fn main() {
env_logger::init();
tokio::run(
"amqps://user:pass@host/vhost?heartbeat=10".connect_cancellable(|err| {
eprintln!("heartbeat error: {:?}", err);
}, |host, stream| {
Box::new(futures::future::result(native_tls::TlsConnector::builder().build().map_err(|_| io::Error::new(io::ErrorKind::Other, "Failed to create connector"))).and_then(move |connector| {
TlsConnector::from(connector).connect(&host, stream).map_err(|_| io::Error::new(io::ErrorKind::Other, "Failed to connect")).map(Box::new)
}))
}).and_then(|(client, heartbeat_handle)| {
println!("Connected!");
client.create_confirm_channel(ConfirmSelectOptions::default()).map(|channel| (channel, heartbeat_handle)).and_then(|(channel, heartbeat_handle)| {
println!("Stopping heartbeat.");
heartbeat_handle.stop();
println!("Closing channel.");
channel.close(200, "Bye")
}).map_err(|e| error::ErrorKind::ProtocolError(e).into())
}).map_err(|err| {
eprintln!("amqp error: {:?}", err);
})
);
}
Modules
The type errors that can be returned in this crate.
Reexport of the
lapin_futures
crateReexport of the
uri
module from the amq_protocol
crateStructs
Reexport of
TcpStream
An I/O object representing a TCP stream connected to a remote endpoint.Enums
Represents either a raw
TcpStream
or a TlsStream
.
The TlsStream
is wrapped in a Box
to keep the enum footprint minimal.Traits
Add a connect method providing a
lapin_futures::client::Client
wrapped in a Future
.