Thursday, February 13, 2014

Introduce Mule ESB

Introduction

The video for this blog is available at:
http://www.youtube.com/watch?v=wVCmik-2xAM&feature=youtu.be

Mule and JBoss Fuse ESBs are most popular open source ESBs on the market. They are the leaders. I have been working with both for numerous years. Both of them have their strengths and weakness. I discuss these further in my later blog. Today, I am going to describe Mule 101 from development point of view. I am going to cover the following aspects:

  • Install Mule Studio
  • Install Mule MMC and Runtime
  • Develop Hello World Mule Application
  • Build Mule Project With Maven
  • Mule Application Deployment

Install Mule Studio

You can download both Mule Studio and MMC from http://www.mulesoft.com/platform/soa/mule-esb-enterprise. You will need to fill a form so that Mule can track you down, and hopefully you will buy their product. I downloaded the following two file to ~/Downloads on my MacBook:

   mmc-distribution-mule-console-bundle-3.4.2.zip
   MuleStudio-for-macosx-64bit-3.5.0-201312091746.zip

As you can see the current mule run time is version 3.4.2 and Mule Studio is 3.5. Execute the following commands [My current dir is ~/Downloads]:

jar vxf mmc-distribution-mule-console-bundle-3.4.2.zip
jar vxf MuleStudio-for-macosx-64bit-3.5.0-201312091746.zip
mv MuleStudio ~/.
mv mule-enterprise-standalone-3.4.2 ~/.

Now, I have both Mule Studio and runtime under my home directory. Let's develop a Hello World Application.

Develop Hello World Mule Application

Start MuleStudio.app [Make sure it is executable]. Enable the maven setting by editing the Preferences as shown below:

To create a mule project, New -> Mule Project. Make sure create maven project as shown below:

As shown below, the MuleStudio will create a project with the following structures.

Now let's develop a simple application using HTTP component. Perform the flowing actions:

  • Double click the mule flow file under flow directory
  • Drag and drop the HTTP component
  • Drag and drop the Logger component
  • Double click the Logger icon in side the flow
  • Fill the groovy script as shown below




    
        
        
    


Now, we can run the mule application inside the studio by right click the the file hello-world.mflow file, run as, Muel application. You should see the following output in the studio console:

NFO  2014-02-15 14:33:05,294 [main] org.mule.module.management.agent.JmxAgent: Registered Connector Service with name Mule.hello-world:type=Connector,name="connector.http.mule.default.1"
INFO  2014-02-15 14:33:05,297 [main] org.mule.DefaultMuleContext: 
**********************************************************************
* Application: hello-world                                           *
* OS encoding: US-ASCII, Mule encoding: UTF-8                        *
*                                                                    *
* Agents Running:                                                    *
*   Clustering Agent                                                 *
*   JMX Agent                                                        *
**********************************************************************
INFO  2014-02-15 14:33:05,297 [main] org.mule.module.launcher.MuleDeploymentService: 
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ Started app 'hello-world'                                +
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Open a web browser, and enter the following URL
http://localhost:8081/echo?UserName=Gary Liu
You should see the following on your browser:
/echo?UserName=Gary%20Liu

At this point, we have created a simple mule application using HTTP and Logger components coming with mule. This process is good for development and unit testing. However, we normal build the application using maven and later perform continuous integration using other utility like Jenkins. Now, let me explain the build process using maven.

Build Mule Application With Maven

In order to build maven project created through MuleStudio, we need to uncomment all the following dependencies:

 

  



  

One more thing before we can build using maven. Execute the folloing script under MuleStudio installation dir [~/MuleStudio]. This is to install licm jar file to our local maven repo.

mvn install:install-file \
 -Dfile=plugins/org.mule.tooling.server.3.4.1.ee_3.4.1.201312062152/mule/plugins/mule-plugin-debugger-3.4.1/lib/licm-1.1.3.jar \
 -DgroupId=com.mulesoft.licm \
 -DartifactId=licm \
 -Dversion=1.1.3 \
 -Dpackaging=jar

Now, we can build the Hello World mule application we just developed. Let's do the following:

