Saturday 25 June 2016

Getting Started with Apache Camel using Spring Boot

Well, I am not going to write post to introduce Apache Camel and EIP concepts. Rather I'll just provide quick highlights of the Spring Boot based project skeleton, which I implemented to integrate hawtio and try it with Apache Camel @ https://github.com/tirthalpatel/Learning-Camel/tree/master/gs-camel-spring-boot-helloworld. For promptly getting started with it, you should obviously know Maven, Java and Spring (not necessarily Spring Boot).

First Things First - Understanding Fundamentals


  • Apache Camel is an open-source, lightweight, integration library that allows your applications to accomplish intelligent routing, message transformation, and protocol mediation using the established Enterprise Integration Patterns and out-of-the-box components with a highly expressive Domain Specific Language (Java, XML, or Scala). With Camel you can implement integration solutions as part of an overarching ESB solution, or as individual routes deployed to any container such as Apache Tomcat, Apache ServiceMix, JBoss AS, or even a stand-alone java process. Read more @ DZone Refcard - Essential Camel Components.
  • Enterprise Integration Patterns (EIP): Integration is a hard problem. To help deal with the complexity of integration problems the Enterprise Integration Patterns (EIP) have become the standard way to describe, document and implement complex integration problems. Apache Camel is an open source project for implementing the EIP easily in a few lines of Java code or Spring XML configuration. Read more @ DZone Refcard - The Top Twelve Integration Patterns for Apache Camel.
  • Integration Framework vs. ESB vs. Integration Suite: See remarkable presentation by Kai Wähner @ Spoilt for Choice: How to Choose the Right Enterprise Service Bus (ESB)?

Get Started with Apache Camel Practically

If you don't  know, what is Spring Boot, then immediately read about it. Believe me, it has already become super popular in Java world. Spring Boot nicely gels with Apache Camel too. Anyway you may get started with Apache Camel by following below steps, even if you don't know Spring Boot.

  1. Download or Clone "gs-camel-spring-boot-helloworld" project from Github.
  2. Prerequisites:
    • Java 1.8+
    • Maven (If maven is not installed on your machine, then just use maven wrapper "mvnw", which is already in project. Be aware that you may need to configure proxy settings, if you are in restricted corporate network.)
    • Spring STS or alternate IDE (Optional, but recommended)
  3. Run maven command at project's root to run project: gs-camel-spring-boot-helloworld > mvn spring-boot:run
  4. This would start Spring Boot's embedded server on default 8080 port. In case you need to change it to different port, then you can configure in "application.properties" file at "gs-camel-spring-boot-helloworld\src\main\resources".
  5. Refer README file to import project in IDE or maven's alternative option to run it.
  6. Once you successfully run it, you should see following logs without errors. Well, App.java does all magic to provide Camel Context with help of Spring Boot. (Alternatively, we may write code for creating Camel Context without using Spring.)
  1. Next, you can see logs for executed example code of router configurations, which is using Camel Java DSL.
  1. Then, open hawtio web console in browser @ http://localhost:8080/hawtio/index.html, which I have already integrated in the project. You can see "HelloWorldRouterFirst.java" has timer component, which triggers events and sends to "direct:helloWorldChannel" end-point. In "HelloWorldRouterSecond.java", it route message from "direct:helloWorldChannel" end-point to further. You can see, "HelloWorldRouterFirst.java" has implemented "Deal Letter Channel EIP". To try it practically, just pause or stop "hw-ex1-second-router-direct-process-log" route and see how it reacts. When "hw-ex1-second-router-direct-process-log" is running, it does its job as per configuration in "HelloWorldRouterSecond.java". When "hw-ex1-second-router-direct-process-log" is unavailable (paused or stopped), all events triggered by "hw-ex1-first-router-timer-bean-direct" route would go to "DeadHelloWorldQueue" queue automatically as per configured Camel provided "Deal Letter Channel EIP".
  1. Likewise, following snapshot speaks about another "HelloWorldJmsRouter.java" example router.
  1. Finally, you can implement few examples in similar way using any Camel supported DSL and Components as per your interest. Just ensure to annotate router component with @Component annotation, implement camel's RouteBuilder and add necessary dependencies in Maven's pom.xml. (Read Apache Camel with Spring Boot post to understand how we get Camel context magically.)

Also Refer

Sunday 19 June 2016

