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.convertAndSend(message);

从交换中读取:

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

(我需要设置交换运行时,因为我是从数据库中获取的)

msg总是null

4

1 回答 1

0

根据文档null,如果队列中没有任何内容,receiveAndConvert 方法可以返回。

于 2013-10-22T20:04:42.817 回答