【问题标题】:Camel - catch SQL exception and try 3 timesCamel - 捕获 SQL 异常并尝试 3 次
【发布时间】:2021-09-19 01:15:50
【问题描述】:

当 Camel route toF("sql:insert into ...") 由于 db 连接问题而失败时,会抛出哪个异常?

我尝试像onException(CannotCreateTransactionException.class, ConnectionException.class) 一样捕获 但它没有捕获。 如果我能捕捉到它,我想做最多 3 次重新交付并调用其他流程,如下所示

.maximumRedeliveries(3)
.redeliveryDelay(10000)
.process("ConnectionExceptionProcess")
.end()

谢谢,

【问题讨论】:

    标签: apache-camel camel-sql


    【解决方案1】:

    sql 组件可以抛出不止一种错误类型。 DataAccessException 、 IllegalArgumentException 、 SQLException 等。您可以通过仅对您将创建的路线执行 sql 操作来解决此问题。您可以从其他路线调用这里

    public class SqlOperationRoute extends RouteBuilder {
    
    @Override
    public void configure() {
    
        onException()
                .maximumRedeliveries(3)
                .process("myProcessor")
                .end();
    
        from("direct:insert")
                .to("sql:insert into table x .....");
    
        from("direct:get")
                .to("sql: select  from ....");
    }
    

    }

    【讨论】:

    • 感谢您的回答。我确实有一个问题。所以假设我有插入语句会抛出什么异常?你能帮我在哪里找到针对特定情况会引发什么样的异常?
    • 查看 SqlProducer 。 sql组件使用spring jdbctemplate
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-02-06
    • 1970-01-01
    • 1970-01-01
    • 2021-12-13
    • 2011-12-05
    • 2014-05-11
    • 2013-10-04
    相关资源
    最近更新 更多