/// <summary> /// Applies decision. /// If save is chosen, saves the message. /// If acknowledge is chosen, sends an ack message to source. /// Returns true is allowed /// </summary> internal async Task <bool> ApplyDecision(Decision decision, QueueMessage message, HorseMessage customAck = null) { try { if (decision.SaveMessage) { await SaveMessage(message); } if (!message.IsProducerAckSent && (decision.Acknowledge == DeliveryAcknowledgeDecision.Always || decision.Acknowledge == DeliveryAcknowledgeDecision.Negative || decision.Acknowledge == DeliveryAcknowledgeDecision.IfSaved && message.IsSaved)) { HorseMessage acknowledge = customAck ?? message.Message.CreateAcknowledge(decision.Acknowledge == DeliveryAcknowledgeDecision.Negative ? "none" : null); if (message.Source != null && message.Source.IsConnected) { bool sent = await message.Source.SendAsync(acknowledge); message.IsProducerAckSent = sent; if (decision.AcknowledgeDelivery != null) { await decision.AcknowledgeDelivery(message, message.Source, sent); } } else if (decision.AcknowledgeDelivery != null) { await decision.AcknowledgeDelivery(message, message.Source, false); } } if (decision.PutBack != PutBackDecision.No) { ApplyPutBack(decision, message); } else if (!decision.Allow) { Info.AddMessageRemove(); _ = DeliveryHandler.MessageDequeued(this, message); } } catch (Exception e) { Server.SendError("APPLY_DECISION", e, $"QueueName:{Name}, MessageId:{message.Message.MessageId}"); } return(decision.Allow); }
/// <summary> /// Applies decision. /// If save is chosen, saves the message. /// If acknowledge is chosen, sends an ack message to source. /// Returns true is allowed /// </summary> internal async Task <bool> ApplyDecision(Decision decision, QueueMessage message, TmqMessage customAck = null) { if (decision.SaveMessage) { await SaveMessage(message); } if (decision.SendAcknowledge == DeliveryAcknowledgeDecision.Always || decision.SendAcknowledge == DeliveryAcknowledgeDecision.IfSaved && message.IsSaved) { TmqMessage acknowledge = customAck ?? message.Message.CreateAcknowledge(); if (message.Source != null && message.Source.IsConnected) { bool sent = await message.Source.SendAsync(acknowledge); if (decision.AcknowledgeDelivery != null) { await decision.AcknowledgeDelivery(message, message.Source, sent); } } else if (decision.AcknowledgeDelivery != null) { await decision.AcknowledgeDelivery(message, message.Source, false); } } if (decision.KeepMessage) { AddMessage(message, false); } else if (!decision.Allow) { Info.AddMessageRemove(); _ = DeliveryHandler.MessageRemoved(this, message); } return(decision.Allow); }