How can I delete a RabbitMq exchange? - rabbitmq

I can easily delete queues, like this:
rabbitmqadmin delete queue name='MyQ'
However, I cannot find a way to delete exchanges. What am I missing?

➜
./rabbitmqadmin delete exchange name='myexchange'
exchange deleted

you can also get the same functionality with the rabbitmq management web interface,
usually accessible via localhost:15672
(the rabbitmq management plugin need to be installed, usually the case)

Related

Scripting RabbitMQ bindings

I want to set up a bunch of rabbitMQ exchanges and queues together with their bindings trough a Octopus deploy step. We're using NServiceBus and we don't want to give the application too much permission hence it can't set up the stuff itself.
Previously we've had a powershell script for setting up virtual host and users and I've been looking at extending this so that we can create the queues, exchanges and bindings too. This script uses RabbitMQ REST API.
The queues and exchanges can be created without any hazzle but the bindings are another matter. I can't find any suitable documentation about setting this up over HTTP. I've read something that this is not the preferred way to do stuff but what options are available to me given octopus scripting?
The code I want to execute is something like this:
http://localhost:15672/api/bindings/TestHost/e/nsb.delay-level-00/q/nsb.delay-level-00
The exchange is named nsb.delay-level-00 and the queue has the same name. Both exists in the rabbitMQ virtual host.
Any ideas?
I found out that, in contrast to creating queues and exchanges, the method call has to be a POST in this scenario.
So, POST http://localhost:15672/api/bindings/TestHost/e/nsb.delay-level-00/q/nsb.delay-level-00 works fine.

How to copy messages to another queue on RabbitMQ?

Using RabbitMQ as broker, I would like to copy all the messages from one queue to another queue for test/debug purpose. What's the simplest way via RabbitMQ web management console / cli?
P.S. Under web console for specified queue, I could only Move messages instead of Copy messages to new queue.
When I need to perform such tasks, I do as follows (assuming you want to copy all of the messages from your reference queue):
create a fanout exchange or use the default one (amq.fanout) if he isn't bound to any queue
bind the reference queue to it
bind the "duplicate" queue to it
configure a shovel to send all the messages in the reference queue to the exchange you bound to both queues, with auto-delete set to "After initial length transferred"
But it does mean that if messages arrived to the reference queue through it's normal flow, they will end up at the top of the queue, with the "copied" messages behind/mixed with them
just create another queue with the same routing key if the exchange is a direct exchange
Go to http://localhost:15672/#/queues
Create vhost (vhost=testhost)
Create two queue using vhost( Test1, Test2)
Create exchange Test_exchange: http://localhost:15672/#/exchanges
Bind these queue(Test1 & Test2) on Test_exchange
Install shovel
sudo rabbitmq-plugins enable rabbitmq_shovel
sudo rabbitmq-plugins enable rabbitmq_shovel_management
Add shovel using admin shovel tab
URI: amqp://{user}:{pass}#{localhost}:5672/vhost (this is for reference queue which u want to create copy, vhost if it has)
source
Destination URI: amqp://user:pass#localhost:5672/Test_exchnage
Queue Name: “Test_exchange”
You can can send msg to your reference queue.
There's a commercial tool, QueueExplorer (disclaimer - I'm the author) which allows you to copy messages, among other things.

Rabbitmqctl usage to do configuration

I am using RabbitMq on windows. I am trying to explore rabbitmqctl options.
i could see options to purge queue, create and delete shovels.
can you please tell me the rabbitmqctl usage to,
1. Create and delete exchange
2. Create and delete queues.
3. Bind and unbind queues.
i am trying to write scripts that can automate all the configurations based on input.
Look at rabbitmqadmin tool, it ships with RabbitMQ Management Plugin. It can declare/delete exchanges/queues/bindings.
Also look at this question and this post.
Just google "rabbitmqadmin your action"
Also you can use Management REST API

Is it posible to make a queue non durable in rabbitMq management portal

Is it possible to make a queue non durable in rabbitMq management portal or via the command line tool ?
If queue or exchange was once declared you can't change it parameters. Not via management plugin nor via CLI nor via API or else. If you want to have queue or exchange with the same name but different parameters, you have to delete existent one and then create new with desired parameters (don't forget to bind queue if you do that).
Note, that policies differs from parameters and they can be added, changed and deleted on existent queues and exchanges on-the-fly.
Also note, if you will delete and then create queue and/or exchanges, there are some chance to lost messages. For more details see RabbitMQ change queue parameters on a production system and Toggle routing in Rabbit MQ questions on SO.

RabbitMQ mirroring queues and exchanges

Is it possible to use federations or shovels to mirror the creation of exchanges and queues on one server to another ?
All the examples I've seen of using shovels and federations use exchanges and queues that already exist on the servers. What I want to do is create an exchange on server A and have a federation or shovel re-create it on Server B then start to send messages to it.
If this cannot be done with a federation or shovel is there anyway of achieving this without using clustering, the connection between the two servers is not consistent so clustering isn't possible.
I'm running RabbitMQ on windows.
You can use the federation plug-in.
It supports the exchange exchange and the queue federation, in order to mirror the queues and exchanges you can configure a policies ( using the management console or command line),for example with this parameters:
Name: my_policy
Pattern: ^mirr\. <---- mirror exchanges and queues with prefix “mirr.”
Definition: federation-upstream-set:all
you can apply the configuration for exchanges and queues, as:
The pattern policy supports regular expression
In this way each new or old exchange or queue that starts with the prefix “mirr.” will be mirrored to the other broker.
I think this could solve your problem.
Unfortunately in this way it is not possible to do this, because the connection is a point-to-point connection. You have to link a exchange with a remote exchange and in your topology this cant be created automatically.
I had also this problem in the past. And how i resolved the problem was over a business logic side. If there was a need for a new Exchange/Queue "on the fly", my data input gateway recognized this and created on the local and on the remote exchange the new exchange and queues with the connection, before the message was sent to RabbitMQ.