Crate pubnub_hyper
source · [−]Expand description
PubNub Hyper
A PubNub client using hyper
and tokio
to provide an
ultra-fast, incredibly reliable message transport over the PubNub edge
network.
Uses pubnub-core
under the hood.
Example
use futures_util::stream::StreamExt;
use pubnub_hyper::runtime::tokio_global::TokioGlobal;
use pubnub_hyper::transport::hyper::Hyper;
use pubnub_hyper::{core::data::channel, core::json::object, Builder};
let transport = Hyper::new()
.publish_key("demo")
.subscribe_key("demo")
.build()?;
let mut pubnub = Builder::new()
.transport(transport)
.runtime(TokioGlobal)
.build();
let message = object! {
"username" => "JoeBob",
"content" => "Hello, world!",
};
let channel_name: channel::Name = "my-channel".parse().unwrap();
let mut stream = pubnub.subscribe(channel_name.clone()).await;
let timetoken = pubnub.publish(channel_name, message.clone()).await?;
let received = stream.next().await;
assert_eq!(received.unwrap().json, message);
Re-exports
pub use crate::runtime::tokio_global::TokioGlobal as DefaultRuntime;
pub use crate::transport::hyper::Hyper as DefaultTransport;
Modules
Re-export core for ease of use.
Runtime implementations.
Tranport implementations.
Macros
Encodes JSON into a urlencoded coding.
Structs
PubNub Client Builder
Type Definitions
PubNub client bound to hyper transport and tokio runtime.