-
Notifications
You must be signed in to change notification settings - Fork 708
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PublishAsync
Retry Mechanism Not Working as Expected
#1678
Comments
Here's my server log |
Hey @somratdutta, thanks for creating the issue and sorry it took so long. Indeed, the old JetStream API does not support, the new one (in In the meantime, I suggest you try the new API - it's meant to make message consumption easier and more straightforward, the rest of the API works similarly to the old one. Here's your example using the new API: func main() {
nc, err := nats.Connect(nats.DefaultURL)
if err != nil {
log.Fatalf("Error connecting to NATS: %v", err)
}
defer nc.Close()
js, err := jetstream.New(nc)
if err != nil {
log.Fatalf("Error getting JetStream context: %v", err)
}
subject := "test"
message := []byte("hi")
retryWait := 5 * time.Second
retryAttempts := 10
log.Printf("Async Publishing to subject %s with %d retry attempts and %v retry wait time", subject, retryAttempts, retryWait)
// PublishAsync with retry options
ack, err := js.PublishAsync(subject, message,
jetstream.WithRetryWait(retryWait),
jetstream.WithRetryAttempts(retryAttempts),
)
if err != nil {
log.Fatalf("Async Publish error: %v", err)
}
select {
case <-ack.Ok():
log.Println("PublishAsync acknowledged successfully")
case err := <-ack.Err():
log.Printf("PublishAsync final error: %s", err)
}
} Also, one thing that I noticed in regards to your example: if ack.Err() != nil {
log.Printf("PublishAsync final error: %v", ack.Err())
} else {
log.Println("PublishAsync acknowledged successfully")
}
select {
case <-ack.Ok():
log.Println("PublishAsync acknowledged successfully")
case err := <-ack.Err():
log.Printf("PublishAsync final error: %s", err)
} |
@piotrpio Can you please review the PR which is opened to add retries in publish async for old jetstream API? |
@pranavmehta94 thanks, I reviewed the PR and have a few comments :) |
closing this issue as it was solved. |
Observed behavior
It gives up at first attempt itself after waiting for 5 second.
Expected behavior
The method should retry publishing the message 10 times, with a 5-second wait between attempts, giving up after 50 seconds if there is an error on each attempt.
Server and client version
Host environment
Steps to reproduce
Console Output:
Server Logs:
Server logs clearly show that there were no retry attempts.
The text was updated successfully, but these errors were encountered: