watermill icon indicating copy to clipboard operation
watermill copied to clipboard

GoChannel pub/sub shouldn't force retry at sendMessageToSubscriber

Open woostundy opened this issue 3 years ago • 5 comments

Due to the underlying processing logic, GoChannel pub/sub will never stop resending NACK messages, at a crazy speed. It shouldn't do retry work here. It's better to handle on the upper level such as retry middleware.

https://github.com/ThreeDotsLabs/watermill/blob/67407a6e41587e97925f207abfe9b07f21f5f356/pubsub/gochannel/pubsub.go#L351-L379

#240

woostundy avatar Aug 24 '22 08:08 woostundy

In contrast to other Pub/Subs, GoChannel has no storage backend besides its memory. So letting the client retry messages with middleware is risky: if someone doesn't use it, the message would be lost forever.

m110 avatar Jan 24 '23 21:01 m110

In contrast to other Pub/Subs, GoChannel has no storage backend besides its memory. So letting the client retry messages with middleware is risky: if someone doesn't use it, the message would be lost forever.

How about adding a param to avoid the endless retry? sometimes, like panic or network errors were thrown, the retry storm will be quite dangerous.

woostundy avatar Feb 02 '23 12:02 woostundy

Are there any updates on this issue? Maybe some workaround to prevent this?

ivaaaan avatar Jun 09 '23 14:06 ivaaaan

Are there any updates on this issue? Maybe some workaround to prevent this?

I'll make a pr to add a param to control if it resends automatically.

woostundy avatar Jun 13 '23 04:06 woostundy

I use this as a workaround

router.AddMiddleware(
  retryMiddleware(logger),
)

func retryMiddleware(logger watermill.LoggerAdapter) func(h message.HandlerFunc) message.HandlerFunc {
  retry := middleware.Retry{
    MaxRetries:      3,
    InitialInterval: time.Microsecond,
    Logger:          logger,
  }
  return func(h message.HandlerFunc) message.HandlerFunc {
    return func(msg *message.Message) ([]*message.Message, error) {
      msgs, err := retry.Middleware(h)(msg)
      if err != nil {
        logger.Error("reach max_retires", err, nil)
        return nil, nil
      }
      return msgs, nil
    }
  }
}

Dragon-Huang0403 avatar Jul 11 '23 04:07 Dragon-Huang0403