1
0
Fork 0
mirror of https://github.com/postmannen/ctrl.git synced 2024-12-14 12:37:31 +00:00

made ACK/NACK selection more clear

This commit is contained in:
postmannen 2022-12-29 22:49:47 +01:00
parent c12cf70620
commit 5c5f8100d0

View file

@ -286,14 +286,18 @@ func (p process) messageDeliverNats(natsMsgPayload []byte, natsMsgHeader nats.He
er := fmt.Errorf("info: preparing to send nats message with subject %v ", msg.Subject)
p.errorKernel.logConsoleOnlyIfDebug(er, p.configuration)
var err error
switch {
// If it is a NACK message we just deliver the message and return
// here so we don't create a ACK message and then stop waiting for it.
if p.subject.Event == EventNACK {
case p.subject.Event == EventNACK:
err = func() error {
err := natsConn.PublishMsg(msg)
if err != nil {
er := fmt.Errorf("error: nats publish for message with subject failed: %v", err)
log.Printf("%v\n", er)
return
return ErrACKSubscribeRetry
}
p.metrics.promNatsDeliveredTotal.Inc()
@ -310,18 +314,16 @@ func (p process) messageDeliverNats(natsMsgPayload []byte, natsMsgHeader nats.He
// The remaining logic is for handling ACK messages, so we return here
// since it was a NACK message, and all or now done.
return
}
return nil
}()
// Since we got here, and the code was not detected as NACK message earlier
// then the message is an ACK message, and we should handle that.
//
case p.subject.Event == EventACK:
// The function below will return nil if the message should not be retried.
//
// All other errors happening will return ErrACKSubscribeRetry which will lead
// to a 'continue' for the for loop when checking the error directly after this
// function is called
err := func() error {
err = func() error {
defer func() { retryAttempts++ }()
if retryAttempts > message.Retries {
@ -425,6 +427,7 @@ func (p process) messageDeliverNats(natsMsgPayload []byte, natsMsgHeader nats.He
return nil
}()
}
if err == ErrACKSubscribeRetry {
continue
@ -664,9 +667,11 @@ func executeHandler(p process, message Message, thisNode string) {
runAsScheduled = true
}
if p.configuration.EnableAclCheck {
// Either ACL were verified OK, or ACL/Signature check was not enabled, so we call the handler.
er := fmt.Errorf("info: subscriberHandler: Either ACL were verified OK, or ACL/Signature check was not enabled, so we call the handler: %v", true)
p.errorKernel.logConsoleOnlyIfDebug(er, p.configuration)
}
switch {
case !runAsScheduled: