2013-05-05 78 views
1

我以這種方式使用rabbitTemplate讀消息

<bean id="rabbitConnFactory" class="org.springframework.amqp.rabbit.connection.SingleConnectionFactory"> 
    <constructor-arg> 
     <value>localhost</value> 
    </constructor-arg> 
</bean> 

<!-- Spring AMQP Template --> 
<bean id="rabbitTemplate" class="org.springframework.amqp.rabbit.core.RabbitTemplate"> 
    <property name="connectionFactory" ref="rabbitConnFactory" /> 
</bean> 

<!-- Spring AMQP Admin --> 
<bean id="rabbitAdmin" class="org.springframework.amqp.rabbit.core.RabbitAdmin"> 
    <constructor-arg ref="rabbitConnFactory" /> 
</bean> 

發送到交換:

rabbitTemplate.setExchange(exchange); 
rabbitTemplate.setQueue(exchange);    //? 
Object msg = rabbitTemplate.receiveAndConvert(); 
return msg; 

(I:

rabbitTemplate.setExchange(exchange); 
rabbitTemplate.convertAndSend(message); 

從交換閱讀需要設置交換運行時間,因爲我從數據庫中得到它)

但是msg總是null

回答

0

根據documentation如果隊列中沒有任何東西,receiveAndConvert方法可以返回null