Skip to content

Update redeliveryCount to deliveryCount across codebase #187

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions jetstream/src/jsapi_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,8 @@ export type ConsumerUpdateConfig = PriorityGroups & {
*/
"ack_wait"?: Nanos;
/**
* The number of times a message will be redelivered to consumers if not acknowledged in time
* The maximum number of times a message will be delivered to consumers if not acknowledged in time.
* Default is -1 (will redeliver until acknowledged).
*/
"max_deliver"?: number;
/**
Expand Down Expand Up @@ -1163,9 +1164,9 @@ export type DeliveryInfo = {
*/
consumer: string;
/**
* The number of times the message has been redelivered.
* The number of times the message has been delivered.
*/
redeliveryCount: number;
deliveryCount: number;
/**
* The sequence number of the message in the stream
*/
Expand Down
10 changes: 5 additions & 5 deletions jetstream/src/jsmsg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,17 +162,17 @@ export function parseInfo(s: string): DeliveryInfo {
}

// old
// "$JS.ACK.<stream>.<consumer>.<redeliveryCount><streamSeq><deliverySequence>.<timestamp>.<pending>"
// "$JS.ACK.<stream>.<consumer>.<deliveryCount><streamSeq><deliverySequence>.<timestamp>.<pending>"
// new
// $JS.ACK.<domain>.<accounthash>.<stream>.<consumer>.<redeliveryCount>.<streamSeq>.<deliverySequence>.<timestamp>.<pending>.<random>
// $JS.ACK.<domain>.<accounthash>.<stream>.<consumer>.<deliveryCount>.<streamSeq>.<deliverySequence>.<timestamp>.<pending>.<random>
const di = {} as DeliveryInfo;
// if domain is "_", replace with blank
di.domain = tokens[2] === "_" ? "" : tokens[2];
di.account_hash = tokens[3];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 156 and 167 should be updated too?
Also, seem like there is no .random in the end?

[15523] 2025/01/08 12:07:23.854376 [TRC] 127.0.0.1:49960 - wid:31 - <<- [PUB $JS.ACK.OCB2058BMO3S4M3H1PCXP2.OCB2058BMO3S4M3H1PDB10_1.1.98.98.1736366843626007307.2 4]   
[15523] 2025/01/08 12:07:23.854411 [TRC] 127.0.0.1:49960 - wid:31 - <<- MSG_PAYLOAD: ["+ACK"]     

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just fixed :)

di.stream = tokens[4];
di.consumer = tokens[5];
di.redeliveryCount = parseInt(tokens[6], 10);
di.redelivered = di.redeliveryCount > 1;
di.deliveryCount = parseInt(tokens[6], 10);
di.redelivered = di.deliveryCount > 1;
di.streamSequence = parseInt(tokens[7], 10);
di.deliverySequence = parseInt(tokens[8], 10);
di.timestampNanos = parseInt(tokens[9], 10);
Expand Down Expand Up @@ -216,7 +216,7 @@ export class JsMsgImpl implements JsMsg {
}

get redelivered(): boolean {
return this.info.redeliveryCount > 1;
return this.info.deliveryCount > 1;
}

