Application:
     B



                BPM




                BAM




 Application:
      A
é




                   Apache ServiceMix : Bus d’intégration (Flux,
     FUSE ESB	     processus techniques) basé sur JBI et OSGI	


  FUSE Message     Apache ActiveMQ : Courtier de messagerie (MOM) basé
     Broker	       sur JMS	



       FUSE         Apache CXF : permet de créer ou consommer des
     Services       Services Web	
    Framework 	


FUSE Mediation 
   Apache Camel : moteur de routage permettant de
    Router	        créer des patterns d'intégration avec une formation
                   minimale grâce à un langage Java simple ou avec XML
#
# Framework selection properties
#
karaf.framework=equinox

#
# Location of the OSGi frameworks
#
karaf.framework.equinox=${karaf.default.repository}/org/eclipse/osgi/....
karaf.framework.felix=${karaf.default.repository}/org/apache/felix/.....
<groupId>fr.aimaf</groupId>
	   <artifactId>Example</artifactId>
	   <packaging>bundle</packaging>
	   <version>0.1</version>
	   <name>Aimaf Example :: Camel OSGi Bundle</name>
Expéditeur:                   Destinataire
Application                   Application
     A                             B




              Queue
                  Queue
                      Queue
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
      xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
      xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"
      xmlns:amq="http://activemq.apache.org/schema/core">
  <!-- Allows us to use system properties as variables in this configuration file -->
  <ext:property-placeholder />
  <broker xmlns="http://activemq.apache.org/schema/core" brokerName="default" dataDirectory="${karaf.data}/activemq/default" useShutdownHook="false">
    <destinationPolicy>
       <policyMap>
        <policyEntries>
          <policyEntry topic=">" producerFlowControl="true" memoryLimit="1mb">
           <pendingSubscriberPolicy>
            <vmCursor />
           </pendingSubscriberPolicy>
          </policyEntry>
          <policyEntry queue=">" producerFlowControl="true" memoryLimit="1mb">
          </policyEntry>
        </policyEntries>
       </policyMap>
    </destinationPolicy>
    <!-- Use the following to configure how ActiveMQ is exposed in JMX -->
    <managementContext>
       <managementContext createConnector="false"/>
    </managementContext>
    <persistenceAdapter>
       <kahaDB directory="${karaf.data}/activemq/default/kahadb"/>
    </persistenceAdapter>
    <!-- The transport connectors ActiveMQ will listen to -->
    <transportConnectors>
       <transportConnector name="openwire" uri="tcp://localhost:61616"/>
       <transportConnector name="stomp" uri="stomp://localhost:61613"/>
    </transportConnectors>
  </broker>

  <bean id="activemqConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">

    <property name="brokerURL" value="tcp://localhost:61616" />
  </bean>

  <bean id="pooledConnectionFactory" class="org.apache.activemq.pool.PooledConnectionFactory">
    <property name="maxConnections" value="8" />
    <property name="connectionFactory" ref="activemqConnectionFactory" />
  </bean>

  <bean id="resourceManager" class="org.apache.activemq.pool.ActiveMQResourceManager" init-method="recoverResource">
     <property name="transactionManager" ref="transactionManager" />
     <property name="connectionFactory" ref="activemqConnectionFactory" />
     <property name="resourceName" value="activemq.default" />
  </bean>

  <reference id="transactionManager" interface="javax.transaction.TransactionManager" />
  <service ref="pooledConnectionFactory" interface="javax.jms.ConnectionFactory">
    <service-properties>
       <entry key="name" value="localhost"/>
    </service-properties>
  </service>
</blueprint>
class MyRouteBuilder extends RouteBuilder {
	     "direct:a" --> "mock:a"
	   }
                                              public class MyRouteBuilder extends RouteBuilder {
                                              	   @Override
                                              	   public void configure() throws Exception {
                                              	   	   from("direct:a")
                                              	   	   .to("mock:a");

                                              	   }
                                              }




<camelContext xmlns="http://camel.apache.org/schema/spring">
  <route>
    <from uri="direct:a"/>
    <to uri="mock:a"/>
  </route>
</camelContext>
public class MyRouteBuilder extends RouteBuilder {

                public void configure() {
                	 Processor myProcessor = new MyProcessor();
           	   	 from("URI1")
           	   	 	 .process(myProcessor)
           	   	 	 	 ...
                             .to("URI2");
                }
           }



public class MyProcessor implements Processor{

