Skip to content

Commit 5bd67fa

Browse files
committed
matching: send status updates to NATS -> reduce message redelivery
1 parent af49b49 commit 5bd67fa

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

lib/match.js

+10
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,12 @@ const runGtfsMatching = async (cfg, opt = {}) => {
234234
matched: isMatched ? '1' : '0',
235235
cached: isCached ? '1' : '0',
236236
}, matchingTime / 1000)
237+
238+
if (!isMatched) {
239+
// > Indicate to the JetStream server that processing of the message failed and that the message should not be sent to the consumer again.
240+
// https://nats-io.github.io/nats.js/jetstream/interfaces/JsMsg.html#term
241+
msg.term()
242+
}
237243
} catch (err) {
238244
if (isProgrammerError(err)) {
239245
throw err
@@ -262,6 +268,10 @@ const runGtfsMatching = async (cfg, opt = {}) => {
262268
dataSlice: data.slice(0, 100).toString('utf8'),
263269
}, 'processing AUS IstFahrt msg')
264270

271+
// > Indicate to the JetStream server that processing of the message is on going, and that the ack wait timer for the message should be reset preventing a redelivery.
272+
// https://nats-io.github.io/nats.js/jetstream/interfaces/JsMsg.html#working
273+
msg.working()
274+
265275
// update NATS metrics
266276
{
267277
const {

0 commit comments

Comments
 (0)