Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import broker definitions into Dockerized RabbitMQ

I have a RabbitMQ broker with some exchanges and queues already defined. I know I can export and import these definitions via the HTTP API. I want to Dockerize it, and have all the broker definitions imported when it starts.

Ideally, it would be done as easily as it is done via the API. I could write a bunch of rabbitmqctl commands, but with a lot of definitions this might take quite a some time. Also, every change somebody else makes through the web interface will have to be inserted.

I have managed to do what I want by writing a script that sleeps a curl request and starts the server, but this seems to be error prone and really not elegant. Are there any better ways to do definition importing/exporting , or is this the best that can be done?

My Dockerfile:

FROM rabbitmq:management
LABEL description="Rabbit image" version="0.0.1"
ADD init.sh /init.sh          
ADD rabbit_e6f2965776b0_2015-7-14.json /rabbit_config.json         
CMD ["/init.sh"]

init.sh

sleep 10 && curl -i -u guest:guest -d @/rabbit_config.json -H "content-type:application/json" http://localhost:15672/api/definitions -X POST &

rabbitmq-server $@
like image 641
Dumitru Avatar asked Feb 10 '23 14:02

Dumitru


1 Answers

  1. Export definitions using rabbitmqadmin export rabbit.definitions.json.

  2. Add them inside the image using your Dockerfile: ADD rabbit.definitions.json /tmp/rabbit.definitions.json

  3. Add an environment variable when starting the container, for example, using docker-compose.yml:

     environment:
       - RABBITMQ_SERVER_ADDITIONAL_ERL_ARGS=-rabbitmq_management load_definitions "/tmp/rabbit.definitions.json"
    
like image 153
andrey Avatar answered Feb 13 '23 03:02

andrey