diff --git a/changelogs/fragments/174-support-headers-publish.yml b/changelogs/fragments/174-support-headers-publish.yml new file mode 100644 index 0000000..6a536ac --- /dev/null +++ b/changelogs/fragments/174-support-headers-publish.yml @@ -0,0 +1,2 @@ +bugfixes: + - rabbitmq_publish - fix support for publishing headers as a part of a message (https://github.com/ansible-collections/community.rabbitmq/pull/174/) diff --git a/plugins/module_utils/rabbitmq.py b/plugins/module_utils/rabbitmq.py index 5f00acc..fddf8af 100644 --- a/plugins/module_utils/rabbitmq.py +++ b/plugins/module_utils/rabbitmq.py @@ -190,14 +190,16 @@ def basic_publish(self): result = self.conn_channel.queue_declare(queue='', durable=self.params.get("durable"), exclusive=self.params.get("exclusive"), - auto_delete=self.params.get("auto_delete")) + auto_delete=self.params.get("auto_delete"), + arguments=self.params.get("headers")) self.conn_channel.confirm_delivery() self.queue = result.method.queue elif self.queue is not None and self.exchange is None: self.conn_channel.queue_declare(queue=self.queue, durable=self.params.get("durable"), exclusive=self.params.get("exclusive"), - auto_delete=self.params.get("auto_delete")) + auto_delete=self.params.get("auto_delete"), + arguments=self.params.get("headers")) self.conn_channel.confirm_delivery() except Exception as e: self.module.fail_json(msg="Queue declare issue: %s" % to_native(e)) diff --git a/tests/integration/targets/rabbitmq_publish/tasks/ubuntu.yml b/tests/integration/targets/rabbitmq_publish/tasks/ubuntu.yml index 4136ae1..2942c46 100644 --- a/tests/integration/targets/rabbitmq_publish/tasks/ubuntu.yml +++ b/tests/integration/targets/rabbitmq_publish/tasks/ubuntu.yml @@ -179,10 +179,10 @@ - "'image/gif' in messages[1]['content_type']" - "'image.gif' in messages[1]['headers']['filename']" - "'Testing with proto/host/port/username/password/vhost' in messages[2]['msg']" -# - messages[3]['headers']['myHeader'] is defined -# - messages[4]['headers']['filename'] is defined -# - messages[4]['headers']['secondHeader'] is defined -# + - messages[4]['headers']['myHeader'] is defined + - messages[4]['headers']['secondHeader'] is defined + - "'Value2' in messages[4]['headers']['secondHeader']" + - name: Check that queue and exchange are mutually exclusive rabbitmq_publish: