From 02af595f1427d0f991a553c6d2d7a5b3d4766bb5 Mon Sep 17 00:00:00 2001 From: PubNub Release Bot <120067856+pubnub-release-bot@users.noreply.github.com> Date: Wed, 7 Feb 2024 15:23:04 +0000 Subject: [PATCH 1/2] PubNub SDK 0.6.0 release. --- .pubnub.yml | 19 +++++++++++++++++- Cargo.toml | 2 +- README.md | 56 +++++++++++++++++++++++++++++++++++++++++------------ src/lib.rs | 10 +++++----- 4 files changed, 68 insertions(+), 19 deletions(-) diff --git a/.pubnub.yml b/.pubnub.yml index da0930e9..0563e2f6 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,9 +1,26 @@ name: rust -version: 0.5.0 +version: 0.6.0 schema: 1 scm: github.com/pubnub/rust files: [] changelog: + - date: 2024-02-07 + version: 0.6.0 + changes: + - type: feature + text: "Make it possible to create `SubscriptionCursor` from the string slice." + - type: feature + text: "Add `add_subscriptions(..)` and `sub_subscriptions(..)` to `SubscriptionSet` to make it possible in addition to sets manipulation use list of subscriptions." + - type: bug + text: "Fix issue because of which `cursor` is not reset on `Subscription` and `SubscriptionSet` on unsubscribe." + - type: bug + text: "Fix issue because of which cancelled effects still asynchronously spawned for processing." + - type: improvement + text: "Change `client` to `pubnub` in inline docs." + - type: improvement + text: "Add subscription token validation." + - type: improvement + text: "Added a method to validate the provided subscription token to conform to PubNub time token requirements with precision. Separate `subscribe` example into two to show separately `subscribe` feature and `presence state` maintenance with subscribe." - date: 2024-01-25 version: 0.5.0 changes: diff --git a/Cargo.toml b/Cargo.toml index 36d95088..7739d7ca 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pubnub" -version = "0.5.0" +version = "0.6.0" edition = "2021" license-file = "LICENSE" authors = ["PubNub "] diff --git a/README.md b/README.md index 51ede15b..c125e259 100644 --- a/README.md +++ b/README.md @@ -36,11 +36,11 @@ Add `pubnub` to your Rust project in the `Cargo.toml` file: ```toml # default features [dependencies] -pubnub = "0.5.0" +pubnub = "0.6.0" # all features [dependencies] -pubnub = { version = "0.5.0", features = ["full"] } +pubnub = { version = "0.6.0", features = ["full"] } ``` ### Example @@ -48,17 +48,20 @@ pubnub = { version = "0.5.0", features = ["full"] } Try the following sample code to get up and running quickly! ```rust -use pubnub::{Keyset, PubNubClientBuilder}; -use pubnub::dx::subscribe::{SubscribeStreamEvent, Update}; +use pubnub::subscribe::Subscriber; use futures::StreamExt; use tokio::time::sleep; use std::time::Duration; use serde_json; - +use pubnub::{ + dx::subscribe::Update, + subscribe::EventSubscriber, + Keyset, PubNubClientBuilder, +}; #[tokio::main] async fn main() -> Result<(), Box> { use pubnub::subscribe::{EventEmitter, SubscriptionParams}; -let publish_key = "my_publish_key"; + let publish_key = "my_publish_key"; let subscribe_key = "my_subscribe_key"; let client = PubNubClientBuilder::with_reqwest_transport() .with_keyset(Keyset { @@ -68,6 +71,7 @@ let publish_key = "my_publish_key"; }) .with_user_id("user_id") .build()?; + println!("PubNub instance created"); let subscription = client.subscription(SubscriptionParams { @@ -76,7 +80,13 @@ let publish_key = "my_publish_key"; options: None }); - println!("Subscribed to channel"); + let channel_entity = client.channel("my_channel_2"); + let channel_entity_subscription = channel_entity.subscription(None); + + subscription.subscribe(); + channel_entity_subscription.subscribe(); + + println!("Subscribed to channels"); // Launch a new task to print out each received message tokio::spawn(client.status_stream().for_each(|status| async move { @@ -107,7 +117,21 @@ let publish_key = "my_publish_key"; } })); - sleep(Duration::from_secs(1)).await; + // Explicitly listen only for real-time `message` updates. + tokio::spawn( + channel_entity_subscription + .messages_stream() + .for_each(|message| async move { + if let Ok(utf8_message) = String::from_utf8(message.data.clone()) { + if let Ok(cleaned) = serde_json::from_str::(&utf8_message) { + println!("message: {}", cleaned); + } + } + }), + ); + + sleep(Duration::from_secs(2)).await; + // Send a message to the channel client .publish_message("hello world!") @@ -116,7 +140,15 @@ let publish_key = "my_publish_key"; .execute() .await?; - sleep(Duration::from_secs(10)).await; + // Send a message to another channel + client + .publish_message("hello world on the other channel!") + .channel("my_channel_2") + .r#type("text-message") + .execute() + .await?; + + sleep(Duration::from_secs(15)).await; Ok(()) } @@ -132,11 +164,11 @@ disable them in the `Cargo.toml` file, like so: ```toml # only blocking and access + default features [dependencies] -pubnub = { version = "0.5.0", features = ["blocking", "access"] } +pubnub = { version = "0.6.0", features = ["blocking", "access"] } # only parse_token + default features [dependencies] -pubnub = { version = "0.5.0", features = ["parse_token"] } +pubnub = { version = "0.6.0", features = ["parse_token"] } ``` ### Available features @@ -175,7 +207,7 @@ you need, for example: ```toml [dependencies] -pubnub = { version = "0.5.0", default-features = false, features = ["serde", "publish", +pubnub = { version = "0.6.0", default-features = false, features = ["serde", "publish", "blocking"] } ``` diff --git a/src/lib.rs b/src/lib.rs index d0d494a9..0b9a37f7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -39,11 +39,11 @@ //! ```toml //! # default features //! [dependencies] -//! pubnub = "0.5.0" +//! pubnub = "0.6.0" //! //! # all features //! [dependencies] -//! pubnub = { version = "0.5.0", features = ["full"] } +//! pubnub = { version = "0.6.0", features = ["full"] } //! ``` //! //! ### Example @@ -167,11 +167,11 @@ //! ```toml //! # only blocking and access + default features //! [dependencies] -//! pubnub = { version = "0.5.0", features = ["blocking", "access"] } +//! pubnub = { version = "0.6.0", features = ["blocking", "access"] } //! //! # only parse_token + default features //! [dependencies] -//! pubnub = { version = "0.5.0", features = ["parse_token"] } +//! pubnub = { version = "0.6.0", features = ["parse_token"] } //! ``` //! //! ### Available features @@ -210,7 +210,7 @@ //! //! ```toml //! [dependencies] -//! pubnub = { version = "0.5.0", default-features = false, features = ["serde", "publish", +//! pubnub = { version = "0.6.0", default-features = false, features = ["serde", "publish", //! "blocking"] } //! ``` //! From 4fd84c89f09159557c4472e965884b156d8e7a62 Mon Sep 17 00:00:00 2001 From: Serhii Mamontov Date: Wed, 7 Feb 2024 17:26:04 +0200 Subject: [PATCH 2/2] Update .pubnub.yml --- .pubnub.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.pubnub.yml b/.pubnub.yml index 0563e2f6..9eb1e8da 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -20,7 +20,9 @@ changelog: - type: improvement text: "Add subscription token validation." - type: improvement - text: "Added a method to validate the provided subscription token to conform to PubNub time token requirements with precision. Separate `subscribe` example into two to show separately `subscribe` feature and `presence state` maintenance with subscribe." + text: "Added a method to validate the provided subscription token to conform to PubNub time token requirements with precision." + - type: improvement + text: "Separate `subscribe` example into two to show separately `subscribe` feature and `presence state` maintenance with subscribe." - date: 2024-01-25 version: 0.5.0 changes: