I'm trying to configure an error channel for Spring Cloud Azure Service Bus Queue Stream Binder with no success. I've enabled the error channel via
spring:
cloud:
stream:
function:
definition: produce
bindings:
produce-out-0:
destination: service-bus-q-a
producer:
error-channel-enabled: true
And tried defining a @ServiceActivator
:
@ServiceActivator(inputChannel = "service-bus-q-a.errors")
public void errors(ErrorMessage receiveMsg) {
System.err.println("receive error msg: " + receiveMsg);
}
I've also tried on inputChannel = "errorChannel"
and inputChannel = "service-bus-qa.$Default.errors"
. Obviously I am missing something here but I couldn't find a working example.
EDIT: I'm using the following Supplier bean:
@Bean
Supplier<String> produce() {
return () -> {
String msg = "a message to produce";
LOG.info("Producing message: " + msg);
return msg;
};
}
According to the binding naming conventions , the name of the binding will be produce-out-0
. I can see that the message is indeed sent to service-bus-qa
(I have a consumer on the other side).
EDIT AND SOLUTION:
So it appears I had a problem with my environment, and after rebuilding it everything worked as expected and as Garry Russell's answer shows . Sorry for the time wasted. For posterity, this is exactly what worked for me:
When declaring a binding
spring:
cloud:
stream:
bindings:
produce-out-0:
destination: service-bus-q-a
producer:
error-channel-enabled: true
The error channel that will be created will be named {destination}.errors
, in this case service-bus-qa.errors
. In addition you have the global error channel errorChannel
that will also be called if an error occurs. So you can use either
@ServiceActivator(inputChannel = "service-bus-q-a.errors")
public void errors(ErrorMessage receiveMsg) {
System.err.println("receive error msg: " + receiveMsg);
}
To receive the errors from service-bus-qa
or
@ServiceActivator(inputChannel = "errorChannel")
public void errors(ErrorMessage receiveMsg) {
System.err.println("receive error msg: " + receiveMsg);
}
To receive the error from the global error channel.
I just tested it with this yaml and the property is true
as expected.
spring:
cloud:
stream:
bindings:
output:
producer:
error-channel-enabled: true
azure:
servicebus:
connectionString: Endpoint=sb://foo.bar
Are you sure your producer name ( produce-out-0
) is correct?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.