Skip to content

Commit

Permalink
feat(queues): create/delete queues using cli
Browse files Browse the repository at this point in the history
  • Loading branch information
noelmcloughlin committed Jun 9, 2021
1 parent 4108523 commit ec02702
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 9 deletions.
19 changes: 10 additions & 9 deletions pillar.example
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,16 @@ rabbitmq:

queue:
my-new-queue:
- user: saltstack
- passwd: 'password'
- durable: true
- auto_delete: false
- vhost: test_vhost
- arguments:
- 'x-message-ttl': 8640000
- 'x-expires': 8640000
- 'x-dead-letter-exchange': 'my-new-exchange'
## note : dict format
user: saltstack
passwd: 'password'
durable: true
auto_delete: false
vhost: test_vhost
arguments:
- 'x-message-ttl': 8640000
- 'x-expires': 8640000
- 'x-dead-letter-exchange': 'my-new-exchange'

exchange:
my-new-exchange:
Expand Down
1 change: 1 addition & 0 deletions rabbitmq/config/clean.sls
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ include:
- .policy.clean
- .plugin.clean
- .upstream.clean
- .queue.clean
- .vhost.clean
- .user.clean
- .file.clean
Expand Down
1 change: 1 addition & 0 deletions rabbitmq/config/init.sls
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ include:
- .file
- .user
- .vhost
- .queue
- .policy
- .plugin
- .upstream
Expand Down
19 changes: 19 additions & 0 deletions rabbitmq/config/queue/clean.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import mapdata as rabbitmq with context %}
{%- set sls_service_running = tplroot ~ '.service.running' %}
include:
- {{ sls_service_running }}
{% for name, q in salt["pillar.get"]("rabbitmq:queue", {}).items() %}
rabbitmq-config-queue-absent-{{ name }}:
cmd.run:
- name: /usr/local/sbin/rabbitmqadmin delete queue --vhost={{ q.vhost }} --username={{ q.user }} --password={{ q.passwd }} name={{ name }}
- require:
- service: {{ rabbitmq.service.name }}
{% endfor %}
5 changes: 5 additions & 0 deletions rabbitmq/config/queue/init.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

include:
- .install
21 changes: 21 additions & 0 deletions rabbitmq/config/queue/install.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import mapdata as rabbitmq with context %}
{%- set sls_service_running = tplroot ~ '.service.running' %}
include:
- {{ sls_service_running }}
{% for name, q in salt["pillar.get"]("rabbitmq:queue", {}).items() %}
rabbitmq-config-queue-present-{{ name }}:
cmd.run:
- name: /usr/local/sbin/rabbitmqadmin declare queue --vhost={{ q.vhost }} --username={{ q.user }} --password={{ q.passwd }} name={{ name }} durable={{ q.durable|to_bool|lower }} auto_delete={{ q.auto_delete|to_bool|lower }}
### note: arguments='{# q.arguments|json #}' causes "mapping values are not allowed in this context"
- require:
- service: {{ rabbitmq.service.name }}
{% endfor %}

0 comments on commit ec02702

Please sign in to comment.