13
Mule with Velocity

Mule with velocity

Embed Size (px)

Citation preview

Page 1: Mule with velocity

Mule with Velocity

Page 2: Mule with velocity

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 ..

Page 3: Mule with velocity

How can we use Velocity template with Mule?

Page 4: Mule with velocity

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.java

I have just modified the code and reused it as per my requirement

Page 5: Mule with velocity

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

Page 6: Mule with velocity

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

Page 7: Mule with velocity

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

Page 8: Mule with velocity

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 !!!!

Page 9: Mule with velocity

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 ..

Now let’s check our actual email

Page 10: Mule with velocity

Here is the mail we received from Mule with Velocity template and here what we got :-

You can see different text formats, bold texts , images , logos etc that was designed in Velocity template with HTML codes. Also, you can see the values are picked from properties file

Page 11: Mule with velocity

So, here you can see how to set a email body colourful and dynamic using Mule and Velocity template !!!….

Page 12: Mule with velocity

In my next slide I will bring some other techniques in Mule implementation .Hope you have enjoyed this simpler version. Keep sharing your knowledge and let our Mule community grow

Page 13: Mule with velocity

Thank You