我不明白的東西。 我使用Spring集成從RabbitMQ的發送和接收消息。直接交換不使用默認工作routingKey
我的拓撲結構是非常簡單的:
一個使用Spring的RabbitTemplate
<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的隊列接收該消息
<rabbit:queue name="${queue.name}" durable="true" />
另一個JVM消耗JVM生成消息該消息(啓動Spring-Batch作業,但是這不是點):
<int-amqp:inbound-channel-adapter queue-names="${queue.name}" channel="amqp-requests" connection-factory="rabbitConnectionFactory" />
使用的發送方法是:
/**
* 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;
它工作正常,但根據文件,我不認爲routingKey是強制性在我的用例。我不知道爲什麼有人放置了一個routingKey。
所以我試圖刪除routingKey:
<bean id="amqpTemplate" parent="rabbitTemplate">
<property name="queue" value="${queue.name}" />
</bean>
然後我還可以將消息發送到隊列,但他們永遠不會再消耗! 有人可以解釋我是怎麼回事? 我不能從一個JVM將消息發送到另一個沒有routingKey?
感謝,我現在明白了:) –