get reply(): string {
Expand Down
4 changes: 2 additions & 2 deletions jetstream/tests/jetstream_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ Deno.test("jetstream - backoff", async () => {
const iter = await c.consume({
callback: (m) => {
when.push(Date.now());
if (m.info.redeliveryCount === 4) {
if (m.info.deliveryCount === 4) {
iter.stop();
}
},
Expand Down Expand Up @@ -779,7 +779,7 @@ Deno.test("jetstream - redelivery", async () => {
if (m.redelivered) {
redeliveries++;
}
if (m.info.redeliveryCount === 4) {
if (m.info.deliveryCount === 4) {
setTimeout(() => {
iter.stop();
}, 2000);
Expand Down
10 changes: 5 additions & 5 deletions jetstream/tests/jsmsg_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,18 @@ import type { JetStreamManagerImpl } from "../src/jsclient.ts";
import { errors } from "../../core/src/mod.ts";

Deno.test("jsmsg - parse", () => {
// "$JS.ACK.<stream>.<consumer>.<redeliveryCount><streamSeq><deliverySequence>.<timestamp>.<pending>"
// "$JS.ACK.<stream>.<consumer>.<deliveryCount><streamSeq><deliverySequence>.<timestamp>.<pending>"
const rs = `$JS.ACK.streamname.consumername.2.3.4.${nanos(Date.now())}.100`;
const info = parseInfo(rs);
assertEquals(info.stream, "streamname");
assertEquals(info.consumer, "consumername");
assertEquals(info.redeliveryCount, 2);
assertEquals(info.deliveryCount, 2);
assertEquals(info.streamSequence, 3);
assertEquals(info.pending, 100);
});

Deno.test("jsmsg - parse long", () => {
// $JS.ACK.<domain>.<accounthash>.<stream>.<consumer>.<redeliveryCount>.<streamSeq>.<deliverySequence>.<timestamp>.<pending>.<random>
// $JS.ACK.<domain>.<accounthash>.<stream>.<consumer>.<deliveryCount>.<streamSeq>.<deliverySequence>.<timestamp>.<pending>.<random>
const rs = `$JS.ACK.domain.account.streamname.consumername.2.3.4.${
nanos(Date.now())
}.100.rand`;
Expand All @@ -63,7 +63,7 @@ Deno.test("jsmsg - parse long", () => {
assertEquals(info.account_hash, "account");
assertEquals(info.stream, "streamname");
assertEquals(info.consumer, "consumername");
assertEquals(info.redeliveryCount, 2);
assertEquals(info.deliveryCount, 2);
assertEquals(info.streamSequence, 3);
assertEquals(info.pending, 100);
});
Expand Down Expand Up @@ -100,7 +100,7 @@ Deno.test("jsmsg - acks", async () => {
fail(err.message);
}
msg.respond(Empty, {
// "$JS.ACK.<stream>.<consumer>.<redeliveryCount><streamSeq><deliverySequence>.<timestamp>.<pending>"
// "$JS.ACK.<stream>.<consumer>.<deliveryCount><streamSeq><deliverySequence>.<timestamp>.<pending>"
reply:
`MY.TEST.streamname.consumername.1.${counter}.${counter}.${Date.now()}.0`,
});
Expand Down
32 changes: 31 additions & 1 deletion jetstream/tests/next_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ Deno.test("next - listener leaks", async () => {
const m = await consumer.next();
if (m) {
m.nak();
if (m.info?.redeliveryCount > 100) {
if (m.info?.deliveryCount > 100) {
break;
}
}
Expand Down Expand Up @@ -203,3 +203,33 @@ Deno.test("next - consumer bind", async () => {

await cleanup(ns, nc);
});

Deno.test("next - delivery count", async () => {
const { ns, nc } = await setup(jetstreamServerConf());

const jsm = await jetstreamManager(nc);
await jsm.streams.add({ name: "A", subjects: ["hello"] });

await jsm.consumers.add("A", {
durable_name: "a",
deliver_policy: DeliverPolicy.All,
ack_policy: AckPolicy.Explicit,
max_deliver: 2,
ack_wait: nanos(1000),
});

const js = jetstream(nc);
await js.publish("hello");

const c = await js.consumers.get("A", "a");
let m = await c.next();
assertEquals(m?.info.deliveryCount, 1);
await delay(1500);
m = await c.next();
await delay(1500);
assertEquals(m?.info.deliveryCount, 2);
m = await c.next({ expires: 1000 });
assertEquals(m, null);

await cleanup(ns, nc);
});
2 changes: 2 additions & 0 deletions migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ To use JetStream, you must install and import `@nats/jetstream`.
- The `ConsumerEvents` and `ConsumerDebugEvents` enum has been removed and
replaced with `ConsumerNotification` which have a discriminating field `type`.
The status objects provide a more specific API for querying those events.
- `JsMsg.info.redeliveryCount` was renamed to `JsMsg.info.deliveryCount` as it
tracks all delivery attempts, not just redeliveries

## Changes to KV

Expand Down