Shell脚本-RabbitMQ创建队列
一、脚本
#!/bin/bash
vhost=test_host
vuser=admin
vpwd=admin
rabbitmqctl add_user $vuser $vpwd
rabbitmqctl set_user_tags $vuser administrator
rabbitmqctl add_vhost $vhost
rabbitmqctl set_permissions -p $vhost $vuser ".*" ".*" ".*"
rabbitmqctl eval 'rabbit_exchange:declare({resource, <<"'$vhost'">>, exchange, <<"exchange-collect">>}, topic, true, false, false, []).'
rabbitmqctl eval 'rabbit_exchange:declare({resource, <<"'$vhost'">>, exchange, <<"exchange-dispatch">>}, topic, true, false, false, []).'
rabbitmqctl eval 'rabbit_amqqueue:declare({resource, <<"'$vhost'">>, queue, <<"queue-collect-finish">>}, true, false, [], none).'
rabbitmqctl eval 'rabbit_amqqueue:declare({resource, <<"'$vhost'">>, queue, <<"queue-collect-finish-oms">>}, true, false, [], none).'
rabbitmqctl eval 'rabbit_binding:add({binding, {resource, <<"'$vhost'">>, exchange, <<"exchange-collect">>}, <<"route.collect.cms">>, {resource, <<"'$vhost'">>, queue, <<"queue-collect-finish">>}, []}).'
rabbitmqctl eval 'rabbit_binding:add({binding, {resource, <<"'$vhost'">>, exchange, <<"exchange-collect">>}, <<"route.collect.cms_oms">>, {resource, <<"'$vhost'">>, queue, <<"queue-collect-finish">>}, []}).'
rabbitmqctl eval 'rabbit_amqqueue:declare({resource, <<"'$vhost'">>, queue, <<"queue-collect-finish-bak">>}, true, false, [], none).'
rabbitmqctl eval 'rabbit_amqqueue:declare({resource, <<"'$vhost'">>, queue, <<"queue-collect-finish-oms-bak">>}, true, false, [], none).'
rabbitmqctl eval 'rabbit_binding:add({binding, {resource, <<"'$vhost'">>, exchange, <<"exchange-collect">>}, <<"route.collect.cms">>, {resource, <<"'$vhost'">>, queue, <<"queue-collect-finish-bak">>}, []}).'
rabbitmqctl eval 'rabbit_binding:add({binding, {resource, <<"'$vhost'">>, exchange, <<"exchange-collect">>}, <<"route.collect.cms_oms">>, {resource, <<"'$vhost'">>, queue, <<"queue-collect-finish-bak">>}, []}).'
二、注意
使用RabbitMQ 3.7+版本,命令中必须添加用户,否则报ERROR
rabbitmqctl eval 'rabbit_exchange:declare({resource, <<"'$vhost'">>, exchange, <<"exchange-collect">>}, topic, true, false, false, [],$vuser).'

浙公网安备 33010602011771号