0
votes

I am using Anypoint studio. I have used esper CEP engine for event detection using java file. Once the event is detected i am getting output in the console from java file as system.out.println(Object).

I want the Obejct to be sent from java output to the mule flow either as a message property or payload, so I can store in MongoDB or I can reuse it for another event detection. here is my flow: mule flow

Here I want the "event.getUnderlying()" Object to be sent to mule flow.

    public void  update(EventBean[] newData, EventBean[] oldData) {
                    EventBean event = newData[0];
                         obj=event.getUnderlying();
                                        
                            if(a2==0){
                            i++;
     System.out.println("Event received:"+i+" "+event.getUnderlying());

Thanks in Advance :)

2
Can you please add the section of your mule flow xml that describes how you are calling the java method from mule flow? - theLastOneInOffice
<component class="esper.Test_main" doc:name="Java"/> - salim

2 Answers

0
votes

Just "post" to the input connector of the flow you want to send to. So for HTTP input use something like org.apache.http.client.HttpClient or HttpUrlConnection

(There are so many examples of how to use those on this site and many others...)

Other inputs have different libraries you can use, you could just save it as a file and have the file input pick it up. (depends on where you are deploying).

0
votes

If you are calling the Java class via Component (as you mentioned in your comment), your Java class esper.Test_main must be implementing Callable interface. More details on using Java component right - https://docs.mulesoft.com/mule-user-guide/v/3.8/java-component-reference

In that case, you need to implement below method:

public Object onCall(MuleEventContext eventContext) {

  //your code here

  return someObject; // return event.getUnderlying() in your case

}

The object returned from onCall() method is passed on as 'payload' to the next message processor in mule flow.

If you need to set a flow variable from the Java class:

public Object onCall(MuleEventContext eventContext) {

  //your code here

  eventContext.getMessage().setInvocationProperty("variableName", "variableValue");

  return someObject; // return event.getUnderlying() in your case

}

Now, you will have a flowVar called variableName available in your mule flow.

HTH.