1

I am trying to use streams with redis using Reddison lib. I am using code StreamReadGroupArgs.neverDelivered() when receiving the messages. But if I don't ack it then the next time when readGroup is called it does not get those messages. The problem is that what if the node crashed or there was a glitch in network and I could not process those messages. Then even if I have not ack it I will not get those messages again. Is there a workaround for this or something else that I can do?

Sachin Jain
  • 97
  • 1
  • 10

1 Answers1

2

This is the correct behavior. Otherwise you will end up receiving redundant messages everytime.

Either you have to acknowledge or you have to explicitly ask redis to resend the messages which you have not acknowledged. For that StreamReadGroupArgs.neverDelivered() is not a correct option. Because it was already delivered. But you lost the message somehow.

Correct option for your use case is the below one which will send the messages which are not acknowledged.

StreamReadGroupArgs.greaterThan(new StreamMessageId(0))

vins
  • 15,030
  • 3
  • 36
  • 47
  • I tried that and what happens is that when the messages are being sent to the stream it just does not get those messages. It only gets messages that were received by were not ack. ```code stream.readGroup("group4", "consumer_4", StreamReadGroupArgs.greaterThan(new StreamMessageId(0)))``` I had to combine the above and ```code StreamReadGroupArgs.neverDelivered() ``` – Sachin Jain Sep 24 '21 at 17:37
  • Yes. it is for 2 different purposes. The correct way to do is - whenever the system restarts after crash - look for `StreamReadGroupArgs.greaterThan(new StreamMessageId(0))`. if therre are any, process them first. once processed, move to `neverDelivered`. – vins Sep 24 '21 at 17:44
  • Yeah that makes sense. Just a FYI coz i saw this, if you are trimming your stream after adding to save space then you have to be careful with just ```codeStreamReadGroupArgs.greaterThan(new StreamMessageId(0))``` coz it can produce a message that is no longer present in stream and client throws array out of bound exception. I had to use some complex logic for that. I will mark your answer though thanks for it. – Sachin Jain Sep 24 '21 at 20:34