Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
RabbitMQ add users configure queues
#!/bin/bash
VHOST=project
EXCHANGE=project-exchange
ADMIN_USER=admin
ADMIN_PASS=secret
MGMT_USER=mgmt
MGMT_PASS=secret
QUEUE1=queue1
QUEUE2=queue2
QUEUE3=queue3
# RabbitMQ
apt install -y -t stretch-backports rabbitmq-server
# Remove guest user
rabbitmqctl delete_user guest
# Enable admin
rabbitmq-plugins enable rabbitmq_management
curl http://localhost:15672/cli/rabbitmqadmin > /usr/local/sbin/rabbitmqadmin
chmod +x /usr/local/sbin/rabbitmqadmin
# Add users
rabbitmqctl add_vhost ${VHOST}
rabbitmqctl add_user ${ADMIN_USER} ${ADMIN_PASS}
rabbitmqctl add_user ${MGMT_USER} ${MGMT_PASS}
rabbitmqctl set_user_tags ${ADMIN_USER} administrator
rabbitmqctl set_user_tags ${MGMT_USER} management
rabbitmqctl set_permissions -p ${VHOST} ${ADMIN_USER} ".*" ".*" ".*"
rabbitmqctl set_permissions -p ${VHOST} ${MGMT_USER} ".*" ".*" ".*"
# Add queues
rabbitmqadmin -u${ADMIN_USER} -pvagrant declare exchange --vhost=${VHOST} name=${EXCHANGE} type=direct durable=true
rabbitmqadmin -u${ADMIN_USER} -pvagrant declare queue --vhost=${VHOST} name=${QUEUE1} durable=true auto_delete=false
rabbitmqadmin -u${ADMIN_USER} -pvagrant declare queue --vhost=${VHOST} name=${QUEUE2} durable=true auto_delete=false
rabbitmqadmin -u${ADMIN_USER} -pvagrant declare queue --vhost=${VHOST} name=${QUEUE3} durable=true auto_delete=false
rabbitmqadmin -u${ADMIN_USER} -pvagrant declare binding --vhost=${VHOST} source=${EXCHANGE} destination=${QUEUE1}
rabbitmqadmin -u${ADMIN_USER} -pvagrant declare binding --vhost=${VHOST} source=${EXCHANGE} destination=${QUEUE2}
rabbitmqadmin -u${ADMIN_USER} -pvagrant declare binding --vhost=${VHOST} source=${EXCHANGE} destination=${QUEUE3}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.