Skip to content

Commit

Permalink
AMQP-502: Fix Fanout @binding Declaration
Browse files Browse the repository at this point in the history
JIRA: https://jira.spring.io/browse/AMQP-502

Queues are bound to fanout exchanges with no routing key.
The `RabbitListenerAnnotationBeanPostProcessor` incorrectly set the key to `null` instead of `""`.

Add a test for a fanout exchange.
  • Loading branch information
garyrussell authored and artembilan committed Jun 19, 2015
1 parent b0ff7a0 commit a287992
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Expand Up @@ -437,7 +437,7 @@ else if (exchangeType.equals(ExchangeTypes.FANOUT)) {
exchange = new FanoutExchange(exchangeName,
resolveExpressionAsBoolean(bindingExchange.durable()),
resolveExpressionAsBoolean(bindingExchange.autoDelete()));
actualBinding = new Binding(queueName, DestinationType.QUEUE, exchangeName, null, null);
actualBinding = new Binding(queueName, DestinationType.QUEUE, exchangeName, "", null);
}
else if (exchangeType.equals(ExchangeTypes.TOPIC)) {
exchange = new TopicExchange(exchangeName,
Expand Down
Expand Up @@ -98,6 +98,11 @@ public void autoDeclare() {
assertEquals("FOO", rabbitTemplate.convertSendAndReceive("auto.exch", "auto.rk", "foo"));
}

@Test
public void autoDeclareFanout() {
assertEquals("FOOFOO", rabbitTemplate.convertSendAndReceive("auto.exch.fanout", "", "foo"));
}

@Test
public void autoDeclareAnon() {
assertEquals("FOO", rabbitTemplate.convertSendAndReceive("auto.exch", "auto.anon.rk", "foo"));
Expand Down Expand Up @@ -191,6 +196,14 @@ public String handleWithDeclare(String foo) {
return foo.toUpperCase();
}

@RabbitListener(bindings = @QueueBinding(
value = @Queue(value = "auto.declare.fanout", autoDelete = "true"),
exchange = @Exchange(value = "auto.exch.fanout", autoDelete = "true", type="fanout"))
)
public String handleWithFanout(String foo) {
return foo.toUpperCase() + foo.toUpperCase();
}

@RabbitListener(bindings = {
@QueueBinding(
value = @Queue(),
Expand Down

0 comments on commit a287992

Please sign in to comment.