Akshat
Akshat

Reputation: 575

Fanout exchange behaving as Direct exchange in Spring AMQP

I am facing an issue while using RabbitMQ in the fanout exchange which due to some unknown reason is behaving like a direct exchange.

I am using a following binding and queue configuration

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

Now we have a same code listening to same testQ on two different VM's but somehow message is send to one VM listener using the round robin algorithm

Sender code

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

Upvotes: 0

Views: 615

Answers (1)

Gary Russell
Gary Russell

Reputation: 174484

The routing key is ignored for a fanout exchange.

Are you sure it's actually a fanout exchange in rabbitmq? I don't see a RabbitAdmin in your configuration (which would attempt to declare the exchange and binding).

Look at your exchange in the RabbitMQ UI and check the type/bindings.

Upvotes: 1

Related Questions