-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from niklasad1/chore-release-v0.2
chore: release v0.2.0
- Loading branch information
Showing
2 changed files
with
69 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Changelog | ||
|
||
The format is based on [Keep a Changelog]. | ||
|
||
[Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ | ||
|
||
## [v0.2.0] - 2023-01-24 | ||
|
||
This release reworks the APIs a little bit and the major changes are: | ||
- The subscription emits an error `DisconnectWillReconnect` once | ||
a reconnection attempt occurs. It also contains the reason why it | ||
was closed. | ||
- Add API to subscribe to reconnections. | ||
- Expose low-level APIs for subscriptions and requests. | ||
- Upgrade jsonrpsee to v0.21. | ||
- Rename `Client::retry_count` to `Client::reconnect_count`. | ||
- Minor documentation tweaks. | ||
- Modify the WebSocket ping/pong API. | ||
|
||
## [v0.1.0] - 2022-01-04 | ||
|
||
Initial release of the crate. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,56 @@ | ||
# reconnecting-jsonrpsee-ws-client | ||
|
||
Wrapper crate over the jsonrpsee ws client which automatically reconnects under the hood | ||
without that the user has to restart it manually by re-transmitting pending calls | ||
and re-establish subscriptions that where closed when the connection was terminated. | ||
Wrapper crate over the jsonrpsee ws client, which automatically reconnects | ||
under the hood; without that, the user has to restart it manually by | ||
re-transmitting pending calls and re-establish subscriptions that | ||
were closed when the connection was terminated. | ||
|
||
This is crate is temporary fix for subxt because it's not easy to implement | ||
reconnect-logic on-top of it the moment. | ||
The tricky part is subscription, which may lose a few notifications, | ||
then re-connect where it's not possible to know which ones. | ||
|
||
The tricky part is subscription which may loose a few notifications then re-connecting | ||
where it's not possible to know which ones. | ||
Lost subscription notifications may be very important to know in some scenarios then | ||
this crate is not recommended. | ||
Lost subscription notifications may be very important to know in some cases, | ||
and then this library is not recommended to use. | ||
|
||
## Example | ||
|
||
```rust | ||
let client = Client::builder().build(addr).await.unwrap(); | ||
let mut sub = client.subscribe("sub".to_string(), rpc_params![], "unsub".to_string()).await.unwrap(); | ||
let msg = sub.next().await.unwrap(); | ||
use reconnecting_jsonrpsee_ws_client::{rpc_params, Client, ExponentialBackoff, PingConfig}; | ||
use std::time::Duration; | ||
|
||
async fn run() { | ||
// Create a new client with with a reconnecting RPC client. | ||
let client = Client::builder() | ||
// Reconnect with exponential backoff. | ||
.retry_policy(ExponentialBackoff::from_millis(100)) | ||
// Send period WebSocket pings/pongs every 6th second and | ||
// if ACK:ed in 30 seconds then disconnect. | ||
// | ||
// This is just a way to ensure that the connection isn't | ||
// idle if no message is sent that often | ||
.enable_ws_ping( | ||
PingConfig::new() | ||
.ping_interval(Duration::from_secs(6)) | ||
.inactive_limit(Duration::from_secs(30)), | ||
) | ||
.build("ws://localhost:9944".to_string()) | ||
.await | ||
.unwrap(); | ||
|
||
// make a JSON-RPC call | ||
let json = client | ||
.request("say_hello".to_string(), rpc_params![]) | ||
.await | ||
.unwrap(); | ||
|
||
// make JSON-RPC subscription. | ||
let mut sub = client | ||
.subscribe( | ||
"subscribe_lo".to_string(), | ||
rpc_params![], | ||
"unsubscribe_lo".to_string(), | ||
) | ||
.await | ||
.unwrap(); | ||
let notif = sub.next().await.unwrap(); | ||
} | ||
``` |