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

    switchyard monitor directory and filename to jms queue

    stonesoft

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

      <route>

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

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

      </route>

       

      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:consume>

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

                          </file:consume>

                     </file:binding.file>

                </service>

       

                <! -- 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">

                     </camel:implementation.camel>

                </component>

           </composite>

      </switchyard>

       

      Now a route.xml file:

       

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

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

           <route>

                <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"/>

           </route>

      </routes>

       

      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
          kcbabo

          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:implementation.camel>
                  <camel:xml path="route.xml"/>
                </camel:implementation.camel>
                <sca:service name="MyService">
                  <sca:interface.java interface="com.example.switchyard.filejms.MyService"/>
                </sca:service>
                <sca:reference name="AnotherService">
                  <sca:interface.java interface="com.example.switchyard.filejms.AnotherService"/>
                </sca:reference>
              </sca:component>
              <sca:service name="MyService" promote="Route/MyService">
                <sca:interface.java interface="com.example.switchyard.filejms.MyService"/>
                <file:binding.file name="file1">
                  <file:directory>/opt/INCOMING</file:directory>
                  <file:consume/>
                </file:binding.file>
              </sca:service>
              <sca:reference name="AnotherService" multiplicity="0..1" promote="Route/AnotherService">
                <sca:interface.java interface="com.example.switchyard.filejms.AnotherService"/>
                <jms:binding.jms name="jms1">
                  <jms:queue>SomeQueue</jms:queue>
                  <jms:connectionFactory>#ConnectionFactory</jms:connectionFactory>
                </jms:binding.jms>
              </sca:reference>
            </sca:composite>
          </sy:switchyard>
          

           

          Camel route:

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

           

          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
            stonesoft

            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
              bhaskarsk

              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)

               

              ==========================================================

                   <when>

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

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

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

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

                          </when>

              =======================================

               

              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">

                      <jms:queue>MapperServiceQueue</jms:queue>

                      <jms:connectionFactory>#ConnectionFactory</jms:connectionFactory>

                    </jms:binding.jms>

                  </sca:service>