简体   繁体   中英

Mule - How to access flow name inside Java Component?

We do have sub flows shared between many flows. I would like find within my subflow which Flow is the call one...

MEL:-

#[flow.name]

is working only in Logger.

I couldn't even pass this value into Session/Anyother property (by set property connector), so I can access using message.getProperty method.

Thanks in advance.

Try making your component org.mule.api.construct.FlowConstructAware. You should then be able to get its name.

HTH

I my case I created other flow for logging which has VM inbound. Then I called it via Java component. See sample codes below.

public class TestCallVm implements Callable{

    @Override
    public Object onCall(MuleEventContext eventContext) throws Exception {
        MuleMessage message = eventContext.getMessage();
        String tid = message.getProperty("tid", PropertyScope.SESSION).toString();

        MuleClient client = new MuleClient(eventContext.getMuleContext());
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("tid", message.getProperty("tid", PropertyScope.SESSION).toString());
        message.setPayload("Hello");
        client.sendNoReceive("vm://vmLogger", "Hello", map);
        client.send("vm://vmLogger", "Hello", map);
        client.send("vm://vmLogger", message, null);
        MuleMessage response = client.send("vm://vmLogger", "Ross", null);
        System.out.println("response = ");
        return null;
    }

}

Hope this will helps :)

You can use following code for getting flow name in java component

import org.mule.api.MuleEventContext;
import org.mule.api.construct.FlowConstruct;
import org.mule.api.construct.FlowConstructAware;
import org.mule.api.lifecycle.Callable;

public class LogFlowName implements Callable, FlowConstructAware {
    private FlowConstruct flowConstruct;
    @Override
    public void setFlowConstruct(FlowConstruct flowConstruct) {
         this.flowConstruct = flowConstruct;

    }
    @Override
    public Object onCall(MuleEventContext eventContext) throws Exception {
        //TODO  your code goes here
        System.out.println("Flow Name is : " +flowConstruct.getName());
        //TODO  your code goes here
        return eventContext.getMessage().getPayload();
    }
}

Hope this helps.

另一种简单的方法,将其设置为变量,然后在Java组件中访问该变量。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM