Autowiring of exchange, queue and binding with Spring AMQP + RabbitMQ (Spring Boot) - rabbitmq

In the Spring docs for Messaging with RabbitMQ, rabbitTemplate, queue, exchange and binding are all set up by Spring Boot. What I don't understand is how rabbitTemplate.convertAndSend(...) sends it to the created exchange, since the method call does not specify an exchange and it includes only the routing key (via the queue name) and the message itself - which I thought implicitly sends the message to the default exchange and not the created exchange. The message will reach the intended queue since the routing key matches the name of the queue.
If I wanted to specify the exchange and routing key, using this API method:
// Convert a Java object to an Amqp Message and send it to
// a specific exchange with a specific routing key.
convertAndSend(String exchange, String routingKey, Object object);
... how do I get a reference to the created exchange?
Thanks.

Boot's RabbitAutoConfiguration only registers the connection factory, a RabbitAdmin a RabbitTemplate and a RabbitMessagingTemplate.
That guide declares its own exchange, queue, and binding.
You can simply #Autowire the exchange as normal and call getName().

Related

I want to a send message to a specific consumer in RabbitMQ. Do you have a solution?

I want to a send message to a specific consumer in RabbitMQ. Do you have a solution?
In RabbitMQ, you cannot send a message to a specific consumer. You maintain a queue for the specific consumer which listens to that queue. Then, you route the message to the queue using a routing key. You can use a exchange which routes the specific message to the specific queue.

Proper routing key for exchange to exchange binding in RabbitMQ

I'm looking for a way to make
hierarchical routing in RabbitMQ. I tried to find the answer in documentation, but suddenly failed.
Generally, RabbitMQ allows you to connect to direct exchanges by some routing key but it is not clear for me how I can route between several exchanges.
For instance, let's say we have 'root' exchange and 'host1' exchange with routing key 'host1'. And I have a queues binded to 'host1' exchange by routing key their own pids.
Can I publish message to 'root' exchange with routing_key, like 'host1.31261'? Obviously, it doesn't work exactly that way but is there a way to make a complex route with different direct exchanges?
yes, you can do this
you can use exchange to exchange bindings for this
you can include routing keys for this binding
the exchange type for both the original and target can be any type you want. need a topic exchange for complex routing? then declare your exchanges as topic.
you can even go from a topic exchange of host to a direct or fanout exchange as the target.
the key is just to declare each exchange as it needs to be declared, before you do the binding.
the examples shown in that documentation include java and .net code. you'll need to check with the library that you are using for your specific language.
in general, though, the same binding for queues works for exchanges. you just need to call the equivalent "bind exchange" method, instead of "bind queue"
if your library doesn't support it, you can manually add the binding via the RabbitMQ management web site.

Push message from HTTP endpoint to JMS endpoint in Mule

I am new to Mule ESB. Currently i am handling a project, where we are using Mule as message broker. Requirement is client will call a SOAP web service (request-response) published in Mule ESB. In the server request will be accepted and return a correlation id in the ws response to the client, but at the same time service will also put request payload in the JMS queue for async processing. The JMS queue is also maintained in the Same Mule ESB. Could you please help me how HTTP endpoint can push to JMS endpoint in Mule ESB?
This is very simple, if you want to put your soap request in a JMS queue along the call to the SOAP web service exposed in the Mule, then what you can do is after your HTTP listener in the flow, you need to put a Async block (reference :- https://docs.mulesoft.com/mule-user-guide/v/3.6/async-scope-reference) and in that Async block you can use Object to String Transformer followed by you JMS outbound end point.
This Async block block will create a separate thread from the flow and will push your SOAP request to the JMS queue along with your SOAP web service which accept the request and return a correlation id in the ws response to the client as you reuired.
Remember anything you put inside <async/> is considered as an async block and will used as a separate thread. You need to put this after your HTTP listener in the flow as mentioned above.

Deliver message to consumer and expect response in RabbitMQ

I have a requirement where in (RabbitMQ)server sends the request to the client and client executes the operation and sends the response back to the server.
I would like to know which mechanism to use for this Topic, PubSub, Routing...
Can we create the bi-directional connection like server-client similar to xmpp in rabbit mq, if yes how can we do?
thanks
Lokesh
You can use a Spring AMQP asynchronous consumer with a MessageListenerAdapter to invoke a POJO. See the reference documentation.
If you want more control; use a simple MessageListener and send the reply with a RabbitTemplate.
This test case shows an end-to-end configuration (client side and server side). The client side automatically takes care of setting the correlationId.

Where to use One way message exchange in WCF?

I'm thinking of what should be practical example of using WCF one way message exchange,
since I'm concerned about success or failure of any operation which I send to WCF service
and in one way message exchange - WCF service does not report success or failure of operation.
When your binding is MSMQ, you must use one-way operations.
All service operations must be one-way because the default queued binding in WCF does not support duplex communication using queues - Queuing in WCF
Plus, callbacks to a possible client regardless of protocol should be one-way in case the client has snuffed it.