Search code examples
spring-integrationspring-cloud-streamspring-rabbit

Automatically publish errors from errorChannel to the specific destination


This documentation says, that it is possible to automatically send error messages from global errorChannel to specific destination, the only thing needed is to set the following property:

spring.cloud.stream.bindings.error.destination

I am really confused with this part. Just adding property doesn't work (I use RabbitMQ, Exchange and Queue are configured). So I can see error handled by @ServiceActivator in my application, but it is not sent to "myErrors" exchange in RabbitMQ. Looks like this property does not define outbound binding for errorChannel.

If I create output "error" channel explicitly in my application,

/**
 * Error channel name.
 */
String ERROR_ONE = "error";

@Output(MySink.ERROR_ONE)
MessageChannel errorOne();

and explicitly send error message to it from my global handler, for example by declaring outputChannel:

@ServiceActivator(inputChannel = "errorChannel", outputChannel = "error")
public ErrorMessage errorGlobal(ErrorMessage message) {
    System.out.println("Handling ERROR GLOBAL SA: " + message);
    return message;
}

it will work. But this can be done to binding-specific handlers also, so there is nothig errorChannel-specific here.

The question: Do I miss something? Can publish be done without defining outbound channels explicitly?


Solution

  • That documentation about ...binding.errors... is obsolete and needs to be fixed.

    You should use auto-bind-dlq and republish-to-dlq instead and the framwork will publish the failed message to the dlq, with additional headers with information about the failure.