Closed alexdjachenko closed 1 year ago
@alexdjachenko thanks for raising this. You are completely right, it appears that I missed out the code for sending messages to an exchange! I've not used rabbit in a while but I will take a look.
Edit: Maybe didn't miss the code after all but perhaps needs some more logic to account for when the exchange is defined. Probably around here: https://github.com/ansible-collections/community.rabbitmq/blob/eb750b027c9abd7fb741bee6fd81f30b9ad337fd/plugins/module_utils/rabbitmq.py#L192
Needs some more logic around handling exchanges and queue is None
.
My ref... a lot of this is in https://www.rabbitmq.com/tutorials/tutorial-three-python.html
@alexdjachenko this probably needs a bit of a tidy up, but, I've tested rabbitmq by creating a exchange (test_exchange
) which fans out to two queues (queue1
& queue2
). By specifying an empty queue with an exchange the module then does not create a random queue and utilises the exchange.
- name: Testing publishing to rabbitmq exchanges
hosts: localhost
gather_facts: no
tasks:
- name: RabbitMQ to exchange
community.rabbitmq.rabbitmq_publish:
exchange: test_exchange
queue: ""
url: "amqp://guest:guest@172.16.10.10:5672/%2F"
body: "Hello world exchange from ansible module rabbitmq_publish"
content_type: "text/plain"
I'll have a look at how to make it a bit more user friendly. :)
Edit: I was wrong, it looks like it the above example posts to both the exchange and creates a random queue. Looking into a fix.
@Im0 thanks a lot for your answer! Yes, I've tested it too. The routing really works, but every launch creates a random queue. I'll be whait your fix with hope and gratitude :) About friendly design, I think en example with exchange in the documentation could help :)
@alexdjachenko do you mind testing the pull request above? I hope it fixes the issue you're seeing with the random queues when an exchange is specified but no queue.
Hi @alexdjachenko - did you get a chance to test the change in https://github.com/ansible-collections/community.rabbitmq/pull/140 ? If you can test locally it would be greatly appreciated (it works for me).
Make a backup of your local files and you'll need to copy the following files into place:
I'm eager to roll this out into a new rabbitmq colection release.
Hi @Im0, sorry for long answer. I'll test it next week.
No worries @alexdjachenko , thank you. :) I'm pretty sure that you will be happy.
Hi @alexdjachenko - I'm going to close this issue now, however, feel free to re-open it if you have any more issues. I'll roll out community.rabbitmq collection v1.2.3 in the coming days, however, if you backup and copy the files previously mentioned into place you'll be able to utilise the fixes immediately.
SUMMARY
All examples of rabbitmq_publish demonstate only publishing to queue, but main publishing method in rabbitmq should work with exchanges. Becouse only exchanges could me configurate for routing. There is options "exchanges", but it doesn't work: when I try publish message to exchange without queue, it post it to random queue and routing is ignored.
ISSUE TYPE
COMPONENT NAME
rabbitmq_publish
ANSIBLE VERSION
STEPS TO REPRODUCE
EXPECTED RESULTS
Message in 'myexchange' exchange point and routing it to queue by preset rules.
ACTUAL RESULTS
Message in random queue without any routing