-
Notifications
You must be signed in to change notification settings - Fork 705
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
why consumer redelivered again when msg.DoubleAck with no error #1717
Comments
log total message: 2000 |
check every time database if exists it will be expensive so how to get only one time |
Hey! Your example does not show how you actually process the acks. Regarding the double ack: |
func (s *PushService) processBatch(msg jetstream.Msg) {
var nt models.Notification
err := pkg.JsonUnmarshal(msg.Data(), &nt)
if err != nil {
log.Println("failed to unmarshal message:", err, string(msg.Data()))
return
}
md, err := msg.Metadata()
log.Println("batch message", nt.BatchId, err, md.NumDelivered, md.NumPending, md.Consumer, md.Sequence.Consumer, md.Sequence.Stream)
vals := make([][]any, 0)
code, resp, err := sendBatchFCM(nt)
log.Println(nt.BatchId, code, err)
if code == 406 {
errStr := ""
if err != nil {
errStr = err.Error()
}
for _, r := range nt.Receivers {
vals = append(vals, []any{nt.BatchId, r.Id, r.Token, errStr, code})
}
err = pkg.BulkInsert(s.ctx, s.db, "pushes", []string{"batch_id", "user_id", "token", "error", "status"}, vals)
if err != nil {
log.Println("failed pkg.BulkInsert:", err)
}
err1 := msg.DoubleAck(s.ctx)
if err1 != nil {
log.Println("failed to ack message:", err1, string(msg.Data()))
}
return
} else if code > 0 {
var sms = models.Notification{BatchId: nt.BatchId, Title: nt.Title, Message: nt.Message, Receivers: make([]models.Receiver, 0)}
//todo retry for timeout and failed for 5xx
errStr := ""
for k, rs := range resp.Responses {
if rs.Success {
vals = append(vals, []any{nt.BatchId, nt.Receivers[k].Id, nt.Receivers[k].Token, rs.MessageID, 200})
} else {
if rs.Error != nil {
errStr = fmt.Sprintf("%s %s", rs.Error, rs.MessageID)
}
sms.Receivers = append(sms.Receivers, nt.Receivers[k])
vals = append(vals, []any{nt.BatchId, nt.Receivers[k].Id, nt.Receivers[k].Token, errStr, 417})
}
}
err = pkg.BulkInsert(s.ctx, s.db, "pushes", []string{"batch_id", "user_id", "token", "error", "status"}, vals)
if err != nil {
log.Println("failed pkg.BulkInsert:", err)
}
if len(sms.Receivers) > 0 {
bt, err := pkg.JsonMarshal(sms)
if err != nil {
log.Println("failed to marshal message:", err)
} else {
err = s.js.Publish(s.ctx, "sms.batch", bt)
if err != nil {
log.Println("failed to publish message:", err)
}
}
}
err1 := msg.DoubleAck(s.ctx)
if err1 != nil {
log.Println("failed to ack message:", err1, string(msg.Data()))
}
}
} |
about ackwait is bigger than timeout of http I logged response code all is is bigger 0 |
Retention: jetstream.WorkQueuePolicy, but it delivered more than 1 |
Observed behavior
Expected behavior
I need only one time delivering
Server and client version
github.com/nats-io/nats.go v1.37.0
server:Version: 2.10.20
Host environment
in docker
Steps to reproduce
No response
The text was updated successfully, but these errors were encountered: