簡體   English   中英

繼續一條駱駝路線的異常並在另一條駱駝路線中處理

[英]Continue the exception from one camel route and handle it in another camel route

我有一個 Apache Camel 路由,它調用 restlet 組件,並希望使用來自異常處理程序的重新傳遞機制,該機制對每次失敗執行一些處理以更新我的數據庫記錄,這應該在通用路由上完成。 所以,我試圖在一個路由中繼續異常,並通過直接組件在另一路由中處理相同的異常。 但例外是不繼續通用路線。

第一條路線:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:cxf="http://camel.apache.org/schema/cxf"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="  http://www.springframework.org/schema/beans   http://www.springframework.org/schema/beans/spring-beans.xsd   http://camel.apache.org/schema/spring       http://camel.apache.org/schema/spring/camel-spring.xsd  http://camel.apache.org/schema/cxf    http://camel.apache.org/schema/cxf/camel-cxf.xsd">
    <!-- CXF Rest Endpoint Declaration -->
    <cxf:rsServer address="http://localhost:9092/rest/corp"
        id="FetchCDFRestRequest" serviceClass="com.tcl.Service.Service" />

    <bean class="com.tcl.ExceptionOccurredRefProcessor" id="exProc" />

    <bean class="org.apache.camel.builder.DeadLetterChannelBuilder"
        id="DLCErrorHandler">
        <property name="deadLetterUri"
            value="activemq:queue:DMS.FAILURES.DLQ" />
        <property name="redeliveryPolicy" ref="redeliveryPolicy" />
    </bean>
    <bean class="org.apache.camel.processor.RedeliveryPolicy"
        id="redeliveryPolicy">
        <property name="maximumRedeliveries"
            value="3" />
        <property name="maximumRedeliveryDelay" value="2000" />
        <property name="retryAttemptedLogLevel" value="WARN" />
    </bean>
    <camelContext id="Corp"
        xmlns="http://camel.apache.org/schema/spring">

        <errorHandler id="eh" onExceptionOccurredRef="exProc">
            <redeliveryPolicy id="redeliveryPolicy" />
        </errorHandler>

        <route id="MainRouteOppIDFolder" streamCache="true">
            <from id="_CreateOppIDFolder"
                uri="restlet:http://localhost:9092/rest/corp/createOppIDFolder?restletMethod=POST" />
            ----------
            <to uri="restlet:http://localhost:9902/CreateOppIDFolder?restletMethod=POST" />
            ------------    
            <onException id="_onException1" useOriginalMessage="true">
                <exception>java.lang.Exception</exception>
                <handled>
                    <simple>false</simple>
                </handled>
                <log id="_log1" message="Cont... ex >>>>> ${exception.message} "/>
                <to uri="direct:ExceptionHandle"/>
            </onException>
        </route>
    </camelContext>
</beans>

第二條路線:

<route errorHandlerRef="DLCErrorHandler" >
            <from id="_from2" uri="direct:ExceptionHandle"/>
            <log id="_log4" message="Req>>>>> ${body}"/>
            <onException id="_onException2"
                onExceptionOccurredRef="exProc" redeliveryPolicyRef="redeliveryPolicy">
                <exception>java.lang.Exception</exception>
                <handled>
                    <simple>true</simple>
                </handled>
                <log id="_log3" loggingLevel="INFO" message="Handled ex >>>>> ${exception.message} "/>
                <choice id="_choice1">
                    <when id="_when1">
                        <simple>${header.errorMessage} contains 'Could not send Message' || ${header.errorMessage} contains 'Connection timed out'</simple>
                        <to id="_to1" pattern="OutOnly" uri="activemq:queue:DMS.FAILURES"/>
                    </when>
                    <otherwise id="_otherwise1">
                        <log id="_log5" loggingLevel="ERROR" message="Exception occured in otherwise block >>>>>> ${exception.stacktrace} "/>
                    </otherwise>
                </choice>
            </onException>
        </route>

12:11:24.384 [Restlet-781390346] WARN  o.a.c.processor.DeadLetterChannel - Failed delivery for (MessageId: ID-DESKTOP-P2DBOO5-1580280046927-0-8 on ExchangeId: ID-DESKTOP-P2DBOO5-1580280046927-0-7).On delivery attempt: 0 caught: org.apache.camel.component.restlet.RestletOperationException: Restlet operation failed invoking http://localhost:9902/CreateOppIDFolder with statusCode: 500 /n responseBody:org.apache.cxf.interceptor.Fault: Could not send Message.
Caused by: java.net.ConnectException: ConnectException invoking http://172.16.18.113:7001/services/TCLDMSSFDCService/TCLDMSSFDCService: Connection timed out: connect
Caused by: java.net.ConnectException: Connection timed out: connect

12:11:24.392 [Restlet-781390346] INFO  MainRouteOppIDFolder - Cont... ex >>>>> Restlet operation failed invoking http://localhost:9902/CreateOppIDFolder with statusCode: 500 /n responseBody:org.apache.cxf.interceptor.Fault: Could not send Message.
Caused by: java.net.ConnectException: ConnectException invoking http://172.16.18.113:7001/services/TCLDMSSFDCService/TCLDMSSFDCService: Connection timed out: connect
Caused by: java.net.ConnectException: Connection timed out: connect

12:11:24.396 [Restlet-781390346] INFO  _route1 - Req>>>>> {
  "oppID" : "10268216",
  "salesOrganization" : "Commerical Finance",
  "salesVertical" : "CEQ",
  "productName" : "Construction Equipment Finance",
  "applicantName" : "SGS INFRASTRUCTURE",
  "docName" : null,
  "appNature" : null,
  "docType" : null,
  "base64Content" : null
}

12:11:24.405 [Restlet-781390346] ERROR o.a.c.processor.DeadLetterChannel - Failed delivery for (MessageId: ID-DESKTOP-P2DBOO5-1580280046927-0-8 on ExchangeId: ID-DESKTOP-P2DBOO5-1580280046927-0-7). Exhausted after delivery attempt: 1 caught: org.apache.camel.component.restlet.RestletOperationException: Restlet operation failed invoking http://localhost:9902/CreateOppIDFolder with statusCode: 500 /n responseBody:org.apache.cxf.interceptor.Fault: Could not send Message.
Caused by: java.net.ConnectException: ConnectException invoking http://172.16.18.113:7001/services/TCLDMSSFDCService/TCLDMSSFDCService: Connection timed out: connect
Caused by: java.net.ConnectException: Connection timed out: connect
. Processed by failure processor: FatalFallbackErrorHandler[Pipeline[[Channel[Log(MainRouteOppIDFolder)[Cont... ex >>>>> ${exception.message} ]], Channel[sendTo(direct://ExceptionHandle)], Channel[Log(MainRouteOppIDFolder)]]]]

Message History
RouteId              ProcessorId          Processor                                                                        Elapsed (ms)
[MainRouteOppIDFold] [MainRouteOppIDFold] [restlet://http://localhost:9092/rest/corp/createOppIDFolder?restletMethod=POST] [     21608]
[MainRouteOppIDFold] [_CreateOppIDFolder] [restlet:http://localhost:9902/CreateOppIDFolder?restletMethod=POST            ] [     21319]
[MainRouteOppIDFold] [_to2              ] [direct:ExceptionHandle                                                        ] [         1]
[_route1           ] [_log4             ] [log                                                                           ] [         1]

Stacktrace
org.apache.camel.component.restlet.RestletOperationException: Restlet operation failed invoking http://localhost:9902/CreateOppIDFolder with statusCode: 500 /n responseBody:org.apache.cxf.interceptor.Fault: Could not send Message.
Caused by: java.net.ConnectException: ConnectException invoking http://172.16.18.113:7001/services/TCLDMSSFDCService/TCLDMSSFDCService: Connection timed out: connect
Caused by: java.net.ConnectException: Connection timed out: connect```

**Any suggestions please?**

老實說:我看不出你的問題。

您的異常塊確實

<log id="_log1" message="Cont... ex >>>>> ${exception.message} "/>
<to uri="direct:ExceptionHandle"/>

直達路線

<log id="_log4" message="Req>>>>> ${body}"/>

你的日志顯示

Cont... ex >>>>> [error message]
Req>>>>> [message body]

所以一切都如你所願。 我錯過了什么嗎?

由於評論而更新

只要第二條路onException沒有發生異常,就不會調用第二條路由的onException塊。 第二條路由通常接收消息並對其進行處理。

您仍然可以使用${exception}訪問消息的異常信息。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM