Creating an exchange if it does not exist with Logstash - rabbitmq

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?

Related

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

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

Connect multiple rabbitMQ to each other

I have been searching, and I couldn't find if it is possible to connect two rabbitmq instances together. I am thinking of this as an alternative to RabbitMQ Clustering feature.
My goal is that for each message that a broker receives, it routes to another broker. Does the exchange or queues in rabbitMQ allow to have this architecture?
Producer -> Broker <-> Broker -> Consumer
You can use exchange federation to publish to both the original broker and another (downstream) broker.

How to create a topic exchange in Qpid JMS for ActiveMQ like RabbitMQ?

I've got a Java application that uses RabbitMQ. This application creates a TOPIC exchange and pushes messages to the TOPIC with its own routing key. From this way if I want the data from any application I create a queue binding with the exchange TOPIC and the routing key I want to.
I want to do the same thing by using a Java application with Qpid JMS as the client and ActiveMQ as the server. The information says it's possible, but I don't know how. I cannot found a specific example seems to RabbitMQ. I can create queues but I don't know how to create the exchange and the binding. What steps should I follow to achieve it?
You might consider using ActiveMQ Artemis instead of ActiveMQ 5.x as the address model of Artemis is much more similar to RabbitMQ's than 5.x's address model (which is more JMS-centric).
As far as JMS goes I think what you need is:
A topic. This is analogous to the "exchange" from RabbitMQ. Any message sent to a JMS topic is delivered to every subscriber. It's basic publish/subscribe semantics.
A topic subscriber with a selector. As noted in #1, every subscriber on a topic will get any message sent to that topic, but a JMS "selector" can be used to filter messages similar to the routing key in RabbitMQ.
An agreed-upon key for a message property. In order to create a viable selector for the topic subscriber the producer and the subscriber must agree upon the property key to filter on.
If each subscription is going to have lots of messages and those messages need to be shared among multiple subscribers/consumers (e.g. for load-balancing/distribution) then you will need to use a JMS "shared subscription." However, shared subscriptions are only part of JMS 2 and only ActiveMQ Artemis implements JMS 2. You can't use ActiveMQ 5.x with JMS shared subscriptions as it only supports JMS 1.1.
Both ActiveMQ 5.x and ActiveMQ Artemis create server-side resources (e.g. topics, queues, etc.) on-demand by default so all you need to do is write your JMS application.

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.