Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Mule with Velocity

ramya
December 22, 2015

Mule with Velocity

Mule with Velocity

ramya

December 22, 2015
Tweet

More Decks by ramya

Other Decks in Education

Transcript

  1. Have you ever wondered how to send an email through

    Mule Esb with a well designed format and where you can pick up some dynamic values from properties file and designed your email from a pre defined template and design in a colourful format with colourful text and logos ?? Yes you can design that email for your customers, subscribers or anybody else you wish to. Mule can trigger mail with a pre defined template where you can design the body of your email with different HTML tags and put various texts, text colour, images, logos in your email body and also pic some dynamic values in it. To design the template you only need a minimum knowledge of HTML tags and can design the template easily. Yes .. I am talking about Mule with Velocity template for your mail .. Ramya
  2. Before we start, we will see what is Velocity template.

    Velocity is an open source templating tool developed by an international volunteer community and hosted by the Apache Software Foundation's Jakarta Project. You can find more information on it here :- https://velocity.apache.org/engine/releases/velocity- 1.5/user-guide.html#what_is_velocity To integrate Velocity template with Mule you will find good examples over net. There is already example by great David Dossot of using Velocity transformer class here :- https://muleinaction.googlecode.com/svn-history/r490/branches/mule-3/chapter05/velocity- transformer/src/main/java/com/muleinaction/transformer/MarkingVelocityMessageTransformer.jav a I have just modified the code and reused it as per my requirement Ramya
  3. So, we first need a Velocity transformer Java class as

    following :- This class will set the email payload, map the external dynamic values with the email Ramya
  4. So, we will also have external values from properties files

    as following :- These values from properties file will make the Velocity template dynamic as it will pick the values form here and set to the mail body .. Values like customer or subscriber name can be defined here dynamically Name=User Subs=Team Ramya
  5. So, we will also have external values from properties files

    as following :- Here you can see, file is picked up by the flow and the file content is set as message body of the email along with other dynamic values from external properties file Ramya
  6. And finally our Velocity template is as following :- Here

    you can see the HTML codes like <p/>, <img/> <html> tags are used to design the email content .. Also, values like $FileName, $Subscriber are picked from properties file. Also $payload is the content from the inbound file and it is appended with this mail body. Isn’t these are dynamic !!!! Ramya
  7. Let’s test our application now.. Let’s place a file in

    the inbound folder with a content say This message is from a file !!! And start our application … we will see the console as following :- You can see the email has been send successfully and the email body as a preview in the log .. Ramya