I don’t understand something.
I’m using Spring Integration to send and receive messages from RabbitMQ.
My topology is pretty simple:
-
One JVM produce messages using the RabbitTemplate of Spring
<rabbit:template id="rabbitTemplate" connection-factory="rabbitConnectionFactory" /> <bean id="amqpTemplate" parent="rabbitTemplate"> <property name="queue" value="${queue.name}" /> <property name="routingKey" value="${queue.name}" /> </bean> -
RabbitMQ queue receive the message
<rabbit:queue name="${queue.name}" durable="true" /> -
Another JVM consume the message (to launch a Spring-Batch job, but that’s not the point):
<int-amqp:inbound-channel-adapter queue-names="${queue.name}" channel="amqp-requests" connection-factory="rabbitConnectionFactory" />
The send method used is:
/**
* Convert a Java object to an Amqp {@link Message} and send it to a default exchange with a default routing key.
*
* @param message a message to send
* @throws AmqpException if there is a problem
*/
void convertAndSend(Object message) throws AmqpException;
It works fine but according to the documentation, I don’t think the routingKey is mandatory in my usecase. I don’t know why someone put a routingKey.
So I tried to remove the routingKey:
<bean id="amqpTemplate" parent="rabbitTemplate">
<property name="queue" value="${queue.name}" />
</bean>
Then I can still send the messages to the queue, but they are never consumed anymore!
Can someone explain me what is going on?
Can’t I send messages from one JVM to another without a routingKey?
Which “documentation” are you referring to?
With AMQP, producers do not know about queues; they send messages to various types of exchanges which have bindings for routing to queues.
Maybe you are mis-understanding the notion of the default exchange, to which every
queueis bound, with arouting keyequal to itsqueue name.This allows simple routing to specific queues (by way of their names). The default exchange is a convenience to provide a quick on-ramp to amqp messaging. This works fine, but you might want to consider using explicitly declared exhanges instead, because it further decouples the producer from the consumer. With the default exchange the producer has to know the name of the queue that the consumer is listening on.
Further, on the RabbitTemplate, the
queueproperty is only used for receiving (consuming) messages, it has no bearing on sending messages; as I said producers don’t know about queues.You should use the following…