打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
How to Configure Exception Handling in Mule

An exception is a difficulty that arises during the implementation of a program. An exception can occur for many different reasons, including the following :

  • A user has entered invalid data.
  • A file that needs to be opened cannot be found.
  • A network connection has been lost in the middle of communications or the JVM has run out of memory.

Some of these exceptions are caused by user error, others by programmer error, and others by physical resources that have failed in some manner. There are different type of exception in Mule.

 

1. Default Connector Exception Strategy

 

Let us say for example we have a file inbound and the data are send as form of mail.

So <default-connector-exception-strategy/> automatically takes care of the exception that is taking care of it.

 

2. Default Service Exception Strategy

 

It throws exception for all Services on behalf of it.

<model name="randomGeneratorModel">

<default-service-exception-strategy/>

<service name="RandomIntegerGenerator">

<inbound>

<vm:inbound-endpoint path="RIG.In" />

</inbound>

<component>

<no-arguments-entry-point-resolver>

<include-entry-point method="nextInt"/>

</no-arguments-entry-point-resolver>

<singleton-object class="java.util.Random" />

</component>

</service>

..

</model>

 

3. Sending all service level exceptions to JMS queue

 

Here is the following example for exception handling

Not always we send all excpetions to get handled internally in some cases we may need our own logic to handle exceptions.

For (ex)

<model name="randomGeneratorModel">

<default-connector-exception-strategy>

<jms:outbound-endpoint queue="transport-errors"/>

</default-connector-exception-strategy>

<default-service-exception-strategy>

<jms:outbound-endpoint queue="business-errors"/>

</default-service-exception-strategy>

<service name="RandomIntegerGenerator">

<inbound>

<vm:inbound-endpoint path="RIG.In" />

</inbound>

<component>

<no-arguments-entry-point-resolver>

<include-entry-point method="nextInt"/>

</no-arguments-entry-point-resolver>

<singleton-object class="java.util.Random" />

</component>

</service>

 

4.Rollback Strategy Exception Handling

 

In this type of strategy, failure may cause at any point of time and you need to re-execute  the use case for the defined number of times it may be 1, 2, …, n.

Consider we are having a case in which  we are not able to connect to server now we want to perform this action for 5 times and if we do not get succeeded in those attempts then we will try to get connected to another server.

So for Looped execution we will write

       <rollback-exception-strategy maxRedeliveryAttempts="3">

    and for maximum exceeded attempts we need to execute     

        <on-redelivery-attempts-exceeded>

For ex.

<jms:activemq-connector name="activeMQ"/>

<flow>

   <jms:inbound-endpoint queue="in">

      <jms:transaction action="ALWAYS_BEGIN"/>

   </jms:inbound-endpoint>

   <processor ref="processor"/>

   <rollback-exception-strategy maxRedeliveryAttempts="3">

      <on-redelivery-attempts-exceeded>

         <jms:outbound-endpoint queue="dlq">

            <jms:transaction action="ALWAYS_JOIN"/> 

         </jms:outbound-endpoint>

      </on-redelivery-attempts-exceeded>

   </rollback-exception-strategy>

</flow>

http://www.mulesoft.org/documentation/display/current/Rollback+Exception+Strategy+Behavior

http://www.mulesoft.org/documentation/display/current/Rollback+Exception+Strategy+Documentation

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
Core J2EE Patterns - Front Controller
spring声明式事务管理
spring事务回滚问题
ABAP 异常处理(Exception Handling) - 什么是 Non-Class-Based 异常试读版
CodeProject: How a C compiler implements exception handling. Free source code and programming help
105集 Win10电脑蓝屏提示System service exception该怎么办?
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服