kubemq-io / kubemq-CSharp

C# Library for KubeMQ server
MIT License
30 stars 8 forks source link

Max Number of Message in queue doesn't seem to work #9

Closed francotiveron closed 1 year ago

francotiveron commented 2 years ago

Setting the maximum number of message in the queue doesn't work.

In both the following examples, the expected number of messages received by the queue should be 2 (max message number is set to 2 both in the constructor and message Policy), instead all the 3 sent message are retrieved by the Pull.

let w = Queue.Queue(queue, "writer", Nullable(2), Nullable(), url)
w.AckAll(1) |> ignore

[
Queue.Message(
    Body = Tools.Converter.ToByteArray "message-1"
    , Metadata = "meta-1"
    , Policy = QueueMessagePolicy(MaxReceiveCount = 2, MaxReceiveQueue = "dead-letter")
) 
Queue.Message(
    Body = Tools.Converter.ToByteArray "message-2"
    , Metadata = "meta-2"
    , Policy = QueueMessagePolicy(MaxReceiveCount = 2, MaxReceiveQueue = "dead-letter")
) 
Queue.Message(
    Body = Tools.Converter.ToByteArray "message-3"
    , Metadata = "meta-3"
    , Policy = QueueMessagePolicy(MaxReceiveCount = 2, MaxReceiveQueue = "dead-letter")
) 
] |> w.Batch |> ignore

let r1 = Queue.Queue(queue, "reader-1", url)

let messages = r1.Pull(10, 0).Messages.ToList()

assert(messages.Count = 2) //fails (3)
let w = Queue.Queue(queue, "writer", Nullable(2), Nullable(), url)
w.AckAll(1) |> ignore

let m = 
    Queue.Message(
        Body = Tools.Converter.ToByteArray "message-1"
        , Metadata = "meta-1"
        , Policy = QueueMessagePolicy(MaxReceiveCount = 2, MaxReceiveQueue = "dead-letter")
    ) 

w.Send(m) |> ignore
w.Send(m) |> ignore
w.Send(m) |> ignore

let r1 = Queue.Queue(queue, "reader-1", , Nullable(2), Nullable(), url)

let messages = r1.Pull(10, 0).Messages.ToList()

assert(messages.Count = 2) //fails (3)
kubemq commented 1 year ago

Please use the QueueStream implementation