ansible-collections / community.rabbitmq

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

Allow to specify queue type in rabbitmq_queue module #114

Closed wrobell closed 1 year ago

wrobell commented 2 years ago

RabbitMQ has various types of queues

It would be great if we could specify queue type via rabbitmq_queue module.

Andersson007 commented 2 years ago

@wrobell hello and welcome to the project! Thanks for the issue! I've put the help_wanted label, so interested folks can pick it up

DavidLevayer commented 2 years ago

You can do it using the arguments parameter:

- name: create quorum queue
  community.rabbitmq.rabbitmq_queue:
    name: quorum_queue
    login_user: guest
    login_password: guest
    login_host: localhost
    arguments:
      x-queue-type: quorum
wrobell commented 2 years ago

I have finally found some time to revisit this.

@DavidLevayer I did try using the arguments parameter in the past, but it failed with an error.

After further investigation, this works:

    - name: Create RabbitMQ stream
      become: yes
      community.rabbitmq.rabbitmq_queue:
        name: test-x
        arguments:
          x-queue-type: stream
          x-max-age: 24h

Changing queue name to contain slash like

    - name: Create RabbitMQ stream
      become: yes
      community.rabbitmq.rabbitmq_queue:
        name: test-x/test-y
        arguments:
          x-queue-type: stream
          x-max-age: 24h

fails with error

Invalid response from RESTAPI when trying to check if queue exists

Using rabbitmqadmin declare queue I can create test-x/test-y stream, so it seems like there is a problem with the Ansible plugin.

Also, I believe, it would be worth having high-level queue type parameter for the plugin. If not, that's OK and I can close this ticket and open new one for the problem above.

Im0 commented 1 year ago

Hi @wrobell ,

WIth regard to your queue name test-x/test-y I feel like it's probably causing problems with the API request which is built in rabbitmq_queue like this:

    url = "%s://%s:%s/api/queues/%s/%s" % (
        module.params['login_protocol'],
        module.params['login_host'],
        module.params['login_port'],
        urllib_parse.quote(module.params['vhost'], ''),
        module.params['name']
    )

I'm wondering if the name argument needs to be escaped so it can be passed through to the URL as a name, not as an extension of the URL path.

Probably needs escaping here: https://github.com/ansible-collections/community.rabbitmq/blob/main/plugins/modules/rabbitmq_queue.py#L159

Does that sound about right?

Second thing would be to put @DavidLevayer 's example into the example documentation. Thanks for that David.

Im0 commented 1 year ago

Thanks @wrobell for raising this and @DavidLevayer for your input. This merge should fix the issue you raised regarding names like this "test-x/test-z" and the documentation enhanced with David's example.

You can start using this by copying the files into place from the github repo (don't forget to backup existing), or, we should be releasing v1.2.3 shortly. Follow #143 for progress. Ta.