You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by jpalmer1026 <pa...@gmail.com> on 2011/04/04 16:36:29 UTC

Route Question

Hi,

I'm working on an app where I need to conditionally route files based on
filename. Ideally I'd like the list of filenames that need to be matched to
be read in from an external file. Is there a simple way to do this using
Camel? Something like the following?


   
      
      
         
            ${header.CamelFileName} regex 'fileNameFromExternalFile'
            
          
      
   


--
View this message in context: http://camel.465427.n5.nabble.com/Route-Question-tp4281861p4281861.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Route Question

Posted by Claus Straube <cl...@catify.com>.
I can't see the code. Perhaps this is the mailinglist issue Claus posted 
some days ago. But anyway - on one side it is a discussion about coding 
style. I think it's cleaner / easier to read to have two three line 
routes where each of the route has its own and clear task to do, than a 
all in one solution with a if clause in the end. But as I said this is a 
question of taste. On the other side I don't have a quick tip for a all 
in one solution...

On 06.04.2011 19:29, jpalmer1026 wrote:
> Nothing is wrong with the proposed solution per se. It would just be cleaner
> if at the end of the route I could just put some sort of otherwise clause
> since I know at this point that the file isn't one contained in the list
> that is getting passed in. Note sure why you couldn't read my snippet (I
> didn't see any  tags to surround it with) but here it is again:
>
>
>
>
>
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Route-Question-tp4281861p4286838.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>


Re: Route Question

Posted by jpalmer1026 <pa...@gmail.com>.
Nothing is wrong with the proposed solution per se. It would just be cleaner
if at the end of the route I could just put some sort of otherwise clause
since I know at this point that the file isn't one contained in the list
that is getting passed in. Note sure why you couldn't read my snippet (I
didn't see any  tags to surround it with) but here it is again:


   
      
      
   



--
View this message in context: http://camel.465427.n5.nabble.com/Route-Question-tp4281861p4286838.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Route Question

Posted by Claus Straube <cl...@catify.com>.
I can't read your sample.

What's the problem with two filters and two routes? You create a base 
class which reads the file into a list of file names and both filters 
extend these class. The one filter returns true if the file name is 
inside the list, the other returns true if it is not.

On 06.04.2011 17:58, jpalmer1026 wrote:
> I ended up creating a file filter to route files that match one of the
> filenames from the list I'm passing in. Is there a way to route non-matching
> filenames to a different uri without creating a new file filter and a new
> route? My current route is as follows:
>
>
>
>
>
>
>
>
> Thanks.
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Route-Question-tp4281861p4286606.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



Re: Route Question

Posted by jpalmer1026 <pa...@gmail.com>.
I ended up creating a file filter to route files that match one of the
filenames from the list I'm passing in. Is there a way to route non-matching
filenames to a different uri without creating a new file filter and a new
route? My current route is as follows:


   
      
      
   


Thanks.

--
View this message in context: http://camel.465427.n5.nabble.com/Route-Question-tp4281861p4286606.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Route Question

Posted by Claus Straube <cl...@catify.com>.
Hi.

If I understand it correct this is your case:

1. load master file with file names
2. load files from an other directory
3. decide where to save them

As Claus wrote - you should use here a file filter which reads in your 
master file. But you have left all the files that are not on the list. 
So a solution could be two file filters - one for the files on the list, 
the other one for the rest. Create two routes with those both filters 
and route them to the both directories you want.

Hope that helps.

Best regards - Claus

On 06.04.2011 16:24, jpalmer1026 wrote:
> Hi Claus,
>
> Thanks for the information. This is getting me a little closer but it still
> doesn't solve my particular use case. What I'm actually trying to do is
> route files based on filename. The filenames will be read in from an
> external file upon the launch of the app and this filename list will then be
> used to conditionally route the files. For example, if the initial list of
> filenames that was read in is test10.txt, test20.txt and test30.txt, then
> the filter would need to route any files with any of those filenames to one
> directory and all other files to a different directory.
>
> Does that make sense? Is there a way to do this with Camel?
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Route-Question-tp4281861p4286385.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>


-- 
claus straube
__________________________________________

phone    +49-89-38157419
mobile   +49-176-49673717
web      http://www.catify.com
office   5. floor, heßstr. 56, 80798 munich
__________________________________________


Re: Route Question

Posted by Claus Ibsen <cl...@gmail.com>.
On Wed, Apr 6, 2011 at 4:24 PM, jpalmer1026 <pa...@gmail.com> wrote:
> Hi Claus,
>
> Thanks for the information. This is getting me a little closer but it still
> doesn't solve my particular use case. What I'm actually trying to do is
> route files based on filename. The filenames will be read in from an
> external file upon the launch of the app and this filename list will then be
> used to conditionally route the files. For example, if the initial list of
> filenames that was read in is test10.txt, test20.txt and test30.txt, then
> the filter would need to route any files with any of those filenames to one
> directory and all other files to a different directory.
>
> Does that make sense? Is there a way to do this with Camel?
>

Just implement a custom filter class and configure it on the endpoint

file:xxx?filter=#myFilter

<bean id="myFilter" class="...MyFilterBean">

And then implement the interface
org.apache.camel.component.file.GenericFileFilter in MyFilterBean.
And return true|false to accept the file or not.



> --
> View this message in context: http://camel.465427.n5.nabble.com/Route-Question-tp4281861p4286385.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
CamelOne 2011: http://fusesource.com/camelone2011/
Twitter: davsclaus
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Re: Route Question

Posted by jpalmer1026 <pa...@gmail.com>.
Hi Claus,

Thanks for the information. This is getting me a little closer but it still
doesn't solve my particular use case. What I'm actually trying to do is
route files based on filename. The filenames will be read in from an
external file upon the launch of the app and this filename list will then be
used to conditionally route the files. For example, if the initial list of
filenames that was read in is test10.txt, test20.txt and test30.txt, then
the filter would need to route any files with any of those filenames to one
directory and all other files to a different directory.

Does that make sense? Is there a way to do this with Camel?

--
View this message in context: http://camel.465427.n5.nabble.com/Route-Question-tp4281861p4286385.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Route Question

Posted by Claus Straube <cl...@catify.com>.
Hi.

yes:

<camelContext xmlns="http://camel.apache.org/schema/spring">
     <template id="camelTemplate"/>

     <!-- use myFilter as filter to allow setting ANT paths for which files to scan for -->
     <endpoint id="myFileEndpoint"  uri="file://target/antpathmatcher?recursive=true&amp;filter=#myAntFilter"/>

     <route>
         <from ref="myFileEndpoint"/>
         <to uri="mock:result"/>
     </route>
</camelContext>

<!-- we use the antpath file filter to use ant paths for includes and exlucde -->
<bean id="myAntFilter"  class="org.apache.camel.component.file.AntPathMatcherGenericFileFilter">
     <!-- include and file in the subfolder that has day in the name -->
     <property name="includes"  value="**/subfolder/**/*day*"/>
     <!-- exclude all files with bad in name or .xml files. Use comma to seperate multiple excludes -->
     <property name="excludes"  value="**/*bad*,**/*.xml"/>
</bean>

You can find this in the documentation:http://camel.apache.org/file2.html

Claus



On 04.04.2011 16:36, jpalmer1026 wrote:
> Hi,
>
> I'm working on an app where I need to conditionally route files based on
> filename. Ideally I'd like the list of filenames that need to be matched to
> be read in from an external file. Is there a simple way to do this using
> Camel? Something like the following?
>
>
>
>
>
>
>              ${header.CamelFileName} regex 'fileNameFromExternalFile'
>
>
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Route-Question-tp4281861p4281861.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Design Review

Posted by Paul Lowry <pl...@newbay.com>.
Hi all,

I have written a route to do the following:
- expose a restful service
- invoke a http server
- catch errors;
  put the associated messages on an error queue
- catch connection exceptions and unknown business errors;
  put the associated request messages on a retry queue
- every 24 hours, poll the retry queue;
  invoke the http server again
  increment a retry counter
  and when a retry limit is reached...
  move the associated messages on the error queue

Can someone please review my route (below), and tell me if I have missed
any useful solutions, or if this is the optimal approach?

Also, is there any handy way to implement an exponential backoff in my
http client?

Thanks,
Paul


<camelContext xmlns="http://camel.apache.org/schema/spring"
id="SPGClient">

  <endpoint id="frontend"
uri="restlet:http://localhost:8080/myclient/{param}"/>
  <endpoint id="httpServer" uri="http://localhost:8080/myserver"/>
  <endpoint id="workQueue" uri="direct:INTERNAL_QUEUE"/>
  <endpoint id="errorQueue"
uri="activemq:ERROR_QUEUE?exchangePattern=InOnly"/>
  <endpoint id="retryQueue"
uri="activemq:RETRY_QUEUE?exchangePattern=InOnly"/>
  <endpoint id="retryTimer" uri="quartz://myTimer/0/0/12/*/*/$"/>

  <route id="frontendRoute">
    <from ref="frontend"/>
    <!-- inject param into message body -->
    <process ref="paramProcessor"/>
    <!-- prepare to invoke http server -->
    <setHeader headerName="CamelHttpMethod">
      <constant>POST</constant>
    </setHeader>
    <setHeader headerName="Content-Type">
      <constant>text/xml</constant>
    </setHeader>
    <removeHeader headerName="CamelHttpUri"/>
    <to ref="workQueue"/>
  </route>

  <route id="backendRoute">
    <from ref="workQueue"/>
    <doTry>
      <!-- invoke the http server -->
      <to ref="httpServer"/>
      <doCatch>
        <!-- if the server is not running -->
        <exception>java.net.ConnectException</exception>
        <!-- put the message on the retry queue -->
        <to ref="retryQueue"/>
      </doCatch>
    </doTry>
    <!-- process the http server's response -->
    <choice>
      <when>
        <xpath>in:header('result') = 'SUCCESS'</xpath>
        <setHeader headerName="Exchange.HTTP_RESPONSE_CODE">
          <constant>200</constant>
        </setHeader>
      </when>
      <when>
        <xpath>in:header('result') = 'ERROR'</xpath>
        <to ref="errorQueue"/>
      </when>
      <otherwise>
        <to ref="retryQueue"/>
      </otherwise>
    </choice>
  </route>

  <route id="retryRoute">
    <!-- every day at noon -->
    <from ref="retryTimer"/>
    <!-- read from the retry queue -->
    <pollEnrich ref="retryQueue"/>
    <!-- check a retry counter -->
    <choice>
      <when>
        <xpath>in:header('retries') > 3</xpath>
        <to ref="errorQueue"/>
      <stop/>
      </when>
      <otherwise>
        <!-- invoke "backendRoute" again -->
        <setExchangePattern pattern="InOnly"/>
        <to ref="workQueue"/>
      </otherwise>
    </choice>
    <!-- increment the retry counter -->
    <process ref="incrementRetryCounterProcessor"/>
  </route>

</camelContext>

STRICTLY PRIVATE, CONFIDENTIAL AND PRIVILEGED COMMUNICATION.

This message (including attachments) may contain information that is
privileged, confidential or protected from disclosure. They are intended
solely for the use of the intended recipient. If you are not the
intended recipient, you are hereby notified that dissemination,
disclosure, copying, distribution, printing, transmission or use of this
message or any information contained in it is strictly prohibited. If
you have received this message from NewBay Software in error, please
immediately notify the sender by reply email and delete this message
from your computer. The content of this e-mail, and any files
transmitted with it, may have been changed or altered without the
consent of the author. Although we have taken steps to ensure that this
email and attachments are free from any virus, we advise that in keeping
with good computing practice the recipient should ensure they are
actually virus free.

Re: Route Question

Posted by Christian Müller <ch...@gmail.com>.
You can combine the content based router [1] and the simple language [2] to
something like:

        from("seda:a")
            .choice()
                .when(simple("${header.CamelFileName} regex 'foo.*'"))
                    .to("seda:b")
                .when(simple("${header.CamelFileName} regex 'bar.*'"))
                    .to("seda:c")
                .otherwise()
                    .to("seda:d");



[1] http://camel.apache.org/content-based-router.html
[2] http://camel.apache.org/simple.html

Christian