Java power tools series - Performance Analysis

I hope, you have already read "Preface" of my java power tools series. Actually, I was intending to write detailed separate posts on numerous performance diagnostic tools, like I wrote few posts previously as part of this series. Anyway, let me start with quickly recollecting my knowledge on this topic.

Well, performance analysis and optimization is indeed not a child's play. At times, it may be a hard nut to crack for developers, specifically when performance problem is reported by a client in production environment and not replicated in testing or development. In fact, scalability issue is reported as performance issue sometimes, which can be solved by vertical or horizontal scalability instead of unnecessarily spending time in code analysis and optimization activity. Likewise, always performance issue could not be triggered by faulty code, rather there could be inefficient application server or JVM tuning issue! You never know. Therefore, there has to be a thoughtful architectural strategy to accomplish application's performance requirements or for troubleshooting and fixing reported performance problems. Well, Performance Engineering, Benchmarking, Software Performance Testing, Performance Tuning and Java Performance are vast topics by own. So, let me restrict this blog primarily for listing java application performance monitoring, profiling and analysis tools.

Few remarkable tools for performance analysis of Java applications


Problem Statements
My Preferred Tool / Product / Solution
Pricing Remark
Related References
I am damn sure, there are memory related issues. Just need to find memory leaks and reduce memory consumption via memory dump analysis.
Free
 
Just need to analyze java thread dumps.
Free
For non-production environment, need visual interface for Java monitoring and troubleshooting tool, which should provide some basic profiling capabilities too. (may use in production, if performance overhead is not a critical concern!)
Free
Looking for modular and extensible web console, which can be used to manage every kind of container or even any JVM middleware.
Free
For production environment or complex performance troubleshooting needs in non-production environments, need advance Java Profiling tool. Needless to mention, such tool's performance overhead should be minimal or even controllable.
Commercial

(Oracle JMC and JFR requires to purchase license for production use, otherwise it's Free.)
Need of APM solution for Business transactions profiling, root cause detection and performance diagnosis in Development or Test Environment for single JVM or an application. Just limited freely offered "Java performance monitoring with automatic root cause detection" features may be sufficient to find a performance bottleneck. (may use in production for simplistic requirement)
Free

(limited features available compare to commercial offerings)
* All in All, looking for adopting full-fledge Application Performance Management (APM) solution for production, and apparently should work for distributed systems by providing a visual dashboard to manage multiple JVMs across different machines.
* The performance issue is reported in production, but not able to replicate in Development and QA environments, so all are at their wit's end to find the bottleneck in the system! Need to troubleshoot problem directly in production with negligible overhead!

* Java profiling tool is not sufficient for performance analysis. Because performance issues are occurring unexpectedly in production systems and exact business transaction or bottleneck is unknown, which is causing the issues! It could be even Database or external Web Service or Scala component!
Pressing business requirement to discover, diagnostic and resolve application issues before they impact end users, violate SLA or negatively impact the business.
* Need a complete solution to monitor various components of the application and technology stack, such as server, database, hardware, network. In fact, looking for an automated capability in production to identify problematic transactions based on performance thresholds and offer centralized business intelligence like dashboard.
Commercial

(for real production purpose, all are commercial. Most offers SaaS pricing model. Although, some offers On-Premise and Hybrid deployment options too)

The Performance Tuning Lifecycle


If you are newbie to Java performance tuning area, then I strongly suggest to attend less than 2 hours Complete Java Performance Tuning Training course on youtube for fundamental understanding on the following performance tuning lifecycle. Then, you can proceed to choose suitable tools to identify performance bottleneck.
  1. Define Requirements
  2. Measure / Test (Create Baseline)
  3. Identify Bottleneck
  4. Implement Fixes
  5. Measure / Test (New Baseline)
  6. Compare to Old Baseline & Requirements
  7. If necessary repeat steps 3 – 6

Performance Troubleshooting Tools Highlights


You may attend an hour presentation on "Troubleshooting Live Java Web Applications", which I found very informative for the performance troubleshooting tools scoping in production vs. development environment. Specifically at the end of the presentation below final tools comparison chart provides outstanding information.


Also Refer


Disclaimer

I am not biased to particular free or commercial tools, rather my objective is about sharing my own candid experience on set of tools.


If you know or have experienced any other tools suitable for Java applications performance analysis, please share the name of such tool along with your personal feedback in the comment.