ansible-collections / community.rabbitmq

Manage RabbitMQ with Ansible
http://galaxy.ansible.com/community/rabbitmq
Other
30 stars 46 forks source link

Support headers in queue_declare function #174

Open V4UIDev opened 1 month ago

V4UIDev commented 1 month ago
SUMMARY

Add headers when running the declare queue function.

ISSUE TYPE
COMPONENT NAME

RabbitMQ Publish basic_publish

ADDITIONAL INFORMATION

When running the following Ansible task:

    - name: Send reindex message to queue
      community.rabbitmq.rabbitmq_publish:
        url: "amqp://user:password@192.168.0.1:5672/%2F"
        queue: "example"
        body: '{ "type": "example" }'
        content_type: "application/json"
        durable: true
        headers: 
          x-max-priority: 15
        delegate_to: localhost

The task would fail adding the message to the queue, due to the headers not being passed in correctly. This pull request addresses that and adds the headers to the message.

Before:

fatal: [192.168.0.1 -> localhost]: FAILED! => changed=false 
  msg: 'Queue declare issue: (406, "PRECONDITION_FAILED - inequivalent arg ''x-max-priority'' for queue ''example'' in vhost ''/'': received none but current is the value ''15'' of type ''signedint''")'

After:

changed: [192.168.0.1-> localhost] => changed=true 
  result:
    content_type: application/json
    msg: Successfully published to queue example
    queue: example

It has also been tested without passing in headers, and the play still functions as before.

V4UIDev commented 1 week ago

@Andersson007 @csmart could I get a review of this please?

Andersson007 commented 1 week ago

@V4UIDev hello, thanks for the PR!

csmart commented 1 week ago

@V4UIDev thanks for the contribution and fixing up this missing component! I think some tests would be great, if you have the time. That will help us to keep on top of this in the future. Thanks!

Andersson007 commented 2 days ago

@V4UIDev if you have any questions, please let us know