Skip to content

Commit

Permalink
matching: send status updates to NATS -> reduce message redelivery
Browse files Browse the repository at this point in the history
  • Loading branch information
derhuerst committed Nov 25, 2024
1 parent cf3f3e6 commit b3c70f8
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/match.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,12 @@ const runGtfsMatching = async (cfg, opt = {}) => {
matched: isMatched ? '1' : '0',
cached: isCached ? '1' : '0',
}, matchingTime / 1000)

if (!isMatched) {
// > Indicate to the JetStream server that processing of the message failed and that the message should not be sent to the consumer again.
// https://nats-io.github.io/nats.js/jetstream/interfaces/JsMsg.html#term
msg.term()
}
} catch (err) {
if (isProgrammerError(err)) {
throw err
Expand Down Expand Up @@ -258,6 +264,10 @@ const runGtfsMatching = async (cfg, opt = {}) => {
dataSlice: data.slice(0, 100).toString('utf8'),
}, 'processing AUS IstFahrt msg')

// > 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.
// https://nats-io.github.io/nats.js/jetstream/interfaces/JsMsg.html#working
msg.working()

// update NATS metrics
{
const {
Expand Down

0 comments on commit b3c70f8

Please sign in to comment.