If the requirement is to keep track of the error messages for downstream processing, you could use the OOTB DLQ mechanics associated with Spring Cloud Stream. It is supported both in Rabbit and Kafka. You could enable DLQ in Spring Cloud Data Flow (SCDF) as a global setting or by per stream basis.
If you'd still like to define your custom channels to handle the messages differently, you'd have to create a custom interface similar to this sample.
While deploying the stream in SCDF, you can then override the destinations between producer and consumer via spring.cloud.stream.kafka.bindings.<channelName>.producer
and spring.cloud.stream.kafka.bindings.<channelName>.consumer
binding properties respectively.
EDIT:
Though there's the above approach, I learned about a much simpler solution from Spring Cloud Stream lead (@marius-bogoevici).
There is already a default error channel that's available for use and Spring Integration backs it.
With this, in your app, you could send custom messages to the default error channel via: @Autowire @Qualifier("errorChannel")
. In fact, this support is also available for all the OOTB applications.
You could then override the destination of this error channel via: spring.cloud.stream.bindings.error.destination=errorchannel-test
.In SCDF, you'd pass this at the time of stream deployment via: --properties
.
For example:
stream create foo --definition "mysource | log"
stream deploy foo --properties "app.mysource.spring.cloud.stream.bindings.error.destination=errorchannel-test"