2015-09-30 39 views
0

我在扇出交換中使用RabbitMQ時遇到了一個問題,由於某些未知原因,它表現得像直接交換一樣。扇形交換在春季AMQP中直接交換行爲AMQP

我使用的是下面的結合和隊列配置

<bean id="testfanout" 
     class="com.test"> 
     <constructor-arg name="exchange" ref="test" /> 
     <constructor-arg name="routingKey" value="test" /> 
     <constructor-arg name="queue" value="testQ" /> 
     <constructor-arg name="template"> 
      <bean class="org.springframework.amqp.rabbit.core.RabbitTemplate"> 
       <constructor-arg ref="connectionFactory" /> 
      </bean> 
     </constructor-arg> 
     <constructor-arg value="true"/> 
    </bean> 

<rabbit:fanout-exchange name="test" id="test"> 
     <rabbit:bindings> 
      <rabbit:binding queue="test"/> 
     </rabbit:bindings> 
</rabbit:fanout-exchange> 

現在我們有一個相同的代碼聽同一testQ在兩個不同的虛擬機,但不知何故消息使用循環算法

發送到一個VM監聽器

發件人代碼

channel = ... 
RabbitTemplate template = null; 
      if(channel != null){ 
       template = channel.getTemplate(); 
       if(template != null){ 
        template.setQueue(channel.getQueue()); 
        template.setExchange(channel.getExchange().getName()); 
        template.convertAndSend(channel.getRoutingKey(), txtMsg); 
+0

fanout更新交換它的而不是 Akshat

回答

1

路由鍵被忽略了扇出交換。

你確定它是rabbitmq中的一個扇出交換嗎?在配置中我沒有看到RabbitAdmin(它會嘗試聲明交換和綁定)。

看看你在RabbitMQ UI中的交換並檢查類型/綁定。