Search code examples
c#.netrabbitmqmessaging

RabbitMQ C# API: How to check if a binding exists?


Using the RabbitMQ C# API, how would I check to see if a binding exists from a given queue to a given exchange?

A lot of RabbitMQ calls are idempotent, so some people may say that the check is unnecessary for those cases, but I think they would be useful in testing.


Solution

  • You could use their REST API to call and see if the binding exists.

    You have a local copy of the API reference at: your_server_name:15672/api/ or you can find it at their online docs

    You can make a GET call to either:

    • /api/exchanges/vhost
    • /name/bindings/destination

    with the appropriate substitutions in there for vhost or name.

    Or you could just call:

    • /api/bindings

    to get all of them.

    From there, you'll need to parse the JSON object that is returned.

    Note, you will likely need to authenticate but their examples show how to do so.