Saturday, March 31, 2012

Monitoring camel routes using camel-bam

Last week I got a question from an Apache Camel user about ways to get statistics on the activity on a route, including errors. There are quite a few ways to achieve that. First there are obviously the logs, but they are mostly useful to investigate a particular problem. Then there are the performance counters (defined in the org.apache.camel.api.management package) that could be obtained either via the JMX support or even exposed as a RESTful service. If one wants to be more fancy she could use a custom ErrorHandler.

There are however situations when message processing is faulty even when all individual messages are processed correctly. As an example, messages not processed in time can lead to service level agreement violations, or messages may be missing, or other business process execution use cases. While not pretending to compete with more specialized tools for business processes (such as BPEL or BPM engines) and while being inherently stateless, camel does offer support for scenarios like the ones described above, via the camel-bam component.

The BAM component is actually one of the rare exceptions that implements a stateful engine using JPA and a database of your choice. It also offers a very neat way to correlate messages by using Expressions (typical camel style) that evaluates against a message to produce a value used for correlation. As such, messages don't necessarily need to have an explicit correlation identifier as long as one can be computed from the content of the message, which means that it can normally be retrofitted to support systems not designed with correlation in mind. At its core camel-bam provides a set of temporal rules that trigger events. These events are processed by camel via processes (called activities) that are nothing else but specialized routes. BAM also offers a dsl for building activities via a ProcessBuilder (which is actually a specialization of the RouteBuilder you may be more familiar with).

That said, I put together a small example in my github account. It illustrates some very basic banking operations (like debits and credits from an account). The relevant part of the process is in ActivityMonitoringBuilder.configure() and looks something like this:

  ActivityBuilder teller = activity("direct:monitor-teller")
    .name("teller").correlate(xpath("/operation/@account"));
  ActivityBuilder office = activity("direct:monitor-office")
    .name("office").correlate(xpath("/operation/@account"));
  ActivityBuilder errors = activity("direct:monitor-errors")
    .name("errors").correlate(header("SampleRef"));
        
  office
    .starts().after(teller.completes())
    .expectWithin(Time.seconds(1))
    .errorIfOver(Time.seconds(1)).to("mock:overdue");
        
  errors
    .starts().after(teller.completes())
    .expectWithin(Time.seconds(1))
    .errorIfOver(Time.seconds(5)).to("mock:error");


The trigger events are generated when regular message flow down the routes defined in the BusinessProcessBuilder.

If you have more questions about how this example works (or bam in general) drop me a note or ask on the camel users@ lists. Enjoy!

18 comments:

  1. Hi, i'm in process of adopting Camel BAM to our needs and found a curios thing - processed messages are not kept and there is no way to reference them in error Route. Maybe i'm missing something? Also what is the difference between expectedWithin and errorIfOver?

    Thanks

    ReplyDelete
  2. Here is my blog post about monitoring alternatives for Apache Camel:

    http://www.kai-waehner.de/blog/2013/07/15/apache-camel-and-talend-esb-management-and-monitoring-of-integration-routes-and-soap-rest-web-services-jmx-osgi-logstash-elasticsearch-kibana-hawtio

    My favorite is Kibana, a great open source project for creating dashboards based on log files.

    ReplyDelete
  3. Nice informative coding u shared,thanks for sharing,keep sharing...

    Mcx Hni Tips

    ReplyDelete
  4. I know it is an old blog post, but is it possible to get the Code?

    ReplyDelete
  5. Thanks for writing this great article! It’s very informative, and you included some great points to the equally great article regarding Operations Support System.

    ReplyDelete
  6. Lawyers communicate effectively with clients, judges, juries, and other legal professionals both verbally and in writing. Lawyers adhere to professional ethics and legal standards while representing their clients' interests with integrity and diligence.
    Top Bus Accident Lawyers

    ReplyDelete
  7. Online Lenders: Many online lenders specialize in loans for individuals with bad credit and can offer instant or fast approval processes. Credit Unions: Credit unions may offer more favorable terms and rates compared to traditional banks and may be more willing to work with individuals with bad credit. Peer-to-Peer Lending: Platforms that connect borrowers with individual investors. These platforms may offer more flexible terms.
    Best Instant Personal Loan

    ReplyDelete
  8. Medical loan PriceAugust 2, 2024 at 4:55 AM

    The lender could also look at the amount of your down payment since it can determine whether they will accept mortgages or other loans with higher terms.
    Medical loan Price

    ReplyDelete
  9. Condo Insurance PolicyAugust 3, 2024 at 4:13 AM

    If you're looking to purchase an Condo Insurance policy to ensure that your financial stability of loved ones following your death, be sure you select the right amount of coverage as well as the best type of Condo insurance.
    Best Condo Insurance Policy

    ReplyDelete
  10. You may even be able to prequalify for your loan online, allowing you to compare potential offers before applying. Another option is to borrow from family or friends. Loans for Personal Installment

    ReplyDelete
  11. While it is important to ask an attorney about their track record, you also need to know how that relates to your specific case. For example, if you are seeking a divorce lawyer and the attorney says they have handled many divorce cases, but only a few personal injury cases, that may not be the best fit for your needs.
    Cheap usa Lawyer in Florida
    Car Accident Attorney in Chicago
    personal injury lawyer in New Jersey

    ReplyDelete
  12. A life insurance policy provides peace of mind knowing that your loved ones will not be left behind with a large financial burden after your death. There are many factors that should be considered when purchasing life insurance, and a financial professional is a good resource for help in this area.
    Maroon Financial Credit Union
    Right Loan Company
    fast cash loans online in Ohio

    ReplyDelete
  13. Your coverage will depend on the type of policy you have and may include liability, collision, comprehensive, medical payment and uninsured motorist coverage. It is also recommended to have higher than minimum liability limits as this will provide some protection should you be sued for an accident you cause that results in injury or death to others.
    Personal Accident Insurance Coverage
    Union funds accuse Markel
    Short Term Disability Insurance

    ReplyDelete
  14. A financial plan is a roadmap that helps you manage your money. It includes a budget, saving strategies, avoiding debt and investing in your future. Having a plan reduces the stress that comes with living paycheck to paycheck and provides peace of mind about your finances.
    Best loan in Massachusetts
    Food Truck Loan
    Personal Loans Provider company

    ReplyDelete
  15. Topest lawyer companies in Massachusetts
    Lawyers need excellent communication skills to express ideas orally and in writing. Car Accident Lawyer Chicago They must also be adept negotiators to resolve disputes and reach favourable agreements with opposing parties. Legal lawyers in Indiana

    ReplyDelete
  16. Getting a policy approved quickly requires knowing all the options available to you. Having an agent review your needs and budget to help select the right plan can save time. Hartford and Capital Credit Union clash over $3 million
    Gary Semmer on building a stronger future
    Aon unveils AI tool to spot supply chain weaknesses
    If the policy requires a medical exam, scheduling it soon can expedite the process.

    ReplyDelete
  17. Sometimes, it makes sense to borrow money for things that improve your life over the long term. But borrowing can also be expensive if you don’t manage your debt wisely. Before you apply for a personal loan, take some time to review your options and make sure the monthly payment fits in with your budget. This will help ensure you’re not overborrowing.
    Top 25 Best Loan Provider
    20 Loan Providers
    21 Food Truck Loan provider

    ReplyDelete