1

I am using the Rabbit MQ HTTP API to purge all messages from a single queue. I have the queue name and I want to purge all these messages. I want to use the HTTP API from my powershell script. This is what I execute from my powershell script:-

Invoke-WebRequest http://server_name:55672/api/queues/%2f/queue_name/Contents -Credential $cred -Method DELETE

But I am getting the below error. Can someone guide me on this?

Invoke-WebRequest : Not Found

The requested document was not found on this server. mochiweb+webmachine web server

  • CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
    • FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
Sumit
  • 119
  • 2
  • 7
  • Is your RMQ instance on 55672? – cantSleepNow Oct 18 '16 at 18:30
  • Yes, the RMQ instance is at 55672. I can view the queue information with this port and Invoke-WebRequest http://localhost:55672/api/queues -Credential $cred -contentType "application/json"-Method Get so this port looks fine. – Sumit Oct 19 '16 at 17:51
  • 1
    I found the problem with the above. There was an issue with the escaping of the virtual host ("/").Somehow the Invoke-WebRequest method was un-escaping the forward slash. It was causing the 404/Document Not Found error. The following 2 links helped identifying the problem:- https://mariuszwojcik.wordpress.com/2014/03/04/how-to-prevent-invoke-restmethod-from-un-escaping-forward-slashes/ This link explains in which .NET version this bug was addressed. http://stackoverflow.com/questions/25596564/percent-encoded-slash-is-decoded-before-the-request-dispatch – Sumit Nov 08 '16 at 17:08

1 Answers1

0

If you are using C#, you can do the following with HareDu:

var result = await _services.GetService<IBrokerObjectFactory>()
    .EmptyQueue("queue", "vhost");

https://github.com/ahives/HareDu2/blob/master/docs/queue-empty.md

Albert
  • 33
  • 6