Tuesday, March 31, 2015

JBoss Fuse - House Keeping, where to download and what version of JBoss Fuse?

First of all, until today most of my post are done on JBoss Fuse 6.1.x and the version of tool that I am working on is JBoss Developer Studio 7 

Where to download JBoss Fuse?

Go to  http://www.jboss.org/products/fuse/overview/ and click on download



Until today, 2015/3/31 I am still using 6.1.x for my examples and demos. 

Where to download JBoss Developer Studio?

Go to  http://www.jboss.org/products/devstudio/download/, scroll down to download the tested version of JBDS 7.1.1 GA 

Until today, 2015/3/31 I am 7.1.1 GA version for my demos and example, I tend to use the supported and GA version for demo, to avoid any problem. 

What version of JDK?

I use JDK 1.7_xx 

What versions of Camel, CXF and A-MQ are you using?

Reference Red Hat document : 

So here is a guide telling you what versions we are actually using with Fuse. 
Basically, depend on when I did the demo, 
For demo I did with JBoss Fuse 6.1.0 (most of the case)
  • Camel  2.12.0.redhat-610379
  • CXF     2.7.0.redhat-610379
  • AMQ    5.9.0.redhat-610379 
  • Fabric8 1.0.0.redhat-379

and demo I did with JBoss Fuse 6.1.1 I use these version of camel
  • Camel  2.12.0.redhat-611412
  • CXF     2.7.0.redhat-611412
  • AMQ    5.9.0.redhat-611412
  • Fabric8 1.0.0.redhat-412
They are basically very similar.

Where are the repository?

Since JBoss Fuse rely very heavily on maven, make sure you are connect to the right repository. So the repository I use is this one. (Note, I don't normally use the tech preview or snapshot version for demos.)

       <repository>
      <id>release.fusesource.org</id>
      <name>FuseSource Release Repository</name>
      <url>http://repo.fusesource.com/nexus/content/repositories/releases</url>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <releases>
        <enabled>true</enabled>
      </releases>
    </repository>

If there is anything you would like to know, please leave a message.

Monday, March 30, 2015

JBoss Fuse - Fuse workshop 101 - Part Five

So far we have focused on the routing capability of Fuse, which is the wire and plug that integrate different systems together.And for now let's just put Camel aside for a second and take a look at the container our little Fuse project can run on. And some of the tools that might help you while developing.

With JBoss Fuse, you have a number of containers.

  • Standalone Camel process
  • Apache Karaf container
  • JBoss Enterprise Application Server (WildFly)

We have been running it as a single Camel process. In this workshop I want to take a look at the the OSGi container inside JBoss Fuse, which comes from the community project Apache Karaf.

OSGI break the application into multiple modules so it is easier to manage the dependency between each modules, and this nature allows it to become very lightweight without the need to load unused modules. You can make dependency base on different version. Also OSGi helps you set boundaries between modules, so you can hide packages that you don'r want to export.


Within this lightweight container, there will be something already installed for you, for example, the log module actually includes various kind of logging libraries, so you application can use without problem. Deployer that scan for new applications, and provisioning of your application via maven, files, or features... etc. It also has exposed JMX for administration and monitoring. A-MQ is bult-in in the base container, but you have a choice of removing it if needed later.


Speaking of deployment, the unit of deployment is called "Bundle", but it is actually a "jar" file. There are several way you can deploy it onto the container, either place your bundle inside the "deploy" folder(JBoss Fuse installation folder) or you can install it by using a install command and specify the maven detail to load it into the container.

    osgi:install -s mvn:org.apache.camel/camel-core/1.5.0

And after successful installation, your bundle will become a service in side this container, and this service will be visible to other service inside, and uses them if needed.

The console for the container is really powerful, here you can see the list of thing you can see via the console.


Can I use the container in my local environment for development? Yes, through the use of JBoss Developer Studio, it is very easy to debug through it's tooling. Go the the Fuse integration perspective, it will automatically detect JBoss Fuse, and here you could simple run your code on the by container by dragging the project to the bundle folder in JBoss Fuse. And see the execution result.



This is the slide for workshop 5.


Our 5th Camel Ride is all about the Karaf container, after this lab, you should be able to run your camel application on top of it!



Here are the lab instructions.



Here are the other parts of the workshops!

Workshop part 1 - Camel basic and components
Workshop part 2 - Data Transformation 
Workshop part 3 - Enterprise Integration Pattern
Workshop part 4 - Bean Registry

Wednesday, March 25, 2015

JBoss Fuse - Fuse workshop 101 - Part Four

This is probably the easiest part of the entire Camel 101 workshop.  It's very similar with Bean injection in Spring, so with the IoC in mind, in Camel we do the same thing.

First we create our POJO, In side each POJO has either your customize and the business logic, which are the most valuable part in the entire system, or just any helper code you would like to use while developing. The reason for this is to keep things easy to maintain and to have a much more light weight framework.

As soon as we got the POJO or Java Bean, we are ready to register it into the "Registry". In Camel there are few registry available.

  • Simple
  • JNDI
  • ApplicationContext
  • OSGi 

Basically, they are just different place to store your Registry, you can probably guess it by it's name. We use SimpleRegistry mainly in Testing, when you want to use Maps to store your Registry. And obviously JNDI is the default in Camel project. And if you have Spring or OSGi you can always register it there! With JBoss Fuse Project, there is no need to worry about this. We use mostly ApplicationContextRegistry. Then we can "reference" this bean from the route within each Camel Context.

The diagram below shows you how to do it.


It's as simple as that!
About the parameter you pass into the method of POJO, Camel is going to automatically map everything from the body for you, if you have not specifically specified in your reference. Camel actually use runtime look up, so don't expect any error message of misconfigure or misspell during compilation time.

The slide for the workshop are here:


In this exercise, we continue on building the stock trading system, putting real business code that calculate how much money of this person that needs to deduct from this stock trade. As well as that, to speed up the process for VIPs, the vendor decide to introduce Messaging Queue to the game. We now need to deliver the trading into via messaging.


 
Lab instructions are here:



Here are the other parts of the workshops!
Workshop part 1 - Camel basic and components
Workshop part 2 - Data Transformation 
Workshop part 3 - Enterprise Integration Pattern

Monday, March 23, 2015

JBoss Fuse - Fuse workshop 101 - Part Three

It's really difficult to design or architect an Integration project, especially within an Enterprise, there are so many factor to take into considerations.
  • System characteristic
  • Data mapping
  • Interface of systems
  • Risk management
  • Security 
  • And even office politics comes into play, I have to say this is the most time consuming and can quickly become nightmares be not deal carefully. 

This quickly became a headache for architects, and people constantly ask for best practice, I have to say, there are no single best practice, because it is not an ONE SIZE FIT ALL answers, integrating system is all about problem solving. 

So how do we solve an complex integration problem? YUP! you are right! break it down to smaller problem and then tackle them one by one! And fortunately this book "Enterprise Integration Patterns" by Gregor Hohpe has most of the solutions. This book "provides a consistent vocabulary and visual notation to describe large-scale integration solutions across many implementation technologies". 

To put it in my words, it's a collections of patterns, each pattern is to solve a design problem, so by implementing the patterns to the pieces of problem you have already broken down and put the patterns together will give you an idea of where to start from. Of course for every pattern it has it's pros and cons and many things to consider. That why using Camel as the tool that supports EIP will allow you to modify or refine your design with a few easy modification steps! 
For this workshop, we talk about Enterprise Integration Patterns, I will skip all the parts that talks about individual pattern, seriously, it's going to take too long, and there are so many resource on the internet that talks about them. I would recommend you visit the official EIP site to learn what each and every pattern does, and maybe read the book if you have time! It's really helpful. 

Let's look at this Ordering system. Shops from different location sending in order data, it needs to go into both inventory system to check for product availability and accounting system for finance check up. Then the inventory sends the product ready for shipment. At the same time it sends a confirmation email to the customer along with some advertisement and coupons. 


OK, so here is the problem, how do I make sure inventory and accounting system gets the message as soon as possible? what if there is something wrong with customer's payment? How do I make sure the shipments are shipped efficiently? And what about the notification system, how do I deliver it? 

Here are my thoughts on the solution, 
To make sure both inventory and accounting system receives the message at the same time, we will use the "publish and subscribe" pattern, so a copy of the message are send to all receivers. so the inventory and start the inventory check and the shipping process immediately and accounting system can start process it's finance and billing process.


If the payment ever goes wrong, a message will be send to a "invalid message channel", that will be pickup by the inventory system and cancel the shipment.  

The shipment message should be sorted according to different delivery priority and area to delivery and "aggregate" into a bigger chuck so it's easier for delivery truck to divide it's duty, and the content send to delivery system should be "filtered" so it only contains necessary data. As for notification, we also want to make sure we send it to the notification system at the same time, but send an cancelation letter or a successful letter in our "Recipient List". And as well as that, we will also "enrich" the content with coupon and the advertisement that might interest the customer. 


OK, what happen if the online shopping team comes in, and they would also like to do the same thing, but their ordering data comes in with a totally different format, so first, we will certainly reuse what we have ready done. (There is a fine line between reusing code and rewriting it all over, but here we assume the process behind is exactly the same). So by "transforming" the data the same as shops, then publish the content to the existing channel will certainly saves you lots of time!  


Slides for the workshop:

As for lab, continue from last one, this time we are going to separate the processing route for VIP and normal stock purchase. Also we want to introduce another vendor that trade with our system but with orders in one large file, we need to spilt the content before reusing our existing route! 


Lab Instructions:


Here are the other parts of the workshops!
Workshop part 1 - Camel basic and components
Workshop part 2 - Data Transformation 

Wednesday, March 18, 2015

JBoss Fuse - Fuse workshop 101 - Part Two

In an ideal world, all software system should use the same protocol, and passing the same type of documents, but sadly, due to time, needs and other reasons that I can't think of, current software systems are full with different types of protocol and formats of data. As a integration developer, we spend a great deal of time just to make two software system understand each other.

Fuse workshop 101 part two is all about message transformation.


In JBoss Fuse, there are different kind of transformations,

So Format or Type and Message content enrichment or reduction are types of transformation that plays around and changes your message body. and Metadata updates mainly modify the header of your messages.

An example of Format transformation is from XML to CSV or from CSV to JSON, or simply just flattening out from one XML to another. whereas Type transformation is about changing the Object type to another, such as from java.lang.String to java.lang.Integer.

So there are few ways you can do format/type transformation, Camel has built-in component, called Marshal, basically converting from a more higher level of data (here we simply means java bean) to lower levels of data like XML, CVS or JSON etc...

the opposite of that is, of course, Unmarshal. Converting from files into complex java object.

The tooling in JBoss Developer studio will show all the available ready to use data format.
take for example, converting from XML to JSON, this is the why to describe it.

<unmarshal>
  <xmljson/>
</unmarshal>

Or you can do it with JAXB

<unmarshal> 
  <jaxb partClass=“example.TradeOrder” contextPath=“example"/>
</unmarshal>

Another way of transforming the message is to use the transform tag(component) in Camel. It uses various scripting languages, by running message body through the script you set, it will generate the result as the transformed output. Here is an example using javascript.

<javaScript> 
   request.body.toLowerCase()

</javaScript>

OK! Now we have Processor and Bean left, the last two ways of transformation are very similar, in both cases you need to create a java class. You will pass in the message through the Processor or Bean. And inside Processor and Bean, you will add your transformation logic there. This is highly customizable.


The only difference between the two, is the parameter you pass through them, with Process, you need to first implements the camel.Processor interface, then in the execute method, you will find the parameter is the exchange object, so you will have the access to the whole message. Whereas, in Bean, it's just a POJO, by adding the transform logic inside a method, the message will pass through it. And NOTICE, it's only the BODY of the message. So the parameter of the method is actually your message body.

There is another way of transforming messages, using the Enterprise Integration Pattern, there are a few built-in patterns that allows you to easily change or transform your message, I won't go too much detail into that. We will talk about EIP in the later workshop.



Time for another Camel Ride, this time, we are taking the Camel route we built, which is taking a file from a vendor and then place it in another folder for another vendor to retrieve later. Now we know that Vendor sending us the stock ordering info is providing their content in XML, and the vendor that needs this info needs it to be in JSON. And beside both vendor, our company needs to process the content too, and since we are a Java-shop, we want to make sure the content is turned into POJO.

Here is the slides for part 2


And this is the lab instruction.
Enjoy! JBoss Fuse workshop part 3 is coming up next!

Workshop part 1 - Camel basic and components
Workshop part 3 - Enterprise Integration Patterns


Monday, March 16, 2015

JBoss Fuse - Fuse workshop 101 - Part One

On my way to Hong Kong for a day of workshop on JBoss Fuse, and as I go through my Slide deck, I cannot find any decent easy workshop for beginners. Therefore I decide make a workshop that is easy for Camel first timer to get their hands dirty.

The first of part of the workshop is an introduction to Camel, it first goes through what is exactly inside JBoss Fuse.

For part one of the workshop, it takes your through the very basic of Camel, one of the very important component inside JBoss Fuse.
Every Camel need to have a runtime container to run in, inside camel we call it a CAMEL CONTEXT.  Inside every Camel context, you can define lots of camel route and registry, don't worry about what those are, we will explain later.


So inside out blueprint xml, you will see a tag called camelContext.



Next up is camel route, they are a chain of command or process defined by you, as a developer.
Inside the camel route, there are consumer endpoints that listens to the incoming messages, producers the sends message to the destination. and Processor handles validations of the messages, transform message formats and calls the business logics. Basically anything you want to do with the message.


And the message that is routing throughout the camel route is packaged inside Exchange.
Think of Exchange as an envelope that contains the message from previous step, and message to the next step, on the envelope there will be address of the sender and receiver. If there are any problem with the delivery, there will also be problem stamped or states on top of it, shows what's wrong.


Each endpoint on Camel has a URI, this URI needs to fill in by you.



And lastly, using Maven to help you build a Fuse project. it'll take care of the 3 nasty things for you, first it's going to generate a profile layout for you by selecting the right archetype. Secondly, you can manage project dependency with i, just like normal maven project. And last but not least, a maven plugin call fabric8 will help you package and deploy your project.



Here are the slides for the workshop:




And here are the lab instructions,



Enjoy!

Continue on to
Workshop part 2 - Data Transformation
Workshop part 3 - Enterprise Integration Patterns



Friday, March 13, 2015

JBoss Fuse - Easy Load Balancing Web Service with JBoss Fuse

There are few ways to do load balance with web Service, using the Http Gateway is probably the easiest way to do the load balance in Fuse,

First we deploy our restful webservice bundle to 2 containers in Fuse,











by doing so, we have 2 container running the web service on 2 different container with different IP:Port combination.


But, inside your application container, make sure you expose your web service to the fabric. Please see the tips and trick post I post before to see how it is done.

The reason we are doing this, is to register our web service, in this case a restful webservice, is to let fabric know there is a registered service, and know where they are.

Next, we are going to add a http gateway to a container, it will handle all the request dispatching, for load balance, this http gateway will find all the registered service under /servlet and /webapp. Also open up a port for client to connect. 

Create a new container, and add Gateway/http profile to it. 









By default, the http gateway service will provide in port 9000, you can alway change it by changing the port properties inside io.fabric8.gateway.http.properties of Gateway/http profile.


And the default load balance behavior is round-robin, but there are 3 kinds of option you can change to,

  • round-robin
  • random 
  • sticky

and change it by configuring the "FABRIC8HTTPGATEWAY_SERVICE_LOAD_BALANCER" properties inside io.fabric8.gateway.http.properties of Gateway/http profile.

And that's it! Can't believe how easy it was!

So to see it running,
here are both of my services, through the API page, you can see they are both running on different container,






With the http gateway, now I can access the restful service through the gateway.



Thanks, Let me know you feedback.