Skip to content

Commit f78179a

Browse files
committed
Update redeliveryCount to deliveryCount across codebase
Renamed `redeliveryCount` to `deliveryCount` to better reflect its purpose, as it tracks all delivery attempts, not just redeliveries. Updated related logic, documentation, and test cases to align with the new naming. Added a migration note for developers regarding this change. Signed-off-by: Alberto Ricart <alberto@synadia.com>
1 parent 7e9b745 commit f78179a

File tree

6 files changed

+44
-11
lines changed

6 files changed

+44
-11
lines changed

jetstream/src/jsapi_types.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,8 @@ export type ConsumerUpdateConfig = PriorityGroups & {
979979
*/
980980
"ack_wait"?: Nanos;
981981
/**
982-
* The number of times a message will be redelivered to consumers if not acknowledged in time
982+
* The maximum number of times a message will be delivered to consumers if not acknowledged in time.
983+
* Default is -1 (will redeliver until acknowledged).
983984
*/
984985
"max_deliver"?: number;
985986
/**
@@ -1163,9 +1164,9 @@ export type DeliveryInfo = {
11631164
*/
11641165
consumer: string;
11651166
/**
1166-
* The number of times the message has been redelivered.
1167+
* The number of times the message has been delivered.
11671168
*/
1168-
redeliveryCount: number;
1169+
deliveryCount: number;
11691170
/**
11701171
* The sequence number of the message in the stream
11711172
*/

jetstream/src/jsmsg.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ export function parseInfo(s: string): DeliveryInfo {
171171
di.account_hash = tokens[3];
172172
di.stream = tokens[4];
173173
di.consumer = tokens[5];
174-
di.redeliveryCount = parseInt(tokens[6], 10);
175-
di.redelivered = di.redeliveryCount > 1;
174+
di.deliveryCount = parseInt(tokens[6], 10);
175+
di.redelivered = di.deliveryCount > 1;
176176
di.streamSequence = parseInt(tokens[7], 10);
177177
di.deliverySequence = parseInt(tokens[8], 10);
178178
di.timestampNanos = parseInt(tokens[9], 10);
@@ -216,7 +216,7 @@ export class JsMsgImpl implements JsMsg {
216216
}
217217

218218
get redelivered(): boolean {
219-
return this.info.redeliveryCount > 1;
219+
return this.info.deliveryCount > 1;
220220
}
221221

222222
get reply(): string {

jetstream/tests/jetstream_test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ Deno.test("jetstream - backoff", async () => {
730730
const iter = await c.consume({
731731
callback: (m) => {
732732
when.push(Date.now());
733-
if (m.info.redeliveryCount === 4) {
733+
if (m.info.deliveryCount === 4) {
734734
iter.stop();
735735
}
736736
},
@@ -779,7 +779,7 @@ Deno.test("jetstream - redelivery", async () => {
779779
if (m.redelivered) {
780780
redeliveries++;
781781
}
782-
if (m.info.redeliveryCount === 4) {
782+
if (m.info.deliveryCount === 4) {
783783
setTimeout(() => {
784784
iter.stop();
785785
}, 2000);

jetstream/tests/jsmsg_test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Deno.test("jsmsg - parse", () => {
4848
const info = parseInfo(rs);
4949
assertEquals(info.stream, "streamname");
5050
assertEquals(info.consumer, "consumername");
51-
assertEquals(info.redeliveryCount, 2);
51+
assertEquals(info.deliveryCount, 2);
5252
assertEquals(info.streamSequence, 3);
5353
assertEquals(info.pending, 100);
5454
});
@@ -63,7 +63,7 @@ Deno.test("jsmsg - parse long", () => {
6363
assertEquals(info.account_hash, "account");
6464
assertEquals(info.stream, "streamname");
6565
assertEquals(info.consumer, "consumername");
66-
assertEquals(info.redeliveryCount, 2);
66+
assertEquals(info.deliveryCount, 2);
6767
assertEquals(info.streamSequence, 3);
6868
assertEquals(info.pending, 100);
6969
});

jetstream/tests/next_test.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ Deno.test("next - listener leaks", async () => {
107107
const m = await consumer.next();
108108
if (m) {
109109
m.nak();
110-
if (m.info?.redeliveryCount > 100) {
110+
if (m.info?.deliveryCount > 100) {
111111
break;
112112
}
113113
}
@@ -203,3 +203,33 @@ Deno.test("next - consumer bind", async () => {
203203

204204
await cleanup(ns, nc);
205205
});
206+
207+
Deno.test("next - delivery count", async () => {
208+
const { ns, nc } = await setup(jetstreamServerConf());
209+
210+
const jsm = await jetstreamManager(nc);
211+
await jsm.streams.add({ name: "A", subjects: ["hello"] });
212+
213+
await jsm.consumers.add("A", {
214+
durable_name: "a",
215+
deliver_policy: DeliverPolicy.All,
216+
ack_policy: AckPolicy.Explicit,
217+
max_deliver: 2,
218+
ack_wait: nanos(1000),
219+
});
220+
221+
const js = jetstream(nc);
222+
await js.publish("hello");
223+
224+
const c = await js.consumers.get("A", "a");
225+
let m = await c.next();
226+
assertEquals(m?.info.deliveryCount, 1);
227+
await delay(1500);
228+
m = await c.next();
229+
await delay(1500);
230+
assertEquals(m?.info.deliveryCount, 2);
231+
m = await c.next({ expires: 1000 });
232+
assertEquals(m, null);
233+
234+
await cleanup(ns, nc);
235+
});

migration.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ To use JetStream, you must install and import `@nats/jetstream`.
144144
- The `ConsumerEvents` and `ConsumerDebugEvents` enum has been removed and
145145
replaced with `ConsumerNotification` which have a discriminating field `type`.
146146
The status objects provide a more specific API for querying those events.
147+
- `JsMsg.info.redeliveryCount` was renamed to `JsMsg.info.deliveryCount` as it
148+
tracks all delivery attempts, not just redeliveries
147149

148150
## Changes to KV
149151

0 commit comments

Comments
 (0)