.Net powershell EventingBasicConsumer

104 views
Skip to first unread message

Patrick von der Hagen

unread,
Aug 6, 2019, 8:01:02 AM8/6/19
to rabbitmq-users
Hi,

I've been running some powershell-Consumer for years, using some old RabbitMQ.dll from 2014. Not sure about the version, probably the last one not affected by https://github.com/rabbitmq/rabbitmq-dotnet-client/issues/264
It stopped working with more recent rabbitmq-releases, so it blocked me from upgrading rabbitmq as well.
Now I have to upgrade rabbitmq from 3.5 to 3.7 for other reasons and therefore need a fix for my powershell-script. I chose RabbitMQ.Client 5.1.0, no reason not to go to the latest release.

The old code is using RabbitMQ.Client.QueueingBasicConsumer, which I need to change to RabbitMQ.Client.Events.EventingBasicConsumer.

This is what I try:
$consumer = New-Object RabbitMQ.Client.Events.EventingBasicConsumer($channel)
$a = function x( $c, $ea) {
$body = $ea.Body
$props = $ea.BasicProperties
$messageJson = $enc.GetString($body)
Write-Warning $messageJson
$channel.BasicNack($ea.DeliveryTag, $false, $true)
}
Register-ObjectEvent $consumer -EventName "Received" $a
$autoAck = $false
$consumerTag = $channel.BasicConsume($queue, $autoAck, $consumer, [type]::Missing,[type]::Missing,[type]::Missing,[type]::Missing)

I'd be extremely surprised if the event worked, but the call to $channel.BasicConsume fails, so that's to be solved later...

The current error is: Cannot find an overload for "BasicConsume" and the argument count: "7".
But as far as I can tell, 7 should be correct?

if I try $channel.BasicConsume($queue, $autoAck, $consumer, $null,$null,$null,$null)
instead, the powershell simply crashes. I'm not surprised, "Missing" seams much more reasonable.

Obviously, I started with $channel.BasicConsume($queue, $autoAck, $consumer), but it's wrong argument count again.

Passing named parameters to .net-code is not supported by powershell.

So, any ideas? Somebody got a solution?

Pull would work, but I'd like to avoid it.

Best regards
Patrick

Karl Nilsson

unread,
Aug 7, 2019, 4:34:38 AM8/7/19
to rabbitm...@googlegroups.com
There is only one "real" method on the IModel interface in 5.x and that is the one with 7 arguments [1]. All the other overloads are implemented as extension methods. Not sure if powershell is able to resolve those but you should be able to use the 7 argument method.


--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-user...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/rabbitmq-users/79d0ecaf-24e1-438e-af3c-4a6ddf0efb72%40googlegroups.com.


--
Karl Nilsson

Pivotal/RabbitMQ

Patrick von der Hagen

unread,
Aug 7, 2019, 11:53:33 AM8/7/19
to rabbitmq-users
Well, as my code shows I've been trying to use that method, but it's quite hard to do without any idea what "noLocal" or "arguments" might be about.
Should I draw inspiration from RabbitMQ.Client/src/client/api/IModelExtensions.cs and just hope for the best?
It uses 
           
bool autoAck = false,
string consumerTag = "",
bool noLocal = false,
bool exclusive = false,
IDictionary<string, object> arguments = null

Best regards
Patrick
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitm...@googlegroups.com.


--
Karl Nilsson

Pivotal/RabbitMQ

Karl Nilsson

unread,
Aug 7, 2019, 11:57:46 AM8/7/19
to rabbitm...@googlegroups.com
That would be a good start. just passing nulls to everything apart from the args is likely to fail.

To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-user...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/rabbitmq-users/5f568423-2445-4912-a511-81bec4da2a7d%40googlegroups.com.


--
Karl Nilsson

Pivotal/RabbitMQ
Reply all
Reply to author
Forward
0 new messages