Skip to content

Commit

Permalink
PubNub SDK 0.6.0 release.
Browse files Browse the repository at this point in the history
  • Loading branch information
pubnub-release-bot committed Feb 7, 2024
1 parent 03b5201 commit 02af595
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 19 deletions.
19 changes: 18 additions & 1 deletion .pubnub.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pubnub"
version = "0.5.0"
version = "0.6.0"
edition = "2021"
license-file = "LICENSE"
authors = ["PubNub <support@pubnub.com>"]
Expand Down
56 changes: 44 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,32 @@ 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

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<dyn std::error::Error>> {
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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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::<String>(&utf8_message) {
println!("message: {}", cleaned);
}
}
}),
);

sleep(Duration::from_secs(2)).await;

// Send a message to the channel
client
.publish_message("hello world!")
Expand All @@ -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(())
}
Expand All @@ -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
Expand Down Expand Up @@ -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"] }
```

Expand Down
10 changes: 5 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"] }
//! ```
//!
Expand Down

0 comments on commit 02af595

Please sign in to comment.