1
0
Fork 0
mirror of https://github.com/postmannen/ctrl.git synced 2025-03-16 03:08:14 +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) er := fmt.Errorf("info: preparing to send nats message with subject %v ", msg.Subject)
p.errorKernel.logConsoleOnlyIfDebug(er, p.configuration) p.errorKernel.logConsoleOnlyIfDebug(er, p.configuration)
var err error
switch {
// If it is a NACK message we just deliver the message and return // 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. // 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) err := natsConn.PublishMsg(msg)
if err != nil { if err != nil {
er := fmt.Errorf("error: nats publish for message with subject failed: %v", err) er := fmt.Errorf("error: nats publish for message with subject failed: %v", err)
log.Printf("%v\n", er) log.Printf("%v\n", er)
return return ErrACKSubscribeRetry
} }
p.metrics.promNatsDeliveredTotal.Inc() 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 // The remaining logic is for handling ACK messages, so we return here
// since it was a NACK message, and all or now done. // 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 case p.subject.Event == EventACK:
// then the message is an ACK message, and we should handle that.
//
// The function below will return nil if the message should not be retried. // The function below will return nil if the message should not be retried.
// //
// All other errors happening will return ErrACKSubscribeRetry which will lead // All other errors happening will return ErrACKSubscribeRetry which will lead
// to a 'continue' for the for loop when checking the error directly after this // to a 'continue' for the for loop when checking the error directly after this
// function is called // function is called
err := func() error { err = func() error {
defer func() { retryAttempts++ }() defer func() { retryAttempts++ }()
if retryAttempts > message.Retries { if retryAttempts > message.Retries {
@ -425,6 +427,7 @@ func (p process) messageDeliverNats(natsMsgPayload []byte, natsMsgHeader nats.He
return nil return nil
}() }()
}
if err == ErrACKSubscribeRetry { if err == ErrACKSubscribeRetry {
continue continue
@ -664,9 +667,11 @@ func executeHandler(p process, message Message, thisNode string) {
runAsScheduled = true runAsScheduled = true
} }
if p.configuration.EnableAclCheck {
// Either ACL were verified OK, or ACL/Signature check was not enabled, so we call the handler. // 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) 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) p.errorKernel.logConsoleOnlyIfDebug(er, p.configuration)
}
switch { switch {
case !runAsScheduled: case !runAsScheduled: