问题
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.
回答1:
Try making your component org.mule.api.construct.FlowConstructAware. You should then be able to get its name.
HTH
回答2:
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 :)
回答3:
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.
回答4:
Another easy way, set it as variable and then access that variable in java component.
来源:https://stackoverflow.com/questions/37118352/mule-how-to-access-flow-name-inside-java-component