Skip to content

Commit

Permalink
Correctly handle multiple confirms
Browse files Browse the repository at this point in the history
  • Loading branch information
axelo committed Sep 13, 2024
1 parent 1bde093 commit ce501e0
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/Insurello.RabbitMqClient/MqClient.fs
Original file line number Diff line number Diff line change
Expand Up @@ -393,13 +393,20 @@ module MqClient =
else
())

/// <summary>Returns true if the publishSeqNo is confirmed.</summary>
/// <param name="multipleConfirms">If false, only one message is confirmed, if true, all messages with a lower or equal sequence number are confirmed.</param>
let private isConfirmed (publishSeqNo: uint64) (deliveredPublishSeqNo: uint64) (multipleConfirms: bool) : bool =
publishSeqNo = deliveredPublishSeqNo
|| multipleConfirms
&& publishSeqNo < deliveredPublishSeqNo

let private createBasicAckEventHandler: uint64
-> System.Threading.Tasks.TaskCompletionSource<PublishResult>
-> System.EventHandler<BasicAckEventArgs> =
fun publishSeqNo tcs ->
System.EventHandler<BasicAckEventArgs> (fun _ args ->
if args.DeliveryTag = publishSeqNo then
tcs.TrySetResult(PublishResult.Acked) |> ignore
if isConfirmed publishSeqNo args.DeliveryTag args.Multiple then
tcs.TrySetResult PublishResult.Acked |> ignore
else
())

Expand All @@ -408,8 +415,8 @@ module MqClient =
-> System.EventHandler<BasicNackEventArgs> =
fun publishSeqNo tcs ->
System.EventHandler<BasicNackEventArgs> (fun _ args ->
if args.DeliveryTag = publishSeqNo then
tcs.TrySetResult(PublishResult.Nacked) |> ignore
if isConfirmed publishSeqNo args.DeliveryTag args.Multiple then
tcs.TrySetResult PublishResult.Nacked |> ignore
else
())

Expand Down

0 comments on commit ce501e0

Please sign in to comment.