3 Replies Latest reply on May 6, 2014 4:51 AM by Bhaskar SK

    switchyard monitor directory and filename to jms queue

    Kevin Stone Novice

      In apache camel you can route a file to a jms queue like:


           <from uri="file://inputdir/"/>

           <to uri="jms.my.queue"/>



      I need to do something similar in switchyard.


      I have a switchyard.xml file that monitors a directory.  For each file it waits for a .DONE file and then will consume the file.

      <?xml version="1.0" encoding="UTF=8"?>

      <switchyard xmlns="urn:switchyard-config:switchyard:1.0>

           <composite xmlns="http://docs.oasis-open.org/ns/opensca/sca/200912" name="S1ESB">

                <service name="FileConsumer" promote="FileConsumer">

                     <file:binding.file xmlns:file="urn:switchyard-component-camel-file:config:1.0">

                          <file:directory>/opt/INCOMING</file:directory>  <!-- Name of the directory to monitor -->


                               <file:doneFileName>$${file:name}.DONE</file:doneFileName>     <!-- Wait for a done file before consuming -->





                <! -- I have been successful sending the file name to a java bean but I would like to send it directly to a jms queue if possible -->

                <!--- from here on I am guessing at how to send the file to jms -->


                <component name="FileConsumer">

                     <camel:implementation.camel xmlns:camel="urn:switchyard-component-camel:config:1.0">

                          <camel:xml path="META-INF/route.xml">






      Now a route.xml file:


      <?xml version="1.0" encoding="UTF-8"?>

      <routes xmlns="http://camel.apache.org/schema/spring">


                <from uri="TBD"/>     <!-- Dont know what to put here since I would expect the file name to be passed to the route from switchyard.xml or something like that -->

                <to uri="jms:xxx.queue"/>




      Am I even close?  I have googled and googled but I cant find anything that does this.  Please don't ding me on spelling since I had to type this all in.

        • 1. Re: switchyard monitor directory and filename to jms queue
          Keith Babo Master

          You are close.  Are you using the tooling?  If so, it will create the Camel route with correct endpoints and wiring to the composite service and reference where you are using Camel bindings.  Here's an example of what the switchyard.xml would look like followed by the Camel route:


          <?xml version="1.0" encoding="UTF-8"?>
          <sy:switchyard xmlns:camel="urn:switchyard-component-camel:config:1.1" xmlns:file="urn:switchyard-component-camel-file:config:1.1" xmlns:jms="urn:switchyard-component-camel-jms:config:1.1" xmlns:sca="http://docs.oasis-open.org/ns/opencsa/sca/200912" xmlns:sy="urn:switchyard-config:switchyard:1.1" name="filejms" targetNamespace="urn:com.example.switchyard:filejms:1.0">
            <sca:composite name="filejms" targetNamespace="urn:com.example.switchyard:filejms:1.0">
              <sca:component name="Route">
                  <camel:xml path="route.xml"/>
                <sca:service name="MyService">
                  <sca:interface.java interface="com.example.switchyard.filejms.MyService"/>
                <sca:reference name="AnotherService">
                  <sca:interface.java interface="com.example.switchyard.filejms.AnotherService"/>
              <sca:service name="MyService" promote="Route/MyService">
                <sca:interface.java interface="com.example.switchyard.filejms.MyService"/>
                <file:binding.file name="file1">
              <sca:reference name="AnotherService" multiplicity="0..1" promote="Route/AnotherService">
                <sca:interface.java interface="com.example.switchyard.filejms.AnotherService"/>
                <jms:binding.jms name="jms1">


          Camel route:

          <?xml version="1.0" encoding="ASCII"?>
          <routes xmlns="http://camel.apache.org/schema/spring">
              <from uri="switchyard://MyService"/>
              <log message="MyService - message received: ${body}"/>
              <to uri="switchyard://AnotherService"/>


          I have attached a copy of the project I created to generate this config in case you want to work from it as a template.  FWIW, it took me < 60 secs to create this in the editor.  I point this out merely to highlight how the editor can be a bit productivity booster.

          • 2. Re: switchyard monitor directory and filename to jms queue
            Kevin Stone Novice

            Thanks Keith.  Although I can't get your example to work, I'm sure it is the right way to go.  Perhaps my problem is that I am on switchyard 0.8 or that we still use ant and not maven.  Not sure.  And yes, I did download the tooling zip and installed it into Eclipse but I really didn't have time to learn how to use the tool (at the time I thought I could just create it by hand - my bad), 

            • 3. Re: Re: switchyard monitor directory and filename to jms queue
              Bhaskar SK Newbie

              Hi Keith,


              I had a similar scenario, and i had followed the same approach as you have mentioned. But iam wondering( checking with log messages), will that be a async call to a JMS switchyard service or it invokes directly the Java interface. ( If this is the case then there is no queuing mechanism?).

              Logs are printed in the sequence

              message sending

              // the request to Mapperservice completes ( all logs )

              message sent ( printed after the entire service is done)




                              <simple>${body.destination} == 'NSN_2G_Mapper'</simple>

                              <log message="MyService - message sending ${body}"/>

                              <to uri="switchyard://MapperService" />

                              <log message="MyService - message sent"/>




              MapperService being a JMS service as below

              <sca:service name="MapperService" promote="NSN_2G_Mapper/MapperService">

                    <sca:interface.java interface="com.alu.ipprd.aor.socket.client.MapperService"/>@

                    <jms:binding.jms name="MapperServiceQueue">