Skip to content

Instantly share code, notes, and snippets.

@garyrussell
Created June 8, 2017 17:58
Show Gist options
  • Save garyrussell/6dac9031feb9cfa73269d61b1c4f6f36 to your computer and use it in GitHub Desktop.
Save garyrussell/6dac9031feb9cfa73269d61b1c4f6f36 to your computer and use it in GitHub Desktop.
Spring Cloud Stream App That Consumes its own Dead Letters
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();
}
}
@GADNT
Copy link

GADNT commented Jun 20, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment