-
-
Save garyrussell/6dac9031feb9cfa73269d61b1c4f6f36 to your computer and use it in GitHub Desktop.
spring.cloud.stream.bindings.input.destination=foo | |
spring.cloud.stream.bindings.input.group=foo | |
spring.cloud.stream.rabbit.bindings.input.consumer.autoBindDlq=true | |
spring.cloud.stream.rabbit.bindings.input.consumer.deadLetterRoutingKey=foo | |
spring.cloud.stream.rabbit.bindings.input.consumer.republishToDlq=true | |
spring.cloud.stream.bindings.errors.group=foo.dlq | |
spring.cloud.stream.bindings.errors.destination=foo | |
spring.cloud.stream.rabbit.bindings.errors.bindQueue=false | |
spring.cloud.stream.rabbit.bindings.errors.declareExchange=false |
/* | |
* Copyright 2017 the original author or authors. | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software | |
* distributed under the License is distributed on an "AS IS" BASIS, | |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
* See the License for the specific language governing permissions and | |
* limitations under the License. | |
*/ | |
package com.example; | |
import org.springframework.boot.SpringApplication; | |
import org.springframework.boot.autoconfigure.SpringBootApplication; | |
import org.springframework.cloud.stream.annotation.EnableBinding; | |
import org.springframework.cloud.stream.annotation.Input; | |
import org.springframework.cloud.stream.annotation.StreamListener; | |
import org.springframework.cloud.stream.messaging.Sink; | |
import org.springframework.integration.annotation.ServiceActivator; | |
import org.springframework.messaging.Message; | |
import org.springframework.messaging.SubscribableChannel; | |
/** | |
* @author Gary Russell | |
*/ | |
@SpringBootApplication | |
@EnableBinding(Gitter2Application.Foo.class) | |
public class Gitter2Application { | |
public static void main(String[] args) { | |
SpringApplication.run(Gitter2Application.class, args); | |
} | |
@StreamListener(Sink.INPUT) | |
public void listen(String in) { | |
throw new RuntimeException("fail"); | |
} | |
@ServiceActivator(inputChannel = "errors") | |
public void handle(Message<?> failedMessage) { | |
System.out.println("Failed message " + failedMessage); | |
} | |
public interface Foo extends Sink { | |
@Input("errors") | |
SubscribableChannel errors(); | |
} | |
} |
That doesn't happen for me.
It looks like you, somehow, have the dlq also bound to the foo
exchange...
amqp_receivedExchange=foo,amqp_consumerQueue=foo.foo.dlq
In the first message. This will cause any message sent to the foo exchange will go to both the main queue and the DLQ.
The DLQ should only be bound to the DLX exchange.
I think I have found the issue. I have adjusted this:
spring.cloud.stream.rabbit.bindings.errors.bindQueue=false spring.cloud.stream.rabbit.bindings.errors.declareExchange=false
to:
spring.cloud.stream.rabbit.bindings.errors.consumer.bindQueue=false spring.cloud.stream.rabbit.bindings.errors.consumer.declareExchange=false
.
Now I see a normal behavior , the DLQ handle just the error.
Also an important note is : I was using springboot 1.4.2.RELEASE and springCloudVersion = 'Camden.SR5'..it should be upgraded to springCloudVersion = 'Camden.SR7'.
Thank for your guidance.
Hi Gary
thanks for this ..it's something that I meant to be in the first place but I observed that the serviceactivator are invoked two times ..one for input channel and one for the case when actually is needed to handle the error thrown.
Below you can find the logs when the message hits the channel and also the error was thrown:
Do you have any idea what is happening?
Thank you
Gabriel