You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by zuff <bh...@live.com> on 2012/09/21 11:50:34 UTC

Correct use of camelproxy?

Hi all, 

   I need some advise on how to get my camel route working.

   <bean id="converter" class="my.Convertoer"/>

   <bean id="resultProcessor" class="my.ResultProcessor"/>

   <bean id="controller"  class="my.Controller" factory-method="getInstance"
>
                <property name="resultProcessor" ref="resultProcessor"/>
    </bean>

   <camel>
                  <proxy id="resultProxy"
serviceInterface="my.IResultProcessor" serviceUrl="direct:resultProcessor"/>


                <route id="handleRequest"> 
                             <from uri="activemq:topic:myTopic"/>
                             <bean ref="eventProcessor"
method="processEvent"/>
                </route>


                <route id="processXMLResult">  
                           <from uri="direct:resultProcessor"/>
                           <bean ref="resultManager"
method="isRequestCompleted"/>
                </route>
   </camel>



Some background info:
Request will be coming in as a JMS topic from activemq:topic:myTopic.
The object payload will then be send for processing in an external system. 
When the external system had processed the request, the result will be saved
as a file in one of the various folders, which will be picked up by a helper
util (not shown here but also injected by spring)  and update the
controller, will then make a method call to the resultProcessor object.


My problem start here:
When this resultProcessor object is triggered, I was hoping that the route
"handleRequest" will start, however,after much trying, i couldnt get the
second route to start once controller trigger the resultProcessor object.
even though I'm quite sure that the resultProcessor is being called.


public class ResultProcessor implements IResultProcessor
{
    public Result processResult(File file)
    {
                  ResultProcessor  result;
                  System.out.println("Processing Started.");
                   ......
                  return result;
    }
}


Any advice? 
Thanks
Zuff



--
View this message in context: http://camel.465427.n5.nabble.com/Correct-use-of-camelproxy-tp5719716.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Correct use of camelproxy + (Updating Exchange in Spring DSL)?

Posted by zuff <bh...@live.com>.
Hi Claus,

  Thanks, I finally managed to get it working after some trying. Right now,
I have to try store the JMSReplyTo in the first route, and "recall" it for
use in the second route. I forsee that I will face quite a number of
challenges and have to seek advise from this forum and you soon.

   To be honest, I have no idea on how to start this portion. thinking..

Best Regards,
Zuff



--
View this message in context: http://camel.465427.n5.nabble.com/Correct-use-of-camelproxy-tp5719716p5720010.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Correct use of camelproxy + (Updating Exchange in Spring DSL)?

Posted by Claus Ibsen <cl...@gmail.com>.
On Tue, Sep 25, 2012 at 5:36 AM, zuff <bh...@live.com> wrote:
> Hi,
>
>    Sorry for slow and poor understanding.
>    Is it possible to provide a more direct example. ;)
>
>    I read some post from
> http://camel.465427.n5.nabble.com/Set-exchange-property-to-a-Map-td3349171.html
>
>    <route>
>           <from uri="direct:processResult"/>
>           <bean ref="convertor"/>     [This bean take in a File object and
> return a Result object that I would like to store into the Exchange
> Properties]

Use this to set a property on the exchange, with a method call (eg
like calling a bean)
 <setProperty propertyName="foo"><method ref="convertor"/></setProperty>


