Rabbitmq-publish not throwing error on invalid routing key

Sett 221 ganger
Hopp til første uleste melding

Yuharsen Ergi

ulest,
21. okt. 2021, 22:45:4921.10.2021
til rabbitmq-users
Hi all,
I am new in rabbitMQ. I am using https://github.com/alanxz/rabbitmq-c library.
I have an issue that the publish message function will not throwing error on invalid routing key. I've read the documentation in http://alanxz.github.io/rabbitmq-c/docs/0.8.0/amqp_8h.html#a9cada07768aa46297acdd701f96d0d7f that indeed it is how the publish function process works.
I've tried to call the bind function before publish the message and it will create a new binding key with given routing key if the routing key did not exists before. But this is not what I want the rabbitmq works. What I want is the unroutable publish message at least can be stored in dummy queue, or if the publish message process return error when publish the message to a routing key that doesn't exists then the rabbitclient publisher will still try to publish the message to rabbitmq-server.
I've read this information https://www.cloudamqp.com/blog/collecting-unroutable-messages-in-a-rabbitmq-alternate-exchange.html that the unroutable message can be collected with alternate-route with fanout exchange, but it gives the example in python.
How I can do this but in C programming language apart setting in from the rabbitmq-server?

Thank you.

Michal Kuratczyk

ulest,
25. okt. 2021, 16:47:1625.10.2021
til rabbitm...@googlegroups.com
Hi,

You don't have to do anything in your application's code - just configure the alternate exchange through a policy as recommended:

For example:
# declare a new exchange
$ rabbitmqadmin declare exchange name=foo type=direct
exchange declared

# publish a message - it can't be routed (no queues bound to the exchange)
$ rabbitmqadmin publish exchange=foo payload="ping" routing_key=1234
Message published but NOT routed

# declare a new queue
$ rabbitmqadmin declare queue name=baz
queue declared

# bind the new queue to amq.fanout (one of the predefined exchanges)
$ rabbitmqadmin declare binding source=amq.fanout destination=baz
binding declared

# declare an alternate exchange for our exchange - when a message can't be routed, it goes to amq.fanout
$ rabbitmqadmin declare policy name=alter pattern='^foo$' definition='{"alternate-exchange":"amq.fanout"}'
policy declared

# publish the message again. - now it is published successfully
$ rabbitmqadmin publish exchange=foo payload="ping" routing_key=1234
Message published

# we can retrieve it from queue "baz"
$ rabbitmqadmin get queue=baz
+-------------+----------+---------------+---------+---------------+------------------+------------+-------------+
| routing_key | exchange | message_count | payload | payload_bytes | payload_encoding | properties | redelivered |
+-------------+----------+---------------+---------+---------------+------------------+------------+-------------+
| 1234        | foo      | 0             | ping    | 4             | string           |            | False       |
+-------------+----------+---------------+---------+---------------+------------------+------------+-------------+

--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-user...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/rabbitmq-users/43d859fc-723f-48ac-bc7c-7e7f350d838cn%40googlegroups.com.


--
Michał
RabbitMQ team
Svar alle
Svar til forfatter
Videresend
0 nye meldinger