	   public void process(Exchange exchange) throws Exception {
	   	 //Use exchange methods for processing it ...
	   }
}
log.info("Source : "+exchange.getFromEndpoint());
	   	   log.info("Pattern : "+exchange.getPattern());
	   	   log.info("Exchange ID : "+exchange.getExchangeId());

	   	   log.info("---------- Here Starts Headers ----------");
	   	   Map<String,Object> dictionnaire = exchange.getIn().getHeaders();
	   	   for (final String cle : dictionnaire.keySet()) {
	   	   	 log.info("Key : "+cle+" Value : "+dictionnaire.get(cle));
	   	   }
	   	
	   	   log.info("---------- Here Starts Properties -------");
	   	   Map<String,Object> dictionnaire2 = exchange.getProperties();
	   	   for (final String cle : dictionnaire2.keySet()) {
	   	   	 log.info("Key : "+cle+" Value : "+dictionnaire2.get(cle));
	   	   }
INFO   Source : Endpoint[file://src/data/?fileName=livraison.csv&noop=true]
INFO   Pattern : InOnly
INFO   Exchange ID : ID-saad-local-51012-1303566625671-0-2
INFO   ---------- Here Starts Headers ----------
INFO   Key : camelfilenameonly Value : livraison.csv
INFO   Key : camelfileparent Value : src/data
INFO   Key : camelfilename Value : livraison.csv
INFO   Key : camelfileabsolute Value : false
INFO   Key : camelfilelength Value : 115
INFO   Key : camelfilerelativepath Value : livraison.csv
INFO   Key : camelfilepath Value : src/data/livraison.csv
INFO   Key : camelfilelastmodified Value : Sat Apr 16 08:26:18 CEST 2011
INFO   Key : camelfileabsolutepath Value : /users/saadrguig/Desktop/CAMEL-CSV-TEST/src/data/livraison.csv
INFO   ---------- Here Starts Properties -------
INFO   Key : CamelBatchComplete Value : true
INFO   Key : CamelBatchSize Value : 1
INFO   Key : CamelCreatedTimestamp Value : Sat Apr 23 15:50:27 CEST 2011
INFO   Key : CamelFileExchangeFile Value : GenericFile[livraison.csv]
INFO   Key : Propriete 1 Value : Contenu de La propriete 1
INFO   Key : CamelBatchIndex Value : 0
<dependency>
	   	 <groupId>org.apache.camel</groupId>
	   	 <artifactId>camel-test</artifactId>
	   	 <version>${camel-version}</version>
	   </dependency>
	   <dependency>	
       <groupId>junit</groupId>
	   	 <artifactId>junit</artifactId>
	   	 <version>${junit-version}</version>
	   </dependency>
public class MyClassTest extends CamelTestSupport{
	   @Test
	   public void methodeTest() throws Exception{
	
	   	   CamelContext context = new DefaultCamelContext();
	   	   context.addRoutes(creaeRoutes());
	   	   context.start();
	   	   MockEndpoint mock = context.getEndpoint("mock:result", MockEndpoint.class);
	   	   mock.expectedBodiesReceived("What ever you expect !");

	   	     ProducerTemplate template = context.createProducerTemplate();
	   	     template.sendBody("direct:MyEndpoint1", MyMessage);
	   	     mock.assertIsSatisfied();
	   }
private    RouteBuilder creaeRoutes() {
	   	     return new RouteBuilder(){
	   	     	   @Override
	   	     	   public void configure() throws Exception {
	   	     	   	    from("direct:MyEndpoint1")
                    	 ....<routing + transformations...>
                    	 	   .to("mock:result");
	   	     	   }
	   	     };
from("file:src/data?noop=true")
    .choice()
	   	    .when(header("CamelFileName").endsWith(".xml"))
	   	    	   .to("seda:xmlLivraison")
	   	    .when(header("CamelFileName").regex("^.*(csv|csl)$"))
	   	    	   .to("seda:csvLivraison");

from("seda:csvLivraison")
	   .split(body(String.class).tokenize("n"))
    	
    	    .unmarshal(camelDataFormat)
        		   .bean(Controler.class)
        		   	    .wireTap("direct:tap")
        		   	    	   .multicast()
        		   	    	   	    .to("jms:queue:livraison?jmsMessageType=Text")
        		   	    	   	    .to("log:Mail----------------------->?level=INFO");

from("direct:tap")
	   .process(myTransformer)
	   	    .marshal(jaxb)
	   	    	   .choice()
	   	    	   	     .when(xpath("/livraison/mode = 'chronopost'"))
	   	    	   	     	 .to("direct:multicast")
	   	    	   	     .otherwise()
	   	    	   	     	 .multicast()
	   	    	   	     	 	     .to("file:target/out/colissimo")
	   	    	   	     	 	     .to("log:JAXB----------------------->?level=INFO");

from("direct:multicast")
	   .multicast()
	   	    .parallelProcessing()
	   	    	   .multicast().to("file:target/out/chronopost",
	   	    	   	    	   	   	    "smtps://smtp.gmail.com?username=srguig&password="+password+From+Subject);
[1) thread #1 - seda://csvOrder] Mail----------------------->   INFO Exchange[ExchangePattern:InOnly, BodyType:java.util.ArrayList, Body:
[{fr.aimaf.model.csv.LivraisonCSV=LivraisonCSV [ref_transaction=981928.0, nom_client=nom_client, prenom_client=prenom_client,
telephone=telephone, email=email, addresse1=addresse1, addresse2=addresse2, code_postal=code_postal, ville=Paris, nomArticle=nomArticle,
mode_livraison=chronopost, relais=relais, date_cmd=Mon Apr 25 00:00:00 CEST 2011, poids_colis=10.0, port_paye=5.0]}]]
[ (camel-1) thread #2 - WireTap] Transformer                    INFO ------------> Processor: Ville de LivraisonCSV------------> Paris
....
Aimaf
Aimaf
Aimaf
Aimaf
Aimaf
Aimaf

Aimaf

  • 3.
    Application: B BPM BAM Application: A
  • 5.
    é Apache ServiceMix : Bus d’intégration (Flux, FUSE ESB processus techniques) basé sur JBI et OSGI FUSE Message Apache ActiveMQ : Courtier de messagerie (MOM) basé Broker sur JMS FUSE Apache CXF : permet de créer ou consommer des Services Services Web Framework FUSE Mediation 
 Apache Camel : moteur de routage permettant de Router créer des patterns d'intégration avec une formation minimale grâce à un langage Java simple ou avec XML
  • 12.
    # # Framework selectionproperties # karaf.framework=equinox # # Location of the OSGi frameworks # karaf.framework.equinox=${karaf.default.repository}/org/eclipse/osgi/.... karaf.framework.felix=${karaf.default.repository}/org/apache/felix/.....
  • 14.
    <groupId>fr.aimaf</groupId> <artifactId>Example</artifactId> <packaging>bundle</packaging> <version>0.1</version> <name>Aimaf Example :: Camel OSGi Bundle</name>
  • 16.
    Expéditeur: Destinataire Application Application A B Queue Queue Queue
  • 18.
    <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0" xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0" xmlns:amq="http://activemq.apache.org/schema/core"> <!-- Allows us to use system properties as variables in this configuration file --> <ext:property-placeholder /> <broker xmlns="http://activemq.apache.org/schema/core" brokerName="default" dataDirectory="${karaf.data}/activemq/default" useShutdownHook="false"> <destinationPolicy> <policyMap> <policyEntries> <policyEntry topic=">" producerFlowControl="true" memoryLimit="1mb"> <pendingSubscriberPolicy> <vmCursor /> </pendingSubscriberPolicy> </policyEntry> <policyEntry queue=">" producerFlowControl="true" memoryLimit="1mb"> </policyEntry> </policyEntries> </policyMap> </destinationPolicy> <!-- Use the following to configure how ActiveMQ is exposed in JMX --> <managementContext> <managementContext createConnector="false"/> </managementContext> <persistenceAdapter> <kahaDB directory="${karaf.data}/activemq/default/kahadb"/> </persistenceAdapter> <!-- The transport connectors ActiveMQ will listen to --> <transportConnectors> <transportConnector name="openwire" uri="tcp://localhost:61616"/> <transportConnector name="stomp" uri="stomp://localhost:61613"/> </transportConnectors> </broker> <bean id="activemqConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory"> <property name="brokerURL" value="tcp://localhost:61616" /> </bean> <bean id="pooledConnectionFactory" class="org.apache.activemq.pool.PooledConnectionFactory"> <property name="maxConnections" value="8" /> <property name="connectionFactory" ref="activemqConnectionFactory" /> </bean> <bean id="resourceManager" class="org.apache.activemq.pool.ActiveMQResourceManager" init-method="recoverResource"> <property name="transactionManager" ref="transactionManager" /> <property name="connectionFactory" ref="activemqConnectionFactory" /> <property name="resourceName" value="activemq.default" /> </bean> <reference id="transactionManager" interface="javax.transaction.TransactionManager" /> <service ref="pooledConnectionFactory" interface="javax.jms.ConnectionFactory"> <service-properties> <entry key="name" value="localhost"/> </service-properties> </service> </blueprint>
  • 23.
    class MyRouteBuilder extendsRouteBuilder { "direct:a" --> "mock:a" } public class MyRouteBuilder extends RouteBuilder { @Override public void configure() throws Exception { from("direct:a") .to("mock:a"); } } <camelContext xmlns="http://camel.apache.org/schema/spring"> <route> <from uri="direct:a"/> <to uri="mock:a"/> </route> </camelContext>
  • 24.
    public class MyRouteBuilderextends RouteBuilder { public void configure() { Processor myProcessor = new MyProcessor(); from("URI1") .process(myProcessor) ... .to("URI2"); } } public class MyProcessor implements Processor{ public void process(Exchange exchange) throws Exception { //Use exchange methods for processing it ... } }
  • 26.
    log.info("Source : "+exchange.getFromEndpoint()); log.info("Pattern : "+exchange.getPattern()); log.info("Exchange ID : "+exchange.getExchangeId()); log.info("---------- Here Starts Headers ----------"); Map<String,Object> dictionnaire = exchange.getIn().getHeaders(); for (final String cle : dictionnaire.keySet()) { log.info("Key : "+cle+" Value : "+dictionnaire.get(cle)); } log.info("---------- Here Starts Properties -------"); Map<String,Object> dictionnaire2 = exchange.getProperties(); for (final String cle : dictionnaire2.keySet()) { log.info("Key : "+cle+" Value : "+dictionnaire2.get(cle)); }
  • 27.
    INFO Source : Endpoint[file://src/data/?fileName=livraison.csv&noop=true] INFO Pattern : InOnly INFO Exchange ID : ID-saad-local-51012-1303566625671-0-2 INFO ---------- Here Starts Headers ---------- INFO Key : camelfilenameonly Value : livraison.csv INFO Key : camelfileparent Value : src/data INFO Key : camelfilename Value : livraison.csv INFO Key : camelfileabsolute Value : false INFO Key : camelfilelength Value : 115 INFO Key : camelfilerelativepath Value : livraison.csv INFO Key : camelfilepath Value : src/data/livraison.csv INFO Key : camelfilelastmodified Value : Sat Apr 16 08:26:18 CEST 2011 INFO Key : camelfileabsolutepath Value : /users/saadrguig/Desktop/CAMEL-CSV-TEST/src/data/livraison.csv INFO ---------- Here Starts Properties ------- INFO Key : CamelBatchComplete Value : true INFO Key : CamelBatchSize Value : 1 INFO Key : CamelCreatedTimestamp Value : Sat Apr 23 15:50:27 CEST 2011 INFO Key : CamelFileExchangeFile Value : GenericFile[livraison.csv] INFO Key : Propriete 1 Value : Contenu de La propriete 1 INFO Key : CamelBatchIndex Value : 0
  • 28.
    <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-test</artifactId> <version>${camel-version}</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>${junit-version}</version> </dependency>
  • 30.
    public class MyClassTestextends CamelTestSupport{ @Test public void methodeTest() throws Exception{ CamelContext context = new DefaultCamelContext(); context.addRoutes(creaeRoutes()); context.start(); MockEndpoint mock = context.getEndpoint("mock:result", MockEndpoint.class); mock.expectedBodiesReceived("What ever you expect !"); ProducerTemplate template = context.createProducerTemplate(); template.sendBody("direct:MyEndpoint1", MyMessage); mock.assertIsSatisfied(); } private RouteBuilder creaeRoutes() { return new RouteBuilder(){ @Override public void configure() throws Exception { from("direct:MyEndpoint1") ....<routing + transformations...> .to("mock:result"); } };
  • 31.
    from("file:src/data?noop=true") .choice() .when(header("CamelFileName").endsWith(".xml")) .to("seda:xmlLivraison") .when(header("CamelFileName").regex("^.*(csv|csl)$")) .to("seda:csvLivraison"); from("seda:csvLivraison") .split(body(String.class).tokenize("n")) .unmarshal(camelDataFormat) .bean(Controler.class) .wireTap("direct:tap") .multicast() .to("jms:queue:livraison?jmsMessageType=Text") .to("log:Mail----------------------->?level=INFO"); from("direct:tap") .process(myTransformer) .marshal(jaxb) .choice() .when(xpath("/livraison/mode = 'chronopost'")) .to("direct:multicast") .otherwise() .multicast() .to("file:target/out/colissimo") .to("log:JAXB----------------------->?level=INFO"); from("direct:multicast") .multicast() .parallelProcessing() .multicast().to("file:target/out/chronopost", "smtps://smtp.gmail.com?username=srguig&password="+password+From+Subject);
  • 32.
    [1) thread #1- seda://csvOrder] Mail-----------------------> INFO Exchange[ExchangePattern:InOnly, BodyType:java.util.ArrayList, Body: [{fr.aimaf.model.csv.LivraisonCSV=LivraisonCSV [ref_transaction=981928.0, nom_client=nom_client, prenom_client=prenom_client, telephone=telephone, email=email, addresse1=addresse1, addresse2=addresse2, code_postal=code_postal, ville=Paris, nomArticle=nomArticle, mode_livraison=chronopost, relais=relais, date_cmd=Mon Apr 25 00:00:00 CEST 2011, poids_colis=10.0, port_paye=5.0]}]] [ (camel-1) thread #2 - WireTap] Transformer INFO ------------> Processor: Ville de LivraisonCSV------------> Paris ....