Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

apache camel filter in xml. Passing parameters to Bean in xml

I am new at working with activemq and Camel.

I have these questions:

  1. I have a bean and bean method, which are invoked by filter.

    <filter>
       <method ref="MyBean" method="CheckReceivedFilesByParameters"/>
       <to uri="direct:b"/>
    </filter>
    

    Method CheckReceivedFilesByParameters returns boolean value. The next route starts succesfully if true. How can I invoke route (direct:b) when false. And I want to do this with xml. I tried to invoke method outside tag but with no luck.

    <to uri="bean:MyBean?method=CheckReceivedFilesByParameters"/>
    <filter>
       <simple>false</simple>
       <to uri="direct:b"/>
    </filter>
    
  2. How can I correctly pass parameters to MyBean method via Exchange message. What is best practice? Right now I'm doing by creating headers and later in my method I get headerValues. Example in my xml.

    <setHeader headerName="RouteId">
        <constant>Test1</constant>
    </setHeader>
    

    And then getting header in MyBean method value. String routeId = exchange.getIn().getHeader("RouteId", String.class);

    Should there'is some more "elegant" way. Like passing parameters. Like in servlets?

    request.getParameter("par1")

Thanks in advance.

like image 378
K.I. Avatar asked Oct 20 '22 05:10

K.I.


1 Answers

Ad 1)

The filter eip only routes if the expression is true, eg the method call returns true. So if the method call returns false, then the filter does not route to "direct:b".

Ad 2)

Read about parameter bindings

  • http://camel.apache.org/bean-binding.html
  • http://camel.apache.org/parameter-binding-annotations.html
like image 60
Claus Ibsen Avatar answered Oct 22 '22 19:10

Claus Ibsen