[][src]Struct pubnub_core::PubNub

pub struct PubNub<TTransport, TRuntime> where
    TTransport: Transport,
    TRuntime: Runtime
{ /* fields omitted */ }

PubNub Client

The PubNub lib implements socket pools to relay data requests as a client connection to the PubNub Network.

Methods

impl<TTransport, TRuntime> PubNub<TTransport, TRuntime> where
    TTransport: Transport + 'static,
    TRuntime: Runtime + 'static, 
[src]

pub async fn publish<'_>(
    &'_ self,
    channel: Name,
    message: Object
) -> Result<Timetoken, <TTransport as Transport>::Error>
[src]

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

pub async fn publish_with_metadata<'_>(
    &'_ self,
    channel: Name,
    message: Object,
    metadata: Object
) -> Result<Timetoken, <TTransport as Transport>::Error>
[src]

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

impl<TTransport, TRuntime> PubNub<TTransport, TRuntime> where
    TTransport: Transport + 'static,
    TRuntime: Runtime + 'static, 
[src]

pub async fn subscribe<'_>(
    &'_ mut self,
    channel: Name
) -> Subscription<TRuntime>
[src]

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

impl<TTransport, TRuntime> PubNub<TTransport, TRuntime> where
    TTransport: Transport + 'static,
    TRuntime: Runtime + 'static, 
[src]

pub fn transport(&self) -> &TTransport[src]

Get a reference to a transport being used.

pub fn runtime(&self) -> &TRuntime[src]

Get a reference to a runtime being used.

impl<TTransport, TRuntime> PubNub<TTransport, TRuntime> where
    TTransport: Transport + 'static,
    TRuntime: Runtime + 'static, 
[src]

pub async fn call<'_, TRequest>(
    &'_ self,
    req: TRequest
) -> Result<<TTransport as Service<TRequest>>::Response, <TTransport as Service<TRequest>>::Error> where
    TTransport: Service<TRequest>, 
[src]

Perform a transport call.

Errors

Returns transport-specific errors.

Trait Implementations

impl<TTransport: Clone, TRuntime: Clone> Clone for PubNub<TTransport, TRuntime> where
    TTransport: Transport,
    TRuntime: Runtime
[src]

impl<TTransport: Debug, TRuntime: Debug> Debug for PubNub<TTransport, TRuntime> where
    TTransport: Transport,
    TRuntime: Runtime
[src]

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

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Any for T where
    T: Any + ?Sized

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,