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

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.

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);

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);

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);
}

Get a reference to a transport being used.

Get a reference to a runtime being used.

Perform a transport call.

Errors

Returns transport-specific errors.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more