使用VM入站端点发出调用流

时间:2012-09-16 11:48:39

标签: mule

我有一个流通过VM端点调用另一个流。调用失败,异常为NoReceiverForEndpointException。日志中的消息是:

There is no receiver registered on connector "connector.VM.mule.default" for endpointUri vm://inner

有谁知道为什么?这是Mule 3.3.0企业版。

感谢。

配置文件:

<mule ...>
    <vm:endpoint name="inner" path="inner" />
    <flow name="inner.flow">
        <inbound-endpoint ref="inner" exchange-pattern="request-response" />
        <logger level="INFO" message="in inner flow" />
    </flow>

    <vm:endpoint name="outer" path="outer" />
    <flow name="outer.flow">
        <inbound-endpoint ref="outer" exchange-pattern="one-way" />
        <logger level="INFO" message="in outer flow" />
        <outbound-endpoint ref="inner" exchange-pattern="request-response" />
    </flow>
</mule>

运行它的测试用例:

import org.junit.Test;
import org.mule.api.MuleException;
import org.mule.module.client.MuleClient;
import org.mule.tck.junit4.FunctionalTestCase;

public class VMEndpointTest extends FunctionalTestCase {

    @Test
    public void innerIsCalled() throws MuleException {
        final MuleClient client = new MuleClient(muleContext);
        client.sendNoReceive("outer", new Object(), null);
    }

    @Override
    protected String getConfigResources() {
        return "test.xml";
    }

}

2 个答案:

答案 0 :(得分:1)

啊,我自己想出来了:

  1. 外部端点为one-way,因此我应该使用dispatch向其发送消息。
  2. 单元测试需要一些机制来等待Mule处理one-way流中的消息。我在Java代码中引入了receive调用,为此引入了一个vm端点。
  3. 配置文件:

    <mule ...>
        <vm:endpoint name="outer" path="outer" />
        <flow name="outer.flow">
            <inbound-endpoint ref="outer" exchange-pattern="one-way" />
            <logger level="INFO" message="in outer flow" />
            <outbound-endpoint ref="inner" exchange-pattern="request-response" />
        </flow>
    
        <vm:endpoint name="inner" path="inner" />
        <vm:endpoint name="inner.completed" path="inner.completed" />
        <flow name="inner.flow">
            <inbound-endpoint ref="inner" exchange-pattern="request-response" />
            <logger level="INFO" message="in inner flow" />
            <outbound-endpoint ref="inner.ftc" exchange-pattern="request-response" />
            <outbound-endpoint ref="inner.completed" exchange-pattern="one-way" />
        </flow>
    
        <vm:endpoint name="inner.ftc" path="inner.ftc" />
        <simple-service name="innerFtc" endpoint-ref="inner.ftc">
            <test:component />
        </simple-service>
    </mule>
    

    测试用例:

    package foo;
    
    import static org.junit.Assert.assertEquals;
    
    import org.junit.Test;
    import org.mule.module.client.MuleClient;
    import org.mule.tck.functional.FunctionalTestComponent;
    import org.mule.tck.junit4.FunctionalTestCase;
    
    public class VMEndpointTest extends FunctionalTestCase {
    
        @Test
        public void innerIsCalled() throws Exception {
            final FunctionalTestComponent ftc = getFunctionalTestComponent("innerFtc");
            final Object object = new Object();
            final MuleClient client = new MuleClient(muleContext);
    
            client.dispatch("outer", object, null);
            client.request("inner.completed", RECEIVE_TIMEOUT);
    
            assertEquals(object, ftc.getLastReceivedMessage());
        }
    
        @Override
        protected String getConfigResources() {
            return "test.xml";
        }
    
    }
    

答案 1 :(得分:0)

对于两个vm端点,您必须使用相同的名称进行配置,然后才会连接。