Is it possible to get the current number of attempts to process the message msg jetstream.Msg?

47 Views Asked by At

Fo Example:

func handler(msg jetstream.Msg) {
    err := doWork()
    if err != nil {
        _ = msg.NakWithDelay(time.Second * 10)
    }

    _ = msg.Ack()
}

I would like to get the current number of attempts to process the message msg jetstream.Msg in order to create a timeout with progression. How can I do it?

1

There are 1 best solutions below

1
Spuxy On

i guess, it would be local variable for counting.

var counter int
err := doWork()
if err != nil {
// ... stufs
counter++
}

just find the point in ur code, where it can failes when it tries to process the message, and handle the return err (it should return non-zero value of type error) and if it happens, just increase the counter and handle that counter how u want eg.:

if counter > 5 {
log.Prinf("Internal err: %v", err.Error())
os.Exit(78)
}