>           <setProperty propertyName="foo>
>               <simple>ref:convertor</simple>   [Is this the correct way to
> do? If i had done this part correctly, can I assume Camel is able to guess
> that it need to pass this into the messageSender? ]
>           </setProperty >
>           <bean ref="strategyManager"  method="isStrategyCompleted"/>
>           <when>
>                   <simple>${body}</simple>
>                   [Need to retrieve the Result object from the Exchange
> Properties and pass it into the messageSender]
>                   <bean ref="messageSender" /> [Currently Camel is trying to
> pass the [True] into the messageSender which is excepting a Result object.
>           </when>
>

When invoking a bean using <bean> it may be a good idea to configure
the method name to call.

<bean ref="messageSender" method="myMethod"/>

And you can bind the parameters also, so if there is a single
parameter and you want the property on the exchange

<bean ref="messageSender" method="myMethod($property.foo})"/>

See details on the links I have previously posted.

>
> Current, as much as possible, I want to keep my beans as "standalone" as
> possible. Hopefully, I dun need to annotate it with the camel library as I'm
> still trying to learn more about camel and worry about timeline should I
> need to put camel aside if schedule do not permit.
>
> Best Regards,
> Zuff
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Correct-use-of-camelproxy-tp5719716p5719900.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: Correct use of camelproxy + (Updating Exchange in Spring DSL)?

Posted by zuff <bh...@live.com>.
Hi, 

   Sorry for slow and poor understanding.
   Is it possible to provide a more direct example. ;)

   I read some post from