cd ~/MuleStudio/workspace/hello-world
mvn clean install

The maven build process takes now time. If you check the target directory, there is a file named as: hello-world-1.0.0-SNAPSHOT.zip. This is the file we will deploy to the mule runtime. If you are curious enough and wander what are the contents inside that zip file, you can do the following:

[/Users/Gary2013/MuleStudio/workspace/hello-world]$ cd target
[/Users/Gary2013/MuleStudio/workspace/hello-world/target]$ jar vtf hello-world-1.0.0-SNAPSHOT.zip 
   989 Sat Feb 15 14:33:02 CST 2014 hello-world.xml
     0 Sat Feb 15 14:14:20 CST 2014 mule-app.properties
   119 Sat Feb 15 14:33:02 CST 2014 mule-deploy.properties
     0 Sat Feb 15 15:01:22 CST 2014 classes/
   989 Sat Feb 15 15:01:22 CST 2014 classes/hello-world.xml
     0 Sat Feb 15 15:01:22 CST 2014 classes/mule-app.properties
   119 Sat Feb 15 15:01:22 CST 2014 classes/mule-deploy.properties
[/Users/Gary2013/MuleStudio/workspace/hello-world/target]$ 

This is the beauty about mule. Its application is very clean and minimum comparing with osgi bundles. Mule will be able to figure out dynamically what jar files should be linked during runtime. Once the application zip file is build, we can deploy it to the mule runtime.

Mule Application Deployment

There is a README.txt file under mule runtime installation [in my case, it is ~/mule-enterprise-standalone-3.4.2]. In that will, the start, stop and restart procedures are described. Let's start the mule as daemon by run the following command:
[/Users/Gary2013/mule-enterprise-standalone-3.4.2]$ bin/mule start
MULE_HOME is set to /Users/Gary2013/mule-enterprise-standalone-3.4.2
Starting Mule Enterprise Edition...
[/Users/Gary2013/mule-enterprise-standalone-3.4.2]$

Now, we can check what java process is mule runtime. Here is what I see:

[/Users/Gary2013/mule-enterprise-standalone-3.4.2]$ ps -eaf | egrep java | egrep -v egrep 
  501 17266 17265   0  3:19PM ??         0:32.28 /Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home/bin/java -Dmule.home=/Users/Gary2013/mule-enterprise-standalone-3.4.2 -Dmule.base=/Users/Gary2013/mule-enterprise-standalone-3.4.2 -Djava.net.preferIPv4Stack=TRUE -XX:MaxPermSize=256m -Djava.endorsed.dirs=/Users/Gary2013/mule-enterprise-standalone-3.4.2/lib/endorsed -Xmx1024m -Djava.library.path=%LD_LIBRARY_PATH%:/Users/Gary2013/mule-enterprise-standalone-3.4.2/lib/boot -classpath %MULE_LIB%:/Users/Gary2013/mule-enterprise-standalone-3.4.2/conf:/Users/Gary2013/mule-enterprise-standalone-3.4.2/lib/boot/commons-cli-1.2.jar:/Users/Gary2013/mule-enterprise-standalone-3.4.2/lib/boot/commons-codec-1.3-osgi.jar:/Users/Gary2013/mule-enterprise-standalone-3.4.2/lib/boot/jul-to-slf4j-1.6.1.jar:/Users/Gary2013/mule-enterprise-standalone-3.4.2/lib/boot/licm-1.1.4.jar:/Users/Gary2013/mule-enterprise-standalone-3.4.2/lib/boot/log4j-1.2.16.jar:/Users/Gary2013/mule-enterprise-standalone-3.4.2/lib/boot/mule-module-boot-ee-3.4.2.jar:/Users/Gary2013/mule-enterprise-standalone-3.4.2/lib/boot/mule-module-logging-3.4.2.jar:/Users/Gary2013/mule-enterprise-standalone-3.4.2/lib/boot/oscore-2.2.4.jar:/Users/Gary2013/mule-enterprise-standalone-3.4.2/lib/boot/propertyset-1.3.jar:/Users/Gary2013/mule-enterprise-standalone-3.4.2/lib/boot/truelicense-1.29.jar:/Users/Gary2013/mule-enterprise-standalone-3.4.2/lib/boot/truexml-1.29.jar:/Users/Gary2013/mule-enterprise-standalone-3.4.2/lib/boot/wrapper-3.5.19.jar:/Users/Gary2013/mule-enterprise-standalone-3.4.2/data-mapper -Dwrapper.key=d4wYZG88GHn1riyEuxVDypA4M4y9i5w4 -Dwrapper.port=32000 -Dwrapper.jvm.port.min=31000 -Dwrapper.jvm.port.max=31999 -Dwrapper.disable_console_input=TRUE -Dwrapper.pid=17265 -Dwrapper.version=3.5.19-st -Dwrapper.native_library=wrapper -Dwrapper.arch=universal -Dwrapper.service=TRUE -Dwrapper.cpu.timeout=10 -Dwrapper.jvmid=1 -Dwrapper.lang.domain=wrapper -Dwrapper.lang.folder=../lang org.mule.module.reboot.MuleContainerBootstrap start0
[/Users/Gary2013/mule-enterprise-standalone-3.4.2]$ 

The deployment procedure is covered pretty well http://www.mulesoft.org/documentation/display/current/Application+Deployment. Simple, we can copy the zip file from target to the apps directory.

cp ~/MuleStudio/workspace/hello-world/target/hello-world-1.0.0-SNAPSHOT.zip  .

Mule has a feature called hot-deployment. Once the zip file is dropped to the apps dir, mule will unzip the archive, delete it, and create a file named like: hello-world-1.0.0-SNAPSHOT-anchor.txt. Inside that file, there is a line of text. The meaning of text is not important. Mule is just using it as key to monitor the application. To undeploy the application, you can simply delete the anchor file.

51 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. thanks a lot ..it would ve been better if u were a bit little more basic (simple step by step) so that a fresher or a beginer like me can cope up good

    ReplyDelete
  3. This was very good. I'm not sure what you could've done to make it "a bit little more basic". I've encountered a problem with v5.4 (rebranded to Anypoint), where the inbound-endpoint has been deprecated and we're supposed to use http:listener. I've tried to follow your guide as much as I can, but the logger message is not being returned by the listener. I'll try to post an update if I figure it out.

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
  4. Edit: It appears that the http:listener requires the use of a set-payload transformer to obtain the response value to be returned. The logger element is not a valid subelement of an http:listener and cannot set the payload for the response. Indeed, the logger element logs whatever is set in the message property to the console for logging purposes.

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete
  6. GregS - I am new to mule and was started by this example, i just cant get the response in the browser, though my lister is running and it captures logging details in console.

    ------------------












    -----------------

    ReplyDelete












  7. --i created this but not getting response back, my app starts fine and logs what I pass in input:

    http://localhost:8081/?UserName=Nishan

    ReplyDelete
  8. This comment has been removed by the author.

    ReplyDelete
  9. have u tried XML to JASON element from mule studio instead of using the transformer element ? what is the use of this element ? and do u have a sample ?

    ReplyDelete
    Replies
    1. Dataweave is the most powerful tool for transform different data types, from xml to json, csv to json, json to xml etc.

      Delete
  10. Replies
    1. I have two video tutorial on DataWeave on YouTube. Let me know if that will help

      Delete
  11. how to call mule flow using java client

    ReplyDelete
    Replies
    1. Hi Buddy,


      Nice to be visiting your blog again, it has been months for me. Well this article that i’ve been waited for so long.

      MuleSoft is the most recent "unicorn" to petition for an IPO. The organization, which enables organizations to like Netflix and Spotify with their APIs, has revealed its financials to people in general in a S-1 recording, recommending that they are focusing on a presentation when March.
      The span of the proposed IPO is $100 million, yet that is liable to change.





      Very useful post !everyone should learn and use it during their learning path.


      Kind Regards,

      Delete
  12. Xin chào GAry Liu

    My name is Tuan Khanh, I am Vietnamese. I watched your video clip about MULE, it's great. I am doing a MULE exercise but I have not done it yet, hope you help. Thank you very much. You give me the address EMAIL.

    ReplyDelete
  13. You wrote an excellent article thank you for sharing Mulesoft online training

    ReplyDelete
  14. Thank you for sharing such detailed article.
    Mulesoft Online course India

    ReplyDelete
  15. Thank you so much for sharing with us. Appreciate them, Mulesoft Online Training Hyderabad

    ReplyDelete

  16. That is very interesting; you are a very skilled blogger. I have shared your website in my social networks! A very nice guide. I will definitely follow these tips. Thank you for sharing such detailed article.

    Mulesoft online training

    ReplyDelete
  17. Iam very impressive your site gives the best and the most interesting information. This is just the kind of information that i had been looking for, i'm already your rss reader now and i would regularly watch out for the new posts, once again hats off to you..

    Mulesoft online training bangalore

    ReplyDelete
  18. Very informative post! There is a lot of information here that can help

    Dot Net Online Training Hyderabad

    ReplyDelete
  19. the blog is about Gary Liu's Technical Knowledge Base it is useful for students and Mulesoft Developers for more updates on Mulesoft follow the link

    mulesoft Online Training

    For more info on other technologies go with below links

    Python Online Training

    tableau online training hyderabad

    ServiceNow Online Training

    ReplyDelete
  20. the blog is good and Interactive it is Introduce Mule ESB it is useful for students and Mulesoft Developers for more updates on Mulesoft

    https://onlineitguru.com/mulesoft-online-training.html

    ReplyDelete
  21. Howdy would you mind sharing which blog platform you're working with? I'm going to start my own blog soon but I'm having a hard time choosing between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your design seems different then most blogs and I'm looking for something unique. P.S My apologies for being off-topic but I had to ask! it services melbourne

    ReplyDelete
  22. the blog is good and Interactive it is about Mulesoft Developer it is useful for students and Mulesoft Developers for more updates on Mulesoft mulesoft Online course

    ReplyDelete
  23. Interesting stuff which is helpful..

    Just an important heads up you can get more details by following this blog which was quite helpful for me.

    Mulesoft Introduction

    ReplyDelete
  24. Hi There,
    Gasping at your brilliance! Thanks a tonne for sharing all that content. Can’t stop reading. Honestly!

    User management and provisioning have always been tedious and time-consuming tasks for IT professionals. If you’ve seen any of my blog posts before, you’ll know that there are two things I like: exposés in the form of parentheses and removing tedious manual work.
    Naturally, this meant I ended up trying to solve user management
    . One of the first questions I asked when I started addressing this problem was: why hasn’t this been solved yet?

    I read multiple articles and watched many videos about how to use this tool - and was still confused! Your instructions were easy to understand and made the process simple.

    Thanks,
    Irene Hynes

    ReplyDelete
  25. You made some good points there. I did a search on the topic and found most people will agree with your blog..

    Also Visit this site to learn more about MuleSoft Online Training.

    ReplyDelete
  26. Your blog is really awesome thanks for sharing most valuable information with us, Mulesoft Online Training

    ReplyDelete
  27. Nice information about test automation tools my sincere thanks for sharing post Please continue to share this post.
    MULESOFT TRAINING

    ReplyDelete
  28. the blog is good and Interactive it is about Mulesoft Developer it is useful for students and Mulesoft Developers for more updates on Mulesoft mulesoft Online training hyderabad

    ReplyDelete
  29. Really Thanks For Posting Such a Useful Content. Really Thanks For Sharing Such an Informative Post.
    Mulesoft Certification Training

    ReplyDelete
  30. Great article ...Thanks for your great information, the contents are quiet interesting.
    Mulesoft Online Training

    ReplyDelete
  31. https://mulesoft-technology.blogspot.com/2017/07/integration-with-microsoft-sharepoint.html?showComment=1575177594131#c6284138410807064724

    ReplyDelete
  32. Thanks for sharing valuable information and very well explained. Keep posting.

    workday training
    workday online course

    ReplyDelete

Anypoint Studio Error: The project is missing Munit lIbrary to run tests

Anypoint Studio 7.9 has a bug. Even if we following the article: https://help.mulesoft.com/s/article/The-project-is-missing-MUnit-libraries-...