调用 mule 可调用 oncall 方法的参数

arguments to invoke mule callable oncall method

我正在尝试调用 class,它实现了从 Mule 中的 Java 调用调用。但是我不知道要从调用配置中作为方法参数传递什么。请帮忙!

public class ModificationService implements Callable {
@Override
public Object onCall(MuleEventContext eventContext) throws Exception {
    MuleMessage msg = eventContext.getMessage();
    String path = msg.getProperty("destination", PropertyScope.OUTBOUND);
    String[] splitpath = path.split("/");
    path = splitpath[0];
    msg.setProperty("destination", path, PropertyScope.OUTBOUND);

    MuleMessage newMessage = new DefaultMuleMessage(path, msg, eventContext.getMuleContext());

    return newMessage;
}

配置XML

<invoke name="ModificationBean" object-ref="modificationServiceBean" method="onCall" methodArguments="#[payload]" doc:name="Invoke"/>

为了不让参数部分为空,我传递了消息有效负载。

我相信您创建的 class 将适用于 Java mule 组件,因为您将需要对 MuleEventContext 的引用,您可以在其中获取有效负载的值。

看到这个link:

https://docs.mulesoft.com/mule-user-guide/v/3.7/java-component-reference

而您正在寻找的是:

https://docs.mulesoft.com/mule-user-guide/v/3.7/invoke-component-reference

您将需要创建自定义 class,请参见下面的示例:

addTwoNumbers 是 class 方法,其中以 #[1] 和 #[2] 作为参数。这些可以是 flowVars 或 SessionVars 或 payload。

这可能对你有帮助:

"How set/get variables, manipulate or modify the payload, read properties file and spring in the same java component"

https://github.com/jrichardsz/mule-esb-usefull-templates

具有可调用方法的简单组件:

package com.spring.component;

import java.util.Map;
import javax.annotation.Resource;
import org.mule.api.MuleEventContext;
import org.mule.api.lifecycle.Callable;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.mule.api.transport.PropertyScope;

@Component("myComponent")
@Scope("prototype")

/*
 * Use Callable if you want : 
 * (spring functionalities, handle mule message and read a properties file) 
 * at the same time.
 * */
public class MyComponent implements Callable{

//  @Autowired
//  private AnotherSpringComponetOrServiceOrWhatever spring;    

    @Override
    public Object onCall(MuleEventContext eventContext) throws Exception {

        //get payload
        String payload = (String) eventContext.getMessage().getPayload();

        //SESSION, INBOUND, OUTBOUND, APPLICATION
        //http://blogs.mulesoft.com/dev/anypoint-platform-dev/mule-school-the-mulemessage-property-scopes-and-variables/

        //get vars according to its scope
        String inputProperty = eventContext.getMessage().getProperty("inputProperty", PropertyScope.INVOCATION);

        //set vars in some scope
        eventContext.getMessage().setProperty("key", "some_value", PropertyScope.SESSION);

        //return eventContext.getMessage().getPayload(); //payload is intact
        return "NEW_PAYLOAD";
    }

}

在 mule 流中 spring:

<component doc:name="myComponent">
    <spring-object bean="myComponent" />
</component>

或不带spring(删除spring注释)

<component class="com.spring.component.MyComponent" doc:name="MyComponent"/>

希望对您有所帮助。