http://camel.465427.n5.nabble.com/Set-exchange-property-to-a-Map-td3349171.html

   <route> 
          <from uri="direct:processResult"/> 
          <bean ref="convertor"/>     [This bean take in a File object and
return a Result object that I would like to store into the Exchange
Properties] 
          <setProperty propertyName="foo> 
              <simple>ref:convertor</simple>   [Is this the correct way to
do? If i had done this part correctly, can I assume Camel is able to guess
that it need to pass this into the messageSender? ]
          </setProperty > 
          <bean ref="strategyManager"  method="isStrategyCompleted"/> 
          <when> 
                  <simple>${body}</simple> 
                  [Need to retrieve the Result object from the Exchange
Properties and pass it into the messageSender] 
                  <bean ref="messageSender" /> [Currently Camel is trying to
pass the [True] into the messageSender which is excepting a Result object.
          </when> 


Current, as much as possible, I want to keep my beans as "standalone" as
possible. Hopefully, I dun need to annotate it with the camel library as I'm
still trying to learn more about camel and worry about timeline should I
need to put camel aside if schedule do not permit.

Best Regards,
Zuff



--
View this message in context: http://camel.465427.n5.nabble.com/Correct-use-of-camelproxy-tp5719716p5719900.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Correct use of camelproxy + (Updating Exchange in Spring DSL)?

Posted by Claus Ibsen <cl...@gmail.com>.
On Mon, Sep 24, 2012 at 10:57 AM, zuff <bh...@live.com> wrote:
> <route>
>          <from uri="direct:processResult"/>
>          <bean ref="convertor"/>     [This bean return a Result object that
> I would like to store]


You can store that as a header or property on the exchange, and call
the bean using a method call expression.

<setHeader headerName="foo>
  <method ref="convertor"/>
</setHeader>

There is also a <setProperty>


>          <bean ref="strategyManager"  method="isStrategyCompleted"/>
>          <when>
>                  <simple>${body}</simple>
>                  [Need to retrieve the Result object here and pass it into
> the messageSender]
>                  <bean ref="messageSender" />
>          </when>

You can use bean parameter bindings for mapping the parameters, there
is a number of annotations for that.
http://camel.apache.org/parameter-binding-annotations.html

Or from Camel 2.9 onwards you can specify the mapping in the XML directly.
http://camel.apache.org/bean-binding.html


>          <otherwise>
>            ....
>           </otherwise>
>    </route>
>
> I'm sorry, used HTML comment that was hidden after I posted.
>
> Thanks and Best Regards,
> Zuff
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Correct-use-of-camelproxy-tp5719716p5719836.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: Correct use of camelproxy + (Updating Exchange in Spring DSL)?

Posted by zuff <bh...@live.com>.
<route>
         <from uri="direct:processResult"/>
         <bean ref="convertor"/>     [This bean return a Result object that
I would like to store]
         <bean ref="strategyManager"  method="isStrategyCompleted"/>   
         <when>   
                 <simple>${body}</simple>
                 [Need to retrieve the Result object here and pass it into
the messageSender]
                 <bean ref="messageSender" />
         </when>
         <otherwise>
           ....
          </otherwise>
   </route>

I'm sorry, used HTML comment that was hidden after I posted.

Thanks and Best Regards,
Zuff



--
View this message in context: http://camel.465427.n5.nabble.com/Correct-use-of-camelproxy-tp5719716p5719836.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Correct use of camelproxy + (Updating Exchange in Spring DSL)?

Posted by Claus Ibsen <cl...@gmail.com>.
On Mon, Sep 24, 2012 at 10:46 AM, zuff <bh...@live.com> wrote:
> Hi Claus,
>
>    Thanks. That resolved my problem. I didn't even try such a simple
> changes, as I thought I had to introduce the camel FactoryBean into my POJO.
>
>
>    I have another issue:
> Even though I found some similar post regarding storing of variable for
> later usage, but most of them are in java DSL which I didnt managed to apply
> directly.
>

What do you want to store?

You can store variables on headers of the message or properties on the exchange.
And the XML DSL has constructs to leverage both kinds.




>    <route>
>          <from uri="direct:processResult"/>
>          <bean ref="convertor"/>
>          <bean ref="strategyManager"  method="isStrategyCompleted"/>
>          <when>
>                  <simple>${body}</simple>
>
>                  <bean ref="messageSender" />
>          </when>
>          <otherwise>
>            ....
>           </otherwise>
>    </route>
>
>
> Will appreciated any advise.
>
> Best Regards,
> Zuff
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Correct-use-of-camelproxy-tp5719716p5719834.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: Correct use of camelproxy + (Updating Exchange in Spring DSL)?

Posted by zuff <bh...@live.com>.
Hi Claus,

   Thanks. That resolved my problem. I didn't even try such a simple
changes, as I thought I had to introduce the camel FactoryBean into my POJO.  


   I have another issue:
Even though I found some similar post regarding storing of variable for
later usage, but most of them are in java DSL which I didnt managed to apply
directly.

   <route>
         <from uri="direct:processResult"/>
         <bean ref="convertor"/>             
         <bean ref="strategyManager"  method="isStrategyCompleted"/>    
         <when>   
                 <simple>${body}</simple>
                 
                 <bean ref="messageSender" />
         </when>
         <otherwise>
           ....
          </otherwise>
   </route>
  

Will appreciated any advise.

Best Regards,
Zuff



--
View this message in context: http://camel.465427.n5.nabble.com/Correct-use-of-camelproxy-tp5719716p5719834.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Correct use of camelproxy?

Posted by Claus Ibsen <cl...@gmail.com>.
On Mon, Sep 24, 2012 at 3:43 AM, zuff <bh...@live.com> wrote:
> Hi All,
>
>    I managed to get the route to work. However, I did this by annotating
> @Produce(uri="direct:resultProcessor") on the resultProcessor instance
> variable in the controller class. Is it possible to decouple camel from the
> code, and just use the camelContext.xml for configuration?
>

Yes it can be all done in the XML file only. You would need though in
the XML to setup IoC for the proxy by its id, eg
where you need to use it, you need to inject the bean by id
"resultProxy". eg standard spring bean IoC stuff.




> Thanks and Best Regards,
> Zuff
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Correct-use-of-camelproxy-tp5719716p5719818.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: Correct use of camelproxy?

Posted by zuff <bh...@live.com>.
Hi All,

   I managed to get the route to work. However, I did this by annotating
@Produce(uri="direct:resultProcessor") on the resultProcessor instance
variable in the controller class. Is it possible to decouple camel from the
code, and just use the camelContext.xml for configuration?

Thanks and Best Regards,
Zuff



--
View this message in context: http://camel.465427.n5.nabble.com/Correct-use-of-camelproxy-tp5719716p5719818.html
Sent from the Camel - Users mailing list archive at Nabble.com.