-
|
Hi everyone I’m experimenting with the new Distributed Counters feature (ADR-49) and wanted to confirm whether the following is the recommended or intended usage. Here’s a minimal example: // docker run --rm -p 4222:4222 nats:latest -js
void testCounterStream() {
record RespBody(String stream, long seq, String val) {}
try (var connection = Nats.connect()) {
var jsonMapper = JsonMapper.builder().build();
var jsm = connection.jetStreamManagement();
jsm.addStream(
StreamConfiguration.builder()
.name("test-counter")
.allowMessageCounter(true)
.build()
);
var headers = new Headers();
headers.add("Nats-Incr", "+" + 10);
var natsMsg = NatsMessage.builder()
.subject("test-counter")
.headers(headers)
.build();
var respMsg = connection.request(natsMsg, Duration.ofMillis(100));
assertNotNull(respMsg)
var respBody = jsonMapper.readValue(respMsg.getData(), RespBody.class);
assertEquals("test-counter", respBody.stream);
assertEquals(1, respBody.seq);
assertEquals("10", respBody.val);
} catch (Exception e) {
fail(e);
}
}Thanks in advance |
Beta Was this translation helpful? Give feedback.
Answered by
scottf
Nov 12, 2025
Replies: 1 comment
-
|
Please look at the Orbit project: https://github.com/synadia-io/orbit.java/tree/main/counters There is a complete example here: https://github.com/synadia-io/orbit.java/blob/main/counters/src/examples/java/io/synadia/examples/CounterExample.java |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
burl21
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Please look at the Orbit project: https://github.com/synadia-io/orbit.java/tree/main/counters
There is a complete example here: https://github.com/synadia-io/orbit.java/blob/main/counters/src/examples/java/io/synadia/examples/CounterExample.java