Skip to content

Commit

Permalink
docs: clarify the receiver field in DDS and utils plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
sxyazi committed Apr 2, 2024
1 parent a131443 commit 88bf032
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/dds.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ One payload per line, each payload contains the following fields separated by co
| Field | Description |
| -------- | --------------------------------------------------------------------------------------------------------------- |
| kind | The kind of this message |
| receiver | The instance ID that receives this message; if it's `0`, broadcasts to all instances |
| receiver | The remote instance ID that receives this message; if it's `0`, broadcasts to all remote instances |
| severity | The severity of this message; if it's non-zero, indicates a [static message](/docs/plugins/utils#ps.pub_static) |
| sender | The sender ID of this message |
| body | The body of this message, which is a JSON string |
Expand Down
8 changes: 4 additions & 4 deletions docs/plugins/utils.md
Original file line number Diff line number Diff line change
Expand Up @@ -331,14 +331,14 @@ Since the `kind` is used globally, to add the plugin name as the prefix is a bes
ps.pub_to(1711957283332834, "greeting", "Hello, World!")
```

Publish a message to a specific instance with `receiver` as the identifier:
Publish a message to a specific instance with `receiver` as the ID:

- If the receiver is the current instance (local), and is subscribed to this `kind` through `sub()`, it will receive this message.
- If the receiver is not the current instance (remote), and is subscribed to this `kind` through `sub_remote()`, it will receive this message.

With:

- `receiver` - Required, the identifier of the receiver, which is a integer; if it's `0` then broadcasting to all instances
- `receiver` - Required, ID of the remote instance, which is a integer; if it's `0` then broadcasting to all remote instances
- `kind` - The same as `pub()`
- `value` - The same as `pub()`

Expand All @@ -348,15 +348,15 @@ With:
ps.pub_static(10, "greeting", "Hello, World!")
```

Broadcast a static message to all instances subscribed to this `kind` through `sub_remote()`:
Broadcast a static message to all remote instances subscribed to this `kind` through `sub_remote()`:

- `severity` - Required, the severity of the message, which is an integer with a range of 1 to 255
- `kind` - The same as `pub()`
- `value` - The same as `pub()`

The message will be stored as static data to achieve state persistence, and when a new instance is created, it will receive all static messages broadcasted by `sub_remote()` before in descending order of `severity` to restore its state from the data.

If you simply want to broadcast a message to all instances without the need for the message to be persisted, use `ps.pub_to()` with receiver `0` instead.
If you simply want to broadcast a message to all remote instances, without the need for the message to be persisted, use `ps.pub_to()` with receiver `0` instead.

### `sub(kind, callback)` {#ps.sub}

Expand Down

0 comments on commit 88bf032

Please sign in to comment.