watermill
watermill copied to clipboard
GoChannel pub/sub shouldn't force retry at sendMessageToSubscriber
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
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.
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.
Are there any updates on this issue? Maybe some workaround to prevent this?
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.
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
}
}
}