Skip to content

Commit b3c70f8

Browse files
committed
matching: send status updates to NATS -> reduce message redelivery
1 parent cf3f3e6 commit b3c70f8

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
@@ -230,6 +230,12 @@ const runGtfsMatching = async (cfg, opt = {}) => {
230230
matched: isMatched ? '1' : '0',
231231
cached: isCached ? '1' : '0',
232232
}, matchingTime / 1000)
233+
234+
if (!isMatched) {
235+
// > Indicate to the JetStream server that processing of the message failed and that the message should not be sent to the consumer again.
236+
// https://nats-io.github.io/nats.js/jetstream/interfaces/JsMsg.html#term
237+
msg.term()
238+
}
233239
} catch (err) {
234240
if (isProgrammerError(err)) {
235241
throw err
@@ -258,6 +264,10 @@ const runGtfsMatching = async (cfg, opt = {}) => {
258264
dataSlice: data.slice(0, 100).toString('utf8'),
259265
}, 'processing AUS IstFahrt msg')
260266

267+
// > 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.
268+
// https://nats-io.github.io/nats.js/jetstream/interfaces/JsMsg.html#working
269+
msg.working()
270+
261271
// update NATS metrics
262272
{
263273
const {

0 commit comments

Comments
 (0)