Fanout交换在Spring AMQP中表现为直接交换

时间:2015-09-30 06:32:54

标签: rabbitmq messaging amqp spring-amqp spring-rabbit

我在扇出交换中使用RabbitMQ时遇到了一个问题,由于一些未知的原因,它表现得像直接交换。

我正在使用以下绑定和队列配置

<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>

现在我们在两个不同的VM上使用相同的代码侦听相同的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);

1 个答案:

答案 0 :(得分:1)

扇出交换忽略路由键。

你确定它实际上是rabbitmq的扇出交换吗?我没有在你的配置中看到RabbitAdmin(它会尝试声明交换和绑定)。

在RabbitMQ UI中查看您的交换并检查类型/绑定。