Handling errors thrown by producers in camel
paul.johansson Jul 14, 2016 7:55 AMThis case is when i put outbound references inside multicast in camel DSL then i'm unable to handle error thrown by outbound components. Let's say i trying to save file to non existing directory, after that i get FileNotFoundException and finally i can't catch this exception by the code below:
errorHandler(deadLetterChannel("switchyard://ErrorOutbound"));
onException(Throwable.class).to("switchyard://ErrorOutbound");
from("switchyard://InboundService")
.multicast()
.to("switchyard://Outbound")
.to("switchyard://Outbound")
.end()
.end();
Noting is going to switchyard://ErrorOutbound. So error handler or onException are unable to handle this, but when i wrap component into directs or pipelines then it start working as i expect.
errorHandler(deadLetterChannel("switchyard://ErrorOutbound"));
onException(Throwable.class).to("switchyard://ErrorOutbound");
from("switchyard://InboundService")
.multicast()
.pipeline().to("switchyard://Outbound").end()
.pipeline().to("switchyard://Outbound").end()
.end()
.end();
Second case:
errorHandler(deadLetterChannel("switchyard://ErrorOutbound"));
onException(Throwable.class).to("switchyard://ErrorOutbound");
from("switchyard://InboundService")
.multicast()
.to("direct:Outbound")
.to("direct:Outbound")
.end()
.end();
from("direct:Outbound")
.to("switchyard://Outbound")
So my question is: This is the usual case how multicast should be used in switchyard? I didn't found any mention about this in documentation. The version i tested was: EAP 6.1, switchayrd 1.1 and EAP 6.4, switchyard 2.0. Similar code developed in pure camel does not needs this trick to make it work.
errorHandler(deadLetterChannel("file:C:/tmp/zzz?fileName=error-${date:now:yyyyMMddHHmmssSSS}"));
onException(Throwable.class).to("file:C:/tmp/zzz?fileName=error-${date:now:yyyyMMddHHmmssSSS}");
from("file:C:/tmp/xxx/pending")
.multicast()
.to("file:C:/tmp/yyy?autoCreate=false")
.to("file:C:/tmp/yyy?autoCreate=false")
.end()
.end();