Struct pubnub_hyper::core::PubNub
source · [−]pub struct PubNub<TTransport, TRuntime> where
TTransport: Transport,
TRuntime: Runtime, { /* private fields */ }
Expand description
PubNub Client
The PubNub lib implements socket pools to relay data requests as a client connection to the PubNub Network.
Implementations
sourceimpl<TTransport, TRuntime> PubNub<TTransport, TRuntime> where
TTransport: 'static + Transport,
TRuntime: 'static + Runtime,
impl<TTransport, TRuntime> PubNub<TTransport, TRuntime> where
TTransport: 'static + Transport,
TRuntime: 'static + Runtime,
sourcepub async fn subscribe_to_presence(
&mut self,
channel: Name
) -> Subscription<TRuntime>
pub async fn subscribe_to_presence(
&mut self,
channel: Name
) -> Subscription<TRuntime>
Subscribe to presence events for the specified channel.
This is just a tiny wrapper that calls PubNub::subscribe
internally with the specified channel name with a -pnpres
suffix.
sourceimpl<TTransport, TRuntime> PubNub<TTransport, TRuntime> where
TTransport: 'static + Transport,
TRuntime: 'static + Runtime,
impl<TTransport, TRuntime> PubNub<TTransport, TRuntime> where
TTransport: 'static + Transport,
TRuntime: 'static + Runtime,
sourcepub async fn publish(
&self,
channel: Name,
message: JsonValue
) -> Result<Timetoken, <TTransport as Transport>::Error>
pub async fn publish(
&self,
channel: Name,
message: JsonValue
) -> Result<Timetoken, <TTransport as Transport>::Error>
Publish a message over the PubNub network.
Errors
Returns transport-specific errors.
Example
use pubnub_core::{data::channel, json::object, Builder};
let pubnub = Builder::with_components(transport, runtime).build();
let channel_name: channel::Name = "my-channel".parse().unwrap();
let timetoken = pubnub
.publish(
channel_name,
object! {
"username" => "JoeBob",
"content" => "Hello, world!",
},
)
.await?;
println!("Timetoken: {}", timetoken);
sourcepub async fn publish_with_metadata(
&self,
channel: Name,
message: JsonValue,
metadata: JsonValue
) -> Result<Timetoken, <TTransport as Transport>::Error>
pub async fn publish_with_metadata(
&self,
channel: Name,
message: JsonValue,
metadata: JsonValue
) -> Result<Timetoken, <TTransport as Transport>::Error>
Publish a message over the PubNub network with an extra metadata payload.
Errors
Returns transport-specific errors.
Example
use pubnub_core::{data::channel, json::object, Builder};
let pubnub = Builder::with_components(transport, runtime).build();
let message = object! {
"username" => "JoeBob",
"content" => "Hello, world!",
};
let metadata = object! {
"uuid" => "JoeBob",
};
let channel_name: channel::Name = "my-channel".parse().unwrap();
let timetoken = pubnub
.publish_with_metadata(channel_name, message, metadata)
.await?;
println!("Timetoken: {}", timetoken);
sourceimpl<TTransport, TRuntime> PubNub<TTransport, TRuntime> where
TTransport: 'static + Transport,
TRuntime: 'static + Runtime,
impl<TTransport, TRuntime> PubNub<TTransport, TRuntime> where
TTransport: 'static + Transport,
TRuntime: 'static + Runtime,
sourcepub async fn subscribe(&mut self, channel: Name) -> Subscription<TRuntime>
pub async fn subscribe(&mut self, channel: Name) -> Subscription<TRuntime>
Subscribe to a message stream over the PubNub network.
The PubNub client only maintains a single subscribe loop for all subscription streams. This has a benefit that it optimizes for a low number of sockets to the PubNub network. It has a downside that requires all streams to consume faster than the subscribe loop produces. A slow consumer will create a head-of-line blocking bottleneck in the processing of received messages. All streams can only consume as fast as the slowest.
For example, with 3 total subscription streams and 1 that takes 30 seconds to process each message; the other 2 streams will be blocked waiting for that 30-second duration on the slow consumer.
Example
use futures_util::stream::StreamExt;
use pubnub_core::{data::channel, json::object, Builder};
let mut pubnub = Builder::with_components(transport, runtime).build();
let channel_name: channel::Name = "my-channel".parse().unwrap();
let mut stream = pubnub.subscribe(channel_name).await;
while let Some(message) = stream.next().await {
println!("Received message: {:?}", message);
}
sourceimpl<TTransport, TRuntime> PubNub<TTransport, TRuntime> where
TTransport: 'static + Transport,
TRuntime: 'static + Runtime,
impl<TTransport, TRuntime> PubNub<TTransport, TRuntime> where
TTransport: 'static + Transport,
TRuntime: 'static + Runtime,
Trait Implementations
Auto Trait Implementations
impl<TTransport, TRuntime> !RefUnwindSafe for PubNub<TTransport, TRuntime>
impl<TTransport, TRuntime> Send for PubNub<TTransport, TRuntime>
impl<TTransport, TRuntime> Sync for PubNub<TTransport, TRuntime>
impl<TTransport, TRuntime> Unpin for PubNub<TTransport, TRuntime> where
TTransport: Unpin,
impl<TTransport, TRuntime> !UnwindSafe for PubNub<TTransport, TRuntime>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more