如何从私有流中传播异常?

发布于 2025-01-03 23:41:02 字数 1668 浏览 1 评论 0原文

我在某处读到,异常不会从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

故事↓在人 2025-01-10 23:41:02

看起来您想使用子流而不是另一个流。

  • 流有自己的生命周期、异常处理和处理策略等。
  • 子流的行为与可以重用的宏完全相同,它与将相同的处理器复制并粘贴到引用和使用子流的流中相同。

HTH。

It looks like you want to use a sub-flow rather than another flow.

  • A flow, has it's own lifecycle, exception handling and processing strategy etc.
  • A sub-flow acts exactly like a macro that can be reused, it's identical to copying and pasting the same processors into the flow that is referencing and using the sub-flow.

HTH.

能怎样 2025-01-10 23:41:02

丹是对的。

异常传播是不可能的,但从 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文