camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alexey-s <alex...@mail.ru>
Subject Camel OSGI and dynamicRoute
Date Tue, 09 Oct 2012 12:46:50 GMT
Hi

I decided to try to call external camel process from another process.
If in the first, specify the name of an external process, the process will
be run once.
If during the specified dynamic route, bean components are run many times.

Use Apache Camel 2.10.1 and Apacke Karaf.
Example route system and log files.

First OSGI Bundle have route process

  <bean id="readDocumentProcess" class="com.myproject.ReadDocument"/>
  <bean id="osgiDynamicRouter" class="com.myproject.DynamicRouterBean"
init-method="initServices"/>

  <camelContext id="camel-exchange-oos-doc-read"
xmlns="http://camel.apache.org/schema/blueprint">
    
    <route id="exchangeDocStoreRoute">
      <from
uri="file:{{exchange.oos.doc.store}}?sorter=#docFileSorter&amp;filter=#docFileFilter&amp;delay=1200000&amp;recursive=true"/>
      <log message="Read
[${header.CamelBatchSize}:${header.CamelBatchIndex}]
${header.CamelFileNameOnly}"/>
      <filter>
        <method bean="docFileFilter" method="acceptByExecute"/>
        <log message="Processing
[${header.CamelBatchSize}:${header.CamelBatchIndex}]
${header.CamelFileNameOnly}"/>
        <setHeader headerName="startProcess"><simple>${date:now:yyyy-MM-dd
HH:mm:ss.SSSS}</simple></setHeader>
        <split streaming="true" stopOnException="true">
          <method bean="zipStaxSplitter" method="splitBody"/>
          <to uri="bean:readDocumentProcess"/>
          <filter>
            <method bean="receiptDocFilter" method="acceptByCustomer"/>
            <log message="Store
[${header.CamelBatchSize}:${header.CamelBatchIndex}:${property.CamelSplitIndex}]
${header.CamelFileName}"/>
            <to uri="bean:storeDocumentProcess?method=storeReceiptDoc"/>
            
            
            <log message="Send data to external systems
[${header.CamelBatchSize}:${header.CamelBatchIndex}:${property.CamelSplitIndex}]
${header.CamelFileName}"/>
            
            <dynamicRouter>
              <method ref="osgiDynamicRouter" method="sendRouteDoc"/>
            </dynamicRouter>
          </filter>
        </split>
        <log message="Save file information
[${header.CamelBatchSize}:${header.CamelBatchIndex}:${property.CamelSplitIndex}]
${header.CamelFileName}"/>
        <to uri="bean:storeFileProcess"/>
      </filter>
    </route>
    ...
  </camelContext>

Next OSGI Bundle have route process

<camelContext id="camel-ccje-exchange-oos-doc-read"
xmlns="http://camel.apache.org/schema/blueprint">

    <route id="ccjeReceiptDoc">
      <from uri="vm:ccjeReceiptDoc"/>
      <transacted ref="required"/>
      ...
    </route>
    ...
</camelContext>


class DynamicRouterBean {
    ...
    public String sendRouteDoc() {
        if(routeDoc == null) {
             routeDoc = readRoutes(references, false);
        }
        LOGGER.info("routeDoc: {}", routeDoc);
        return routeDoc;
    }
}

First log file: karaf.log.16 size 100K

2012-10-09 15:39:11,334 | INFO  | s/doc-read-store | exchangeDocStoreRoute           
| 103 - org.apache.camel.camel-core - 2.10.1 | Read [337:0]
notification__Vologodskaja_obl_inc_20121003_000000_20121004_000000_493.xml.zip
2012-10-09 15:39:11,338 | INFO  | s/doc-read-store | exchangeDocStoreRoute           
| 103 - org.apache.camel.camel-core - 2.10.1 | Processing [337:0]
notification__Vologodskaja_obl_inc_20121003_000000_20121004_000000_493.xml.zip
2012-10-09 15:39:11,425 | INFO  | s/doc-read-store | ReadDocument                    
| 144 - exchange-oos-core - 1.3.0.SNAPSHOT | Processing XML document. Size
24045 bytes
2012-10-09 15:39:12,250 | INFO  | s/doc-read-store | ReceiptDocFilterBean            
| 144 - exchange-oos-core - 1.3.0.SNAPSHOT | Processing document
notificationOK regNum:0530300001012000001
2012-10-09 15:39:12,251 | INFO  | s/doc-read-store | exchangeDocStoreRoute           
| 103 - org.apache.camel.camel-core - 2.10.1 | Store [337:0:0]
Vologodskaja_obl/notifications/daily/notification__Vologodskaja_obl_inc_20121003_000000_20121004_000000_493.xml.zip
2012-10-09 15:39:12,328 | INFO  | s/doc-read-store | exchangeDocStoreRoute           
| 103 - org.apache.camel.camel-core - 2.10.1 | Send data to external systems
[337:0:0]
Vologodskaja_obl/notifications/daily/notification__Vologodskaja_obl_inc_20121003_000000_20121004_000000_493.xml.zip
2012-10-09 15:39:12,330 | INFO  | s/doc-read-store | DynamicRouterBean               
| 144 - exchange-oos-core - 1.3.0.SNAPSHOT | routeDoc: vm:ccjeReceiptDoc

The last message is repeated many times.

Next log file: karaf.log.15  size 100K
Next log file: karaf.log.14  size 100K
...
Next log file: karaf.log.3  size 100K
Next log file: karaf.log.2

2012-10-09 15:39:36,409 | INFO  | s/doc-read-store | exchangeDocStoreRoute           
| 103 - org.apache.camel.camel-core - 2.10.1 | Save file information
[337:0:]
Vologodskaja_obl/notifications/daily/notification__Vologodskaja_obl_inc_20121003_000000_20121004_000000_493.xml.zip




--
View this message in context: http://camel.465427.n5.nabble.com/Camel-OSGI-and-dynamicRoute-tp5720793.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Mime
View raw message