Tuesday, November 29, 2016

How to Connect Database in Mule Soft ESB

In This tutorial we are going to learn the database connectivity. In mule ESB you can connect to any database but here I will try to connect MySQL Database.

I have created a table and inserted some data in that table:


I am using test database and created empdetails table in it also inserted some records as mention in below image.


Now let’s create a program in Mule and try to connect this database and display the results.

Step 1:

Go to File-New-Mule Project below screen will come and give MuleDBTutorial as project name. 


Now click on finish. Below screen will be there.



Step 2:

Drag the HTTP connector into the canvas.


Step 3:

Drag the Database connector into there and it will look like as below screen.



Step 4:

Add logger connector into canvas to capture the logs.


Step 5:

Click on the HTTP connector and configure the property.


Click on “+” icon, below screen wills popup


Click OK.

Step 6:

 Now click on database and update the property


Click on “+” icon and choose the database from below screen.


Click on the MySQL Configuration and click ‘OK’.



Fill the necessary details.


Click “Add File” button to add “MySQL Driver”. Once you connect MySQL driver all the error will be gone.

Now click on the “Check Connection” icon to test the DB connection.


If all ok then it will give you successful message.

Step 7:

Now click on the database in canvas and configure the property.


Choose the connection configuration as MySQL and chose operation as “Select” and write query inside of “parameterised Query” box.

Step 8:

Now click on “Log connector” and updated the configuration.


Step 9:

 Now run the programme and hit the URL in browser or POSTMAN application, it will give you the object formed data.


Step 10:

If you want a formatted data then add one more connector which can convert object to String and give you proper data.



Now again redeploy and run the program, it will give you the proper data as mention below.


Step 11: 

Now if you want a parameterized data then add a variable as mention below and pass a particular value.


Step 12:

We need to update the database query to get this dynamic value from the variable.
select * from emp where id=#[flowVars.empID];


Step 13:

Now again redeploy and check the results ad mentioned below.


Step 14:

Now if you want to pass a variable from the URL as per your requirement then again go the variable connector and change the value.
#[message.inboundProperties.'http.query.params'.get('EmpIDVal')]


Step 15:

Redeploy it again and check the results by passing a dynamic value.


Change the value again and check results.


Thursday, November 3, 2016

Hello World Programme in Mule Soft ESB

We have already covered basics of Mule ESB in our previous blogs. Now this is the time to create a very basic "Hello World" program and get to know it practically.

To start with Mule soft ESB, you need to have below thing in your system.
  • JDK 1.7
  • Anypoint Studio (if not then download from here)


Step 1: Open Anypoint Studio in your system



Step 2: Go to “File” menu then go to “New” and then click “Mule Project


Step 3: Below screen will be opened and give “Hello World” name to your project.


Step 4: Click “Next” button. It will open below screen, which will show you the location of the project & JRE used.


Step 5: Click on the “Finish” button. Below screen will be opened in which you can see Palette, canvas, project files etc. Screen is very similar to eclipse IDE but you can see graphical canvas screen also over here.


Step 6: Below highlighted part in the screen called “Palette” which provides the inbuilt functional graphical components which can be dragged to canvas to create your programming logic. However you can write it XML code but by using Palette you can design your code very easily. All you need to drag to canvas the functionality you want.


Step 7: I am using HTTP component to start with Hello World program. You can find it in Palette or just write in the search box it will appear and drag it to your canvas screen.


Step 8: Once you drag it to your screen it will look like below image, in a same way drag one more component called “setPayload”.


Step 9: Select on the “HTTP” and click on “Message Flow”, you can see the below screen. Click on the highlighted Red Square to make your connector configuration.


Step 10: Below screen will pop up which has Port, Host Name and generic Name in it (Which is already filled).


Step 11: Click on the “OK” button.



Step 12: Now select “SetPayload” and click on the “Message Flow”. Define the value “Hello World” as highlighted.


Step 13: You can see the code by clicking the “Configuration XML” tab.


Step 14:  You are all set to go! Right click on the canvas and run project as “Hello World”. If everything goes fine in the console log then you can see the output in browser.


Step 15: Open your favorite browser and hit “http://localhost:8081” URL as shown below, you will be able to see the output of your first Mule ESB program!



Introduction to Mule Soft ESB

Mule ESB is Java bases Enterprise Service Bus. This is very light weight and provides facility to developer to integrate their different application without having any kind of dependency. It provides a very easy integration and enables different application to exchange their data.




Mule ESB provides the some powerful capabilities as mentioned below:

Orchestration:         
You can create and host a web service which can be used any time. You can do call different web service and design your own orchestration as per your requirement

Service Mediation:
Shield services from message formats and protocols. You can create different logic from the messaging and enable local independent service.

Message routing:
You can use router, filter, aggregate sequence to create your logic and route the message accordingly

Data transformation:
You can exchange the data in different formats and transport protocols.

Conversion:
You can receive any kind of message as input and transform to different message format as per your requirement

It can be easily integrate from POJO to any other component. It provides the reusable facility to developer without making any change in existing component because all logic or unit can be developed separately.

Mule Flow

Mule flow is a sequence of message processing events


Message Processor

These are the prepacked functionality that processes the message. Some of them are defined below.

  • Endpoints
  • Scope
  • Component
  • Transformers
  • Filters
  • Flow Control
  • Error Handling



Mule Security

Mule provides a very strong security with their own component

  • Mule Security Manager
  • Mule Security API
  • Pluggable Security Manager
  • Spring Security