【问题标题】:Custom Mediator in Sequence only run when WSO2 StartUp序列中的自定义中介仅在 WSO2 启动时运行
【发布时间】:2013-06-20 22:52:38
【问题描述】:

我制作了一个自定义中介,它只打印“Hello World”,我的自定义中介看起来像这样:

public class HelloWorld extends AbstractMediator implements ManagedLifecycle{

public static void helloWorld() {
    System.out.println("Hello World");  
}

public void init(SynapseEnvironment synapseEnvironment) {
    // initializing  surcharges map with some symbols
    helloWorld();
}

public void destroy() {
    // clearing the surcharges contents

}

@Override
public boolean mediate(MessageContext arg0) {
    // TODO Auto-generated method stub
    return false;
}

}

我将这个类依次称为“Hello”:

   <sequence name="Hello">
  <class name="com.exec.HelloWorld">
  </class>

我在代理中使用这个序列:

<proxy xmlns="http://ws.apache.org/ns/synapse" name="FileProxy" transports="vfs" startOnLoad="true" trace="disable">
<target>
    <inSequence>
        <log level="full"/>
            <target sequence="Hello"/>
    </inSequence>
</target>
<parameter name="transport.vfs.ActionAfterProcess">MOVE</parameter>
<parameter name="transport.PollInterval">15</parameter>
<parameter name="transport.vfs.MoveAfterProcess">file:///Users/Source</parameter>
<parameter name="transport.vfs.FileURI">file:///Users/Target/</parameter>
<parameter name="transport.vfs.FileNamePattern">.*.txt</parameter>
<parameter name="transport.vfs.ContentType">text/plain</parameter>

我希望每次我在源文件夹中放置一个文件 (*.txt) 时都会调用我的序列。但问题是该序列只被调用一次(当 wso2 esb 启动时)。每次将文件放入源文件夹时,如何调用我的序列?

谢谢,

【问题讨论】:

    标签: wso2 wso2esb


    【解决方案1】:

    我认为它按预期工作,但我认为您误解了它是如何工作的自定义调解器。您看到的消息是 init 方法显示的消息,这是创建 meditor 时的消息。

    每次您将文件留在文件夹中时,此调解器都会运行,但发生时启动的方法是“调解器”方法,该实现不执行任何操作(返回 false)。所以你应该将中介方法实现为

    public boolean mediate(MessageContext arg0) {
        hellowWorld();
        return false;
    }
    

    它会如你所愿地显示消息。

    希望它有效!

    【讨论】:

      【解决方案2】:

      您应该在中介方法()中调用您的逻辑。并使返回值为真。如果您将其设为 false,则中介引擎将在中介过程中返回 false,并在消息流中产生问题。 你可以查看这个sample

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-06-08
        • 2023-04-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-10-05
        • 2019-04-21
        • 1970-01-01
        相关资源
        最近更新 更多