Skip to content

Commit 0ff82ac

Browse files
committed
Include the latest value in PubAck for counters
Signed-off-by: R.I.Pienaar <[email protected]>
1 parent f156468 commit 0ff82ac

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

adr/ADR-49.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ Publishing a message to such a Stream will load the most recent message on the s
3333
the new message with the latest value in the body. The header is preserved for downstream processing by Sources and for
3434
visibility and debugging purposes.
3535

36+
The `PubAck` will include the value post-increment for fast feedback, avoiding a Get to get the latest value.
37+
3638
```bash
3739
$ nats s get COUNTER --last-for counter.hits
3840
Item: COUNTER#22802062 received 2025-01-09 18:05:07.93747413 +0000 UTC on Subject counter.hits
@@ -41,7 +43,8 @@ Headers:
4143
Nats-Incr: +2
4244

4345
{"val":"100"}
44-
$ nats pub counter.hits '' -J -H "Nats-Incr:+1"
46+
$ nats req counter.hits '' -J -H "Nats-Incr:+1"
47+
{"stream":"COUNTER", "domain":"hub", "seq":22802063, "val":"101"}
4548
$ nats s get COUNTER --last-for counter.hits
4649
Item: COUNTER#22802063 received 2025-01-09 18:06:00 +0000 UTC on Subject counter.hits
4750

@@ -81,6 +84,15 @@ We use a `string` value since JavaScript would only support up to `2^53` for num
8184

8285
We use a JSON result so we can extend the structure in future, perhaps to indicate data type and more.
8386

87+
The PubAck gets a new field:
88+
89+
```go
90+
type PubAck struct {
91+
// ....
92+
Value string `json:"val,omitempty"`
93+
}
94+
```
95+
8496
## Recounts and Audit
8597

8698
It's important in many scenarios that counter values can be audited and recounts can happen. We preserve the `Nats-Incr`

0 commit comments

Comments
 (0)