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
。