snapshot of https://github.com/ThreeDotsLabs/watermill.git (master, 2026-09-15; blobs > 131072B omitted)
Some checks failed
master / ci (push) Failing after 0s
Some checks failed
master / ci (push) Failing after 0s
This commit is contained in:
22
message/router/middleware/duplicator.go
Normal file
22
message/router/middleware/duplicator.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"github.com/ThreeDotsLabs/watermill/message"
|
||||
)
|
||||
|
||||
// Duplicator is processing messages twice, to ensure that the endpoint is idempotent.
|
||||
func Duplicator(h message.HandlerFunc) message.HandlerFunc {
|
||||
return func(msg *message.Message) ([]*message.Message, error) {
|
||||
firstProducedMessages, firstErr := h(msg)
|
||||
if firstErr != nil {
|
||||
return nil, firstErr
|
||||
}
|
||||
|
||||
secondProducedMessages, secondErr := h(msg)
|
||||
if secondErr != nil {
|
||||
return nil, secondErr
|
||||
}
|
||||
|
||||
return append(firstProducedMessages, secondProducedMessages...), nil
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user