注册FunctionalTestComponents的回调

时间:2015-08-18 23:47:42

标签: mule

我试图将xml中定义的给定功能测试组件的回调注册为单例对象。我直接在Mule网站上的文档中工作,但是看下面的内容,我不知道对getFunctionalTestCOmponent("TestComponentService").setEventCallback(callback);的调用是如何找到单身人士的,因为这个名字TestComponentService与组件无关。我自己没有运气就尝试过这个。我还尝试添加doc:name =" TestComponentService"组件,但仍然没有运气。知道如何使这个例子在下面有用吗?

public void testEventCallback() throws Exception 
{
    EventCallback callback = new EventCallback()
    {
        public void eventReceived(MuleEventContext context, Object component) 
            throws Exception
        {
            System.out.println("Thanks for calling me back");
        }
    };

    getFunctionalTestComponent("TestComponentService").setEventCallback(callback);

    MuleClient client = new MuleClient();

    client.send("vm://test", new DefaultMuleMessage("foo"));
 }


<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:spring="http://www.springframework.org/schema/beans"
    xmlns:vm="http://www.mulesoft.org/schema/mule/vm"
    xmlns:test="http://www.mulesoft.org/schema/mule/test"
    xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
    http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
    http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsd
    http://www.mulesoft.org/schema/mule/test http://www.mulesoft.org/schema/mule/test/current/mule-test.xsd">

<flow name="TestComponentFlow">
    <inbound-endpoint address="vm://test" exchange-pattern="request-response" />  
    <component>
        <singleton-object class="org.mule.tck.functional.FunctionalTestComponent"/>
    </component>
</flow>

1 个答案:

答案 0 :(得分:1)

应该是'TestComponentFlow',它按流程名称查找。

所以使用:

getFunctionalTestComponent("TestComponentFlow").setEventCallback(callback);