[[BAM-BusinessActivityMonitoring]]
Business Activity Monitoring
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The *Camel BAM* module provides a Business Activity Monitoring (BAM)
framework for testing business processes across multiple message
exchanges on different Endpoint instances.

Consider, for example, a simple system in which you submit Purchase
Orders into system A and then receive Invoices from system B. You might
want to test that, for a given Purchase Order, you receive a matching
Invoice from system B within a specific time period.

[[BAM-HowCamelBAMWorks]]
How Camel BAM Works
^^^^^^^^^^^^^^^^^^^

Camel BAM uses a link:correlation-identifier.html[Correlation
Identifier] on an input message to determine the _Process Instance_ to
which it belongs. The process instance is an entity bean which can
maintain state for each _Activity_ (where an activity typically maps to
a single endpoint - such as the submission of Purchase Orders or the
receipt of Invoices).

[source,java]
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
return new ProcessBuilder(entityManagerFactory, transactionTemplate) {
    public void configure() throws Exception {
 
        // let's define some activities, correlating on an XPath on the message bodies
        ActivityBuilder a = activity("seda:a").name("a")
                .correlate(xpath("/hello/@id"));
 
        ActivityBuilder b = activity("seda:b").name("b")
                .correlate(xpath("/hello/@id"));
 
        // now let's add some rules
        b.starts().after(a.completes())
                .expectWithin(seconds(1))
                .errorIfOver(seconds(errorTimeout)).to("mock:overdue");
    }
};
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

You can then add rules to be triggered when a message is received on any
activity - such as to set time expectations or perform real time
reconciliation of values across activities.

[[BAM-SimpleExample]]
Simple Example
^^^^^^^^^^^^^^

The following example shows how to perform some time based rules on a
simple business process of 2 activities - A and B - which correspond
with Purchase Orders and Invoices in the example above. If you would
like to experiment with this scenario, you may edit this
http://svn.apache.org/repos/asf/camel/trunk/components/camel-bam/src/test/java/org/apache/camel/bam/BamRouteTest.java[Test
Case], which defines the activities and rules, and then tests that they
work.

As you can see in the above example, we first define two activities, and
then rules to specify when we expect them to complete for a process
instance and when an error condition should be raised.p. The
ProcessBuilder is a RouteBuilder and can be
added to any CamelContext.

[[BAM-CompleteExample]]
Complete Example
^^^^^^^^^^^^^^^^

For a complete example please see the link:bam-example.html[BAM
Example], which is part of the standard Camel
Examples

[[BAM-UseCases]]
Use Cases
^^^^^^^^^

In the world of finance, a common requirement is tracking trades. Often
a trader will submit a Front Office Trade which then flows through the
Middle Office and Back Office through various systems to settle the
trade so that money is exchanged. You may wish to test that the front
and back office trades match up within a certain time period; if they
don't match or a back office trade does not arrive within a required
amount of time, you might signal an alarm.
