Invoke method of an object using Invoke Component in Mule ESB

In this tutorial, I will show you how to invoke method of an object using Invoke Component in Mule ESB.

First, I will create a new project as an example:

Invoke method of an object using Invoke Component in Mule ESB

Now, I will create a new HelloWorld object in the com.huongdanjava.muleesbinvokecomponent package.

Invoke method of an object using Invoke Component in Mule ESB

With the following content:

In order to the Invoke Component can call the hello() method in the HelloWorld class, we need to declare the object of this class as a Spring bean in Spring’s container.

So, just open the mule-esb-invoke-component.xml file and declare the HelloWorld object in the Spring container as follows:

Now, we will create a new flow to see how the Invoke Component works.

Our flow will include the HTTP Listener Connector and the Invoke Component as follows:

Invoke method of an object using Invoke Component in Mule ESB

Inside:

  • The HTTP Listener Connector is configured as follows:

Invoke method of an object using Invoke Component in Mule ESB

General Settings:

Invoke method of an object using Invoke Component in Mule ESB

If you do not know how to configure the HTTP Listener Connector, you can refer to this tutorial!

  • For the Invoke Component, we configure it as follows:

Invoke method of an object using Invoke Component in Mule ESB

Here:

– Name is the name of Endpoint.

– Object Ref is the id of the object in the Spring’s container. In our example, our HelloWorld object has been declared with id as invoke in Spring’s container.

– Method is the name of the method we want to call. My example is the hello() method.

– Method Arguments is the value of the parameters we will pass to the method. If there are multiple parameters, each value will be separated by a comma. In my example, because the hello() method has only one parameter then I declared only one value. And this value is derived from the request’s parameter to the HTTP Listener Connector.

OK, so we have completed a simple flow using the Invoke Component.

Try running it now.
http://localhost:8081/hello?name=Khanh
Result:

Invoke method of an object using Invoke Component in Mule ESB

 

Tham khảo project trên GitHub tại: https://github.com/huongdanjavacom/huongdanjava.com/tree/master/mule-esb-invoke-component


Add Comment