如何从私有流中传播异常?
我在某处读到,异常不会从 Mule (3.2) 的私有流中传播出来。如果是这样,是否存在另一个 mule 构造:
- 消息处理器链
- 是否可以从另一个构造引用
- 将异常传播到调用构造
?
或者,有没有办法规避例外情况不会从私人流量中传播的限制?
您可以使用 mule-config.xml 和下面的 java 代码来重现我上面描述的行为,其中异常不会从私有流中传播:
mule-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:stdio="http://www.mulesoft.org/schema/mule/stdio"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/stdio http://www.mulesoft.org/schema/mule/stdio/3.2/mule-stdio.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/3.2/mule.xsd">
<stdio:connector name="unused" promptMessage="Yes? " messageDelayTime="1000" />
<flow name="throwsException">
<component class="apackage.ThrowsException" />
</flow>
<flow name="echo">
<stdio:inbound-endpoint system="IN"/>
<flow-ref name="throwsException" />
<component class="apackage.DuplicateString" />
<stdio:outbound-endpoint system="OUT"/>
</flow>
</mule>
ThrowsException。 java
package apackage;
public class ThrowsException {
public String throwsException(String string) {
throw new RuntimeException();
}
}
DuplicateString.java
package apackage;
public class DuplicateString {
public String duplicateString(String string) {
return string.concat(string);
}
}
I read somewhere that exceptions are not propagated out of private flows in Mule (3.2). If so, is there another mule construct that:
- is a chain of message processors
- can be referenced from another construct
- propagates exceptions to the calling construct
?
Or, is there a way to circumvent the restriction that exceptions are not propagated out of private flows?
You could use the mule-config.xml and the java code below to reproduce the behavior I am describing above in which exceptions do not propagate out of private flows:
mule-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:stdio="http://www.mulesoft.org/schema/mule/stdio"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/stdio http://www.mulesoft.org/schema/mule/stdio/3.2/mule-stdio.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/3.2/mule.xsd">
<stdio:connector name="unused" promptMessage="Yes? " messageDelayTime="1000" />
<flow name="throwsException">
<component class="apackage.ThrowsException" />
</flow>
<flow name="echo">
<stdio:inbound-endpoint system="IN"/>
<flow-ref name="throwsException" />
<component class="apackage.DuplicateString" />
<stdio:outbound-endpoint system="OUT"/>
</flow>
</mule>
ThrowsException.java
package apackage;
public class ThrowsException {
public String throwsException(String string) {
throw new RuntimeException();
}
}
DuplicateString.java
package apackage;
public class DuplicateString {
public String duplicateString(String string) {
return string.concat(string);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来您想使用子流而不是另一个流。
HTH。
It looks like you want to use a sub-flow rather than another flow.
HTH.
丹是对的。
异常传播是不可能的,但从 Mule 3.3 开始,您将能够传播私有流中引发的异常,以便调用者流异常策略可以管理它。
Dan is right.
Exception propagation was not possible but since Mule 3.3 you will be able to propagate exceptions thrown in private flow so the caller flow exception strategy can manage it.