Quarkus - SmallRye Reactive Messaging - RabbitMQ: Send message to default exchange - rabbitmq

Using the remote procedure call pattern, I need to send an answer to a reply-queue, i.e. I need to send the message to the default exchange with the name of the queue as the routing key.
I am using the SmallRye Reactive Messing RabbitMQ plugin on Quarkus. All channels are defined statically in the configuration files (which is ok), however, due to the way the configuration mechanism works (microprofile config), I cannot use the empty string as a configuration value, which is the name of the default exchange.
It does not help to omit the name of the exchange, as by default the channel name is used.
Is there a way to send a message to the default exchange using the SmallRye RabbitMQ plugin?
Edit: I have no control over the RabbitMQ server.

You should be able to send messages to the default direct RabbitMQ exchange by setting below attributes:
exchange.name (set to empty string)
exchange.type (set to direct)
Assuming your Reactive Messaging channel is named pets-out, here down a configuration sample:
mp.messaging.outgoing.pets-out.connector=smallrye-rabbitmq
mp.messaging.outgoing.pets-out.exchange.name=
mp.messaging.outgoing.pets-out.exchange.declare=false
mp.messaging.outgoing.pets-out.exchange.type=direct
mp.messaging.outgoing.pets-out.default-routing-key=pets
EDIT
After digging into smallrye-reactive-messaging implementation, I figured out that an empty exchange name will cause a fallback to the channel name as the exchange name.
Hence, there should be no way to send direct messages to the default RabbitMQ exchange.
The alternative solution, neglecting the out-of-the-box offered default exchange would be to
Create a direct exchange without any bound queues and have the Outgoing message handler using a dedicated channel config bound to it:
mp.messaging.outgoing.pets-out.connector=smallrye-rabbitmq
mp.messaging.outgoing.pets-out.exchange.name=my-direct
mp.messaging.outgoing.pets-out.exchange.declare=true
mp.messaging.outgoing.pets-out.exchange.type=direct
mp.messaging.outgoing.pets-out.default-routing-key=pets
Create an alternate exchange configuration for the my-direct exchange routing messages to the default one. This can be operated on the RabbitMQ broker directly using rabbitmqctl:
rabbitmqctl set_policy AE "^my-direct$" '{"alternate-exchange":""}' --apply-to exchanges

Related

How to use activemq wildcards for sending messages

I try to send message to multiple queues according this documentation ActiveMQ Wildcards. The idea is to send message to PRICE.> queue and receive them in queues PRICE.STOCK.NASDAQ.ORCL and PRICE.STOCK.NYSE.IBM (queues are created). But instead of forwarding messages to PRICE.STOCK.NASDAQ.ORCL and PRICE.STOCK.NYSE.IBM activemq create new queue PRICE.> that become this message.
I tried to send message with activemq admin tool (send mask) and spring boot application. Behavior is the same - message is placed in new created queue PRICE.>.Activemq was not additionally configured, I'm using configuration provided with activemq 5.15.7.
The feature is only supported for subscribers, you need to send to a specific named destination when publishing a message. You can use the Virtual Destinations feature of ActiveMQ to define a target destination that forwards to some defined set.

How to copy messages to another queue on RabbitMQ?

Using RabbitMQ as broker, I would like to copy all the messages from one queue to another queue for test/debug purpose. What's the simplest way via RabbitMQ web management console / cli?
P.S. Under web console for specified queue, I could only Move messages instead of Copy messages to new queue.
When I need to perform such tasks, I do as follows (assuming you want to copy all of the messages from your reference queue):
create a fanout exchange or use the default one (amq.fanout) if he isn't bound to any queue
bind the reference queue to it
bind the "duplicate" queue to it
configure a shovel to send all the messages in the reference queue to the exchange you bound to both queues, with auto-delete set to "After initial length transferred"
But it does mean that if messages arrived to the reference queue through it's normal flow, they will end up at the top of the queue, with the "copied" messages behind/mixed with them
just create another queue with the same routing key if the exchange is a direct exchange
Go to http://localhost:15672/#/queues
Create vhost (vhost=testhost)
Create two queue using vhost( Test1, Test2)
Create exchange Test_exchange: http://localhost:15672/#/exchanges
Bind these queue(Test1 & Test2) on Test_exchange
Install shovel
sudo rabbitmq-plugins enable rabbitmq_shovel
sudo rabbitmq-plugins enable rabbitmq_shovel_management
Add shovel using admin shovel tab
URI: amqp://{user}:{pass}#{localhost}:5672/vhost (this is for reference queue which u want to create copy, vhost if it has)
source
Destination URI: amqp://user:pass#localhost:5672/Test_exchnage
Queue Name: “Test_exchange”
You can can send msg to your reference queue.
There's a commercial tool, QueueExplorer (disclaimer - I'm the author) which allows you to copy messages, among other things.

Creating an exchange if it does not exist with Logstash

I created a Logstash instance that has a RabbitMQ input. I specified the key, exchange and queue in the configuration of Logstash.
When looking at the RabbitMQ web interface some time later, I realized that the exchange and queue used by Logstash weren't automatically created in RabbitMQ. Is there a way to tune Logstash to create the exchanges and queues it needs in RabbitMQ, without having to create them with the web interface?

Is it posible to make a queue non durable in rabbitMq management portal

Is it possible to make a queue non durable in rabbitMq management portal or via the command line tool ?
If queue or exchange was once declared you can't change it parameters. Not via management plugin nor via CLI nor via API or else. If you want to have queue or exchange with the same name but different parameters, you have to delete existent one and then create new with desired parameters (don't forget to bind queue if you do that).
Note, that policies differs from parameters and they can be added, changed and deleted on existent queues and exchanges on-the-fly.
Also note, if you will delete and then create queue and/or exchanges, there are some chance to lost messages. For more details see RabbitMQ change queue parameters on a production system and Toggle routing in Rabbit MQ questions on SO.

RabbitMQ mirroring queues and exchanges

Is it possible to use federations or shovels to mirror the creation of exchanges and queues on one server to another ?
All the examples I've seen of using shovels and federations use exchanges and queues that already exist on the servers. What I want to do is create an exchange on server A and have a federation or shovel re-create it on Server B then start to send messages to it.
If this cannot be done with a federation or shovel is there anyway of achieving this without using clustering, the connection between the two servers is not consistent so clustering isn't possible.
I'm running RabbitMQ on windows.
You can use the federation plug-in.
It supports the exchange exchange and the queue federation, in order to mirror the queues and exchanges you can configure a policies ( using the management console or command line),for example with this parameters:
Name: my_policy
Pattern: ^mirr\. <---- mirror exchanges and queues with prefix “mirr.”
Definition: federation-upstream-set:all
you can apply the configuration for exchanges and queues, as:
The pattern policy supports regular expression
In this way each new or old exchange or queue that starts with the prefix “mirr.” will be mirrored to the other broker.
I think this could solve your problem.
Unfortunately in this way it is not possible to do this, because the connection is a point-to-point connection. You have to link a exchange with a remote exchange and in your topology this cant be created automatically.
I had also this problem in the past. And how i resolved the problem was over a business logic side. If there was a need for a new Exchange/Queue "on the fly", my data input gateway recognized this and created on the local and on the remote exchange the new exchange and queues with the connection, before the message was sent to RabbitMQ.