RamblingCookieMonster / PSRabbitMq

PowerShell module to send and receive messages from a RabbitMq server
http://ramblingcookiemonster.github.io/RabbitMQ-Intro/
MIT License
47 stars 29 forks source link

Wait-RabbitMqMessage drains queue with one run #27

Open kensel opened 5 years ago

kensel commented 5 years ago

Hello,

I'm using the module and when I run Wait-RabbitMqMessage it removes all messages but only returns 1 output. Trying to understand if this is the expected behavior as I expected it to be more like the Get-RabbitMQMessage where it would return 1 object per run as Wait-RabbitMqMessage doesn't have the count parameter.

Get-NetIPAddress | Select-Object -ExpandProperty IPAddress | Send-RabbitMQMessage -Exchange TestFanExc -Key 'TestQueue'-Persistent @Params -SerializeAs "text/plain"

$Incoming = Wait-RabbitMQMessage -Exchange TestFanExc -Key 'TestQueue' -QueueName TestQueue2 -Timeout 120 @Params
$Incoming
# ::1

Thank you, Kensel

derekmwright commented 5 years ago

Similar to https://github.com/RamblingCookieMonster/PSRabbitMq/issues/23

You should pipe this to a for-each loop and process messages and/or do assignment within that loop.

kensel commented 5 years ago

Hello derekmwright, I tried changing to:

Wait-RabbitMQMessage -Exchange TestFanExc -Key 'TestQueue' -QueueName TestQueue -Timeout 120 @Params -LoopInterval 5 | ForEach-Object { Write-host $_}
#And
Start-RabbitMqListener -Exchange TestFanExc -Key 'TestQueue' -QueueName TestQueue @Params | ForEach-Object { Write-host $_}

But the first one still drains the queue while only outputting one item and the second outputs the number of messages but the same message (28 lines of '::1').

yuvalmarciano commented 4 years ago

Try to turn on the -RequireAck flag (it's not optimal, but that's the current solution I have for you). From the function's docstring:

.PARAMETER RequireAck
        If specified, require an ack for messages
        Note: Without this, dequeue seems to empty a whole queue?