SlideShare uma empresa Scribd logo
Camel In Action 2nd edition 読書会
2020年7⽉7⽇
11.4 Using onException in Camel
l Camelで提供された5つのError Handler(前回読書会で説明した)
は、例外種類を区別せず、⼀律に例外処理⾏うための⼿段
l 例外種類を区別して例外処理を⾏う⼿段はonException
l onExceptionは、”exception policies”とも呼ばれる
l onExceptionは、Error Handlerと併⽤可能
l onExceptionが捕捉されない例外がError Handlerに渡される
onExceptionとは
20202
onException(OrderFailedException.class)
.maximumRedeliveries(3).[例外処理];
from("direct:order")
.bean(OrderServiceBean.class, "handleOrder")
.bean(OrderServiceBean.class, "saveToDB");
<camelContext>
<onException>
<exception>my.OrderFailedException</exception>
<redeliveryPolicy maximumRedeliveries="3"/>
<!– 例外処理 -->
</onException>
<route id="receive-order">
<from uri="direct:order"/>
<bean ref="orderServ" method="handleOrder"/>
<bean ref="orderServ" method="saveToDB"/>
</route>
</camelContext>
Java DSLで記述の場合: XML DSLで記述の場合:
l Camel Routeの例
l Route Engineの正常時処理
1. Consumerが受け取ったExchangeをChannelに渡し
2. ProcessorがExchangeを加⼯してChannelに渡し
3. ChannelがExchangeをProessor/Producerに渡し
4. 上記2-3の繰り返し
onExceptionがどこで呼ばれる
20203
Direct:
order
Consumer
orderService:
handleOrder
Processor
orderService:
saveToDB
Channel Channel
Processor
Exchange Exchange Exchange Exchange
<camelContext>
<onException>
<exception>my.OrderFailedException</exception>
<!– 例外処理 -->
</onException>
<route id="receive-order">
<from uri="direct:order"/>
<bean ref="orderServ" method="handleOrder"/>
<bean ref="orderServ" method="saveToDB"/>
</route>
</camelContext>
1 2 3 4 5 6
onException
マッチング
※詳細はP5-P7
l Route Engineの例外時処理
1. Processorで処理異常が発⽣すると、exchange.setException(e)
2. ExchangeがChannelに戻される
3. Channelが適切なonExceptionをマッチング(詳細は次ページ)
4. マッチの場合、ChannelがExchangeをonExceptionに渡して、その後「例外処理」が実⾏される
5. マッチしない場合、ChannelがExchangeをErrorHandler(前回読書会で説明した)に渡す
onExceptionがどこで呼ばれる
20204
Direct:
newOrder
Consumer
orderService:
validate
orderService:
store
Channel Channel
Processor
Exchange Exchange
Exchange with Ex:
my.OrderFailedException
+ java.net.ConnectException
例外
onException
(my.OrderFailedException)
onException
(…)
onException
(…)
1
2
3 4
※詳細はP8〜P10
MyErrorHandler
<例: DefaultErrorHandler>
5
例外処理
<Route/Bean/Proce
ssor>
例外処理
<Route/Bean/Proce
ssor>
例外処理
<Route/Bean/Proce
ssor>
※詳細はP11〜14
l マッチング⽅法
l 最初に「Direct Match」を使⽤
l 発⽣した例外のルートExceptionが⼀番優先にマッチングされる
l 発⽣した例外タイプとonExceptionが⼀致したら、これで決定
l ⼀致するonExceptionがない場合は、は「Gap Detection」メカニズムを使⽤
l 発⽣した例外タイプの”Exception hierarchy”とonExceptionのGap値を計算する
l Gap値が⼀番⼩さい、かつルートExceptionに⼀番近いものに決定
onExceptionのマッチング
20205
l 「Direct Match」
l 発⽣した例外のルートExceptionが⼀番優先にマッチングされる
l 発⽣した例外タイプとonExceptionが⼀致すること
onExceptionのマッチング例1
20206
Exchange with Ex:
org.apache.camel.RuntimeCamelException
(wrapper by Camel)
+ my.OrderFailedException
+ java.net.ConnectException
発⽣した例外タイプ:
onException:
my.OrderFailedException
onException:
java.lang.Exception
onException:
java.net.ConnectException
onExceptionの例外タイプ:
Direct Match
Direct Match
ルートExceptionが「Direct Match」した。
こっちのonExceptionを実⾏する。
l 「Direct Match」でマッチしない場合、「Gap Detection」メカニズムが使
われる
l 発⽣した例外タイプの”Exception hierarchy”とonExceptionのGap値を計算する
l Gap値が⼀番⼩さいonExceptionが選べれる
l 発⽣した例外のルートExceptionが⼀番優先に決定
onExceptionのマッチング例2
20207
Exchange with Ex:
org.apache.camel.RuntimeCamelException
(wrapper by Camel)
+ my.OrderFailedException
+ java.io.FileNotFoundException
発⽣した例外タイプ:
onException:
java.lang.Exception
onException:
java.net.ConnectException
onExceptionの例外タイプ:
Gap=1 onException:
java.io.IOException
Gap=2
不⼀致
Gap=1
不⼀致
不⼀致
java.lang.Exception
my.OrderFailedException
Exception hierarchy Exception hierarchy
Gap値⼩さい、かつルートExceptionのた
め、こっちのonExceptionを実⾏する。
l 1つのonExceptionで複数Exceptionのタイプを捕捉する
l onExceptionでExceptionタイプに加え、Exception中⾝をフィルターして捕捉する
onExceptionのカスタマイズ1
20208
<onException>
<exception>Exception1</exception>
<exception>Exception2</exception>
<!– 例外処理 -->
</onException>
public static boolean isIllegalDataError(HttpOperationFailedException cause) {
int code = cause.getStatusCode();
if (code != 500) {
return false;
}
return "ILLEGAL DATA".equals(cause.getResponseBody().toString());
}
<bean id="myHttpUtil" class="com.mycompany.MyHttpUtil"/>
<onException>
<exception>MyException</exception>
<onWhen><method ref="myHttpUtil" method="isIllegalData"/></onWhen>
<!– 例外処理 -->
</onException>
l onExceptionでExceptionを捕捉直後の動作をカスタマイズ
l onExceptionでリトライさせる
l onExceptionでリトライの直前の動作をカスタマイズ
onExceptionのカスタマイズ2
20209
<bean id="myLogException" class="com.mycompany.MyLogExceptionProcessor"/>
<onException onExceptionOccurredRef="myLogException">
<exception>Exception1</exception>
<!– 例外処理 -->
</onException>
<bean id="myLogException" class="com.mycompany.MyLogExceptionProcessor"/>
<onException onRedeliveryRef="myLogException">
<exception>Exception1</exception>
<redeliveryPolicy maximumRedeliveries="3"/>
<!– 例外処理 -->
</onException>
<onException>
<exception>Exception1</exception>
<redeliveryPolicy maximumRedeliveries="3"
redeliveryDelay="1000"
retryAttemptedLogLevel="WARN"/>
<!– 例外処理 -->
</onException>
l onExceptionで動的にリトライさせる
onExceptionのカスタマイズ3
202010
<bean id="myRetryRuleset" class="com.mycompany.MyRetryRuleset"/>
<onException>
<exception>Exception1</exception>
<retryWhile><method ref="myRetryRuleset" method="shouldRetry"/></retryWhile>
<!– 例外処理 -->
</onException>
public static boolean shouldRetry (@Header(Exchange.REDELIVERY_COUNTER) Integer
counter, Exception causedBy
) {
// あなたのリトライ判断ロジック
return true/false;
}
l 例外処理をCamel Routeで処理させる
l 例外処理をBean/Processorで処理させる
onExceptionの中の例外処理の書き⽅
202011
<onException>
<exception>Exception1</exception>
<!– 例外処理 -->
<to uri="direct:my-error-handle-route"/>
</onException>
<bean id="myLogException" class="com.mycompany.MyLogExceptionProcessor"/>
<onException>
<exception>Exception1</exception>
<!– 例外処理 -->
<process ref="myLogException"/>
</onException>
l handled=trueの設定 (デフォルトがfalse)
onException使⽤時の注意点1
202012
<onException>
<exception>Exception1</exception>
<handled><constant>true</constant></handled>
<!– 例外処理 -->
<process ref="generateFailureResponse"/>
</onException>
この例では、onException内でhandled=true指定のため、カスタ
ムのエラーレスポンスが最終の処理結果となる。
仮に、handled=falseと指定した場合、ハンドルされないことに
なるので、CamelはError Handler(例:DefaultErrorHandler)を
呼び出して、StackTraceが最終レスポンスとなる。
l contunued=trueの設定 (デフォルトがfalse)
onException使⽤時の注意点2
202013
<onException>
<exception>Exception1</exception>
<continued><constant>true</constant></continued>
<!– 例外処理 -->
<process ref="generateFailureResponse"/>
</onException>
この例では、onException内でcontinued=true指定
のため、例外が発⽣しなかったように、Camelが後
続の処理(channel)に回す。
仮に、continued=false(デフォルト)の場合、
Camelが処理を中断する。即ち前ページのシーケン
ス図の動きとなる。
l 例外処理の中でさらに例外発⽣の場合
onException使⽤時の注意点3
202014
<onException>
<exception>Exception1</exception>
<!– 例外処理 -->
<process ref="generateFailureResponse"/>
</onException>
この例では、generateFailureResponseの中で
更に例外が発⽣することを仮定する
例外
org.apache.camel.processor
.FataFallbackErrorHandler
例外処理の中でさらに例外(例えば、NullPointerException)が発
⽣する場合、CamelがFataFallbackErrorHandlerを実⾏して、
エラーをログ出⼒するだけ。
※ このHandlerの動きはカスタムできない。

Mais conteúdo relacionado

Destaque

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
Marius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Expeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
Skeleton Technologies
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
Christy Abraham Joy
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
Vit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
MindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
RachelPearson36
 

Destaque (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

11.4 camel on exception

  • 1. Camel In Action 2nd edition 読書会 2020年7⽉7⽇ 11.4 Using onException in Camel
  • 2. l Camelで提供された5つのError Handler(前回読書会で説明した) は、例外種類を区別せず、⼀律に例外処理⾏うための⼿段 l 例外種類を区別して例外処理を⾏う⼿段はonException l onExceptionは、”exception policies”とも呼ばれる l onExceptionは、Error Handlerと併⽤可能 l onExceptionが捕捉されない例外がError Handlerに渡される onExceptionとは 20202 onException(OrderFailedException.class) .maximumRedeliveries(3).[例外処理]; from("direct:order") .bean(OrderServiceBean.class, "handleOrder") .bean(OrderServiceBean.class, "saveToDB"); <camelContext> <onException> <exception>my.OrderFailedException</exception> <redeliveryPolicy maximumRedeliveries="3"/> <!– 例外処理 --> </onException> <route id="receive-order"> <from uri="direct:order"/> <bean ref="orderServ" method="handleOrder"/> <bean ref="orderServ" method="saveToDB"/> </route> </camelContext> Java DSLで記述の場合: XML DSLで記述の場合:
  • 3. l Camel Routeの例 l Route Engineの正常時処理 1. Consumerが受け取ったExchangeをChannelに渡し 2. ProcessorがExchangeを加⼯してChannelに渡し 3. ChannelがExchangeをProessor/Producerに渡し 4. 上記2-3の繰り返し onExceptionがどこで呼ばれる 20203 Direct: order Consumer orderService: handleOrder Processor orderService: saveToDB Channel Channel Processor Exchange Exchange Exchange Exchange <camelContext> <onException> <exception>my.OrderFailedException</exception> <!– 例外処理 --> </onException> <route id="receive-order"> <from uri="direct:order"/> <bean ref="orderServ" method="handleOrder"/> <bean ref="orderServ" method="saveToDB"/> </route> </camelContext> 1 2 3 4 5 6
  • 4. onException マッチング ※詳細はP5-P7 l Route Engineの例外時処理 1. Processorで処理異常が発⽣すると、exchange.setException(e) 2. ExchangeがChannelに戻される 3. Channelが適切なonExceptionをマッチング(詳細は次ページ) 4. マッチの場合、ChannelがExchangeをonExceptionに渡して、その後「例外処理」が実⾏される 5. マッチしない場合、ChannelがExchangeをErrorHandler(前回読書会で説明した)に渡す onExceptionがどこで呼ばれる 20204 Direct: newOrder Consumer orderService: validate orderService: store Channel Channel Processor Exchange Exchange Exchange with Ex: my.OrderFailedException + java.net.ConnectException 例外 onException (my.OrderFailedException) onException (…) onException (…) 1 2 3 4 ※詳細はP8〜P10 MyErrorHandler <例: DefaultErrorHandler> 5 例外処理 <Route/Bean/Proce ssor> 例外処理 <Route/Bean/Proce ssor> 例外処理 <Route/Bean/Proce ssor> ※詳細はP11〜14
  • 5. l マッチング⽅法 l 最初に「Direct Match」を使⽤ l 発⽣した例外のルートExceptionが⼀番優先にマッチングされる l 発⽣した例外タイプとonExceptionが⼀致したら、これで決定 l ⼀致するonExceptionがない場合は、は「Gap Detection」メカニズムを使⽤ l 発⽣した例外タイプの”Exception hierarchy”とonExceptionのGap値を計算する l Gap値が⼀番⼩さい、かつルートExceptionに⼀番近いものに決定 onExceptionのマッチング 20205
  • 6. l 「Direct Match」 l 発⽣した例外のルートExceptionが⼀番優先にマッチングされる l 発⽣した例外タイプとonExceptionが⼀致すること onExceptionのマッチング例1 20206 Exchange with Ex: org.apache.camel.RuntimeCamelException (wrapper by Camel) + my.OrderFailedException + java.net.ConnectException 発⽣した例外タイプ: onException: my.OrderFailedException onException: java.lang.Exception onException: java.net.ConnectException onExceptionの例外タイプ: Direct Match Direct Match ルートExceptionが「Direct Match」した。 こっちのonExceptionを実⾏する。
  • 7. l 「Direct Match」でマッチしない場合、「Gap Detection」メカニズムが使 われる l 発⽣した例外タイプの”Exception hierarchy”とonExceptionのGap値を計算する l Gap値が⼀番⼩さいonExceptionが選べれる l 発⽣した例外のルートExceptionが⼀番優先に決定 onExceptionのマッチング例2 20207 Exchange with Ex: org.apache.camel.RuntimeCamelException (wrapper by Camel) + my.OrderFailedException + java.io.FileNotFoundException 発⽣した例外タイプ: onException: java.lang.Exception onException: java.net.ConnectException onExceptionの例外タイプ: Gap=1 onException: java.io.IOException Gap=2 不⼀致 Gap=1 不⼀致 不⼀致 java.lang.Exception my.OrderFailedException Exception hierarchy Exception hierarchy Gap値⼩さい、かつルートExceptionのた め、こっちのonExceptionを実⾏する。
  • 8. l 1つのonExceptionで複数Exceptionのタイプを捕捉する l onExceptionでExceptionタイプに加え、Exception中⾝をフィルターして捕捉する onExceptionのカスタマイズ1 20208 <onException> <exception>Exception1</exception> <exception>Exception2</exception> <!– 例外処理 --> </onException> public static boolean isIllegalDataError(HttpOperationFailedException cause) { int code = cause.getStatusCode(); if (code != 500) { return false; } return "ILLEGAL DATA".equals(cause.getResponseBody().toString()); } <bean id="myHttpUtil" class="com.mycompany.MyHttpUtil"/> <onException> <exception>MyException</exception> <onWhen><method ref="myHttpUtil" method="isIllegalData"/></onWhen> <!– 例外処理 --> </onException>
  • 9. l onExceptionでExceptionを捕捉直後の動作をカスタマイズ l onExceptionでリトライさせる l onExceptionでリトライの直前の動作をカスタマイズ onExceptionのカスタマイズ2 20209 <bean id="myLogException" class="com.mycompany.MyLogExceptionProcessor"/> <onException onExceptionOccurredRef="myLogException"> <exception>Exception1</exception> <!– 例外処理 --> </onException> <bean id="myLogException" class="com.mycompany.MyLogExceptionProcessor"/> <onException onRedeliveryRef="myLogException"> <exception>Exception1</exception> <redeliveryPolicy maximumRedeliveries="3"/> <!– 例外処理 --> </onException> <onException> <exception>Exception1</exception> <redeliveryPolicy maximumRedeliveries="3" redeliveryDelay="1000" retryAttemptedLogLevel="WARN"/> <!– 例外処理 --> </onException>
  • 10. l onExceptionで動的にリトライさせる onExceptionのカスタマイズ3 202010 <bean id="myRetryRuleset" class="com.mycompany.MyRetryRuleset"/> <onException> <exception>Exception1</exception> <retryWhile><method ref="myRetryRuleset" method="shouldRetry"/></retryWhile> <!– 例外処理 --> </onException> public static boolean shouldRetry (@Header(Exchange.REDELIVERY_COUNTER) Integer counter, Exception causedBy ) { // あなたのリトライ判断ロジック return true/false; }
  • 11. l 例外処理をCamel Routeで処理させる l 例外処理をBean/Processorで処理させる onExceptionの中の例外処理の書き⽅ 202011 <onException> <exception>Exception1</exception> <!– 例外処理 --> <to uri="direct:my-error-handle-route"/> </onException> <bean id="myLogException" class="com.mycompany.MyLogExceptionProcessor"/> <onException> <exception>Exception1</exception> <!– 例外処理 --> <process ref="myLogException"/> </onException>
  • 12. l handled=trueの設定 (デフォルトがfalse) onException使⽤時の注意点1 202012 <onException> <exception>Exception1</exception> <handled><constant>true</constant></handled> <!– 例外処理 --> <process ref="generateFailureResponse"/> </onException> この例では、onException内でhandled=true指定のため、カスタ ムのエラーレスポンスが最終の処理結果となる。 仮に、handled=falseと指定した場合、ハンドルされないことに なるので、CamelはError Handler(例:DefaultErrorHandler)を 呼び出して、StackTraceが最終レスポンスとなる。
  • 13. l contunued=trueの設定 (デフォルトがfalse) onException使⽤時の注意点2 202013 <onException> <exception>Exception1</exception> <continued><constant>true</constant></continued> <!– 例外処理 --> <process ref="generateFailureResponse"/> </onException> この例では、onException内でcontinued=true指定 のため、例外が発⽣しなかったように、Camelが後 続の処理(channel)に回す。 仮に、continued=false(デフォルト)の場合、 Camelが処理を中断する。即ち前ページのシーケン ス図の動きとなる。
  • 14. l 例外処理の中でさらに例外発⽣の場合 onException使⽤時の注意点3 202014 <onException> <exception>Exception1</exception> <!– 例外処理 --> <process ref="generateFailureResponse"/> </onException> この例では、generateFailureResponseの中で 更に例外が発⽣することを仮定する 例外 org.apache.camel.processor .FataFallbackErrorHandler 例外処理の中でさらに例外(例えば、NullPointerException)が発 ⽣する場合、CamelがFataFallbackErrorHandlerを実⾏して、 エラーをログ出⼒するだけ。 ※ このHandlerの動きはカスタムできない。