generated from acid-info/logos-sites-content-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
25c71cf
commit a060043
Showing
6 changed files
with
70 additions
and
6 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 |
---|---|---|
|
@@ -71,6 +71,7 @@ | |
"letsencrypt", | ||
"lightpushnode", | ||
"filternode", | ||
"instanceof", | ||
], | ||
"flagWords": [], | ||
"ignorePaths": [ | ||
|
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,12 @@ | ||
```mermaid | ||
graph TD | ||
A[Start Monitoring Filter Subscriptions] --> B{Check Peer Connection} | ||
B -- Connected --> C[Send Ping] | ||
C --> D{Ping Success?} | ||
D -- Yes --> B | ||
D -- No --> E[Handle Error/Reinitiate Subscription] | ||
B -- Disconnected --> F[Check Intentional Disconnection/Unsubscription] | ||
F -- Yes --> G[Stop Monitoring] | ||
F -- No --> B | ||
E --> B | ||
``` |
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
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
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
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,5 +1,56 @@ | ||
--- | ||
title: Manage Your Filter Subscription | ||
title: Manage Your Filter Subscriptions | ||
--- | ||
|
||
This guide provides detailed steps to manage [filter subscriptions](/overview/concepts/protocols#filter) and handle node disconnections in your application. Have a look at the [Filter guide](/guides/js-waku/light-send-receive) for receiving messages with the `Filter protocol`. | ||
This guide provides detailed steps to manage [Filter](/overview/concepts/protocols#filter) subscriptions and handle node disconnections in your application. Have a look at the [Filter guide](/guides/js-waku/light-send-receive) for receiving messages with the `Light Push and Filter protocol`. | ||
|
||
## Overview | ||
|
||
Occasionally, your `Filter` subscriptions might disconnect from the Waku Network, resulting in messages not being received by your application. To manage your subscriptions, periodically ping peers to check for an active connection. The error message `"peer has no subscriptions"` indicates a failed ping due to disconnection. You can stop the pings if the disconnection/unsubscription is deliberate. | ||
|
||
```mdx-code-block | ||
import FilterPingFlow from "@site/diagrams/_filter-ping-flow.md"; | ||
<FilterPingFlow /> | ||
``` | ||
|
||
## Pinging Filter Subscriptions | ||
|
||
The `@waku/sdk` package provides a `Filter.ping()` function to ping subscriptions and check for an active connection. To begin, create a `Filter` subscription: | ||
|
||
```js | ||
// Create a Filter subscription | ||
const subscription = await node.filter.createSubscription(); | ||
|
||
// Subscribe to content topics and process new messages | ||
await subscription.subscribe([decoder], callback); | ||
``` | ||
|
||
Next, create a function to ping and reinitiate the subscription: | ||
|
||
```js | ||
const pingAndReinitiateSubscription = async () => { | ||
try { | ||
// Ping the subscription | ||
await subscription.ping(); | ||
} catch (error) { | ||
if ( | ||
// Check if the error message includes "peer has no subscriptions" | ||
error instanceof Error && | ||
error.message.includes("peer has no subscriptions") | ||
) { | ||
// Reinitiate the subscription if the ping fails | ||
await subscription.subscribe([decoder], callback); | ||
} else { | ||
throw error; | ||
} | ||
} | ||
}; | ||
|
||
// Periodically ping the subscription | ||
await pingAndReinitiateSubscription(); | ||
``` | ||
|
||
:::success Congratulations! | ||
You have successfully managed your `Filter` subscriptions to handle node disconnections in your application. | ||
::: |