-
Notifications
You must be signed in to change notification settings - Fork 492
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Steps to reproduce
docker-compose.yml
version: "3.8"
services:
nats:
image: nats:2.10
ports:
- "4222:4222"
go
package main
import (
"errors"
"time"
"github.com/ThreeDotsLabs/watermill"
"github.com/ThreeDotsLabs/watermill/message"
"github.com/ThreeDotsLabs/watermill/message/router"
"github.com/ThreeDotsLabs/watermill/message/router/middleware"
wmnats "github.com/ThreeDotsLabs/watermill-nats/v2/pkg/nats"
)
func main() {
logger := watermill.NewStdLogger(false, false)
sub, _ := wmnats.NewSubscriber(
wmnats.SubscriberConfig{URL: "nats://localhost:4222"},
logger,
)
pub, _ := wmnats.NewPublisher(
wmnats.PublisherConfig{URL: "nats://localhost:4222"},
logger,
)
r, _ := router.NewRouter(router.Config{}, logger)
r.AddMiddleware(middleware.Retry{
MaxRetries: 3,
InitialInterval: time.Second,
}.Middleware)
r.AddMiddleware(middleware.PoisonQueue(pub, "poison.topic"))
r.AddHandler(
"test-handler",
"input.topic",
sub,
"output.topic",
pub,
func(msg *message.Message) ([]*message.Message, error) {
return nil, errors.New("simulated error")
},
)
go r.Run(nil)
_ = pub.Publish("input.topic",
message.NewMessage(watermill.NewUUID(), []byte("test")),
)
select {}
}
Expected behavior
When the handler returns an error and Retry middleware is configured, the handler should be retried according to MaxRetries, and the message should be sent to the poison queue only after retries are exhausted.
Actual behavior
The handler is executed only once and the message is sent directly to the poison queue without retrying.
Possible solution
Clarify in documentation how Retry and PoisonQueue behave when used with AddHandler, or document that AddHandler is intended only for handlers that always publish output messages.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working