You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Brendan Long <br...@realgo.com> on 2011/07/06 01:04:10 UTC

Having trouble with an InOut route

I've been working on this for a couple days and can't seem to get it
working. What I want is to send a message using a ProducerTemplate, have
it go to JMS, then another Camel route, then return a response (through
the ProducerTemplate).

This page seems to indicate that the last message send in the route will
be returned back to the caller:
https://cwiki.apache.org/confluence/display/CAMEL/Using+getIn+or+getOut+methods+on+Exchange

But the message that gets returned is the same one that I sent through
the ProducerTemplate.

My CamelContext looks like this:

    <camel:camelContext xmlns="http://camel.apache.org/schema/spring">
        <endpoint id="source" uri="jms:${sourceQueue}"/>
        <endpoint id="destination" uri="jms:${destinationQueue}"/>
        <camel:route>
            <from ref="source"/>
            <transacted/>
            <process ref="validator"/>
            <camel:split stopOnException="true" strategyRef="aggregator">
                <camel:method ref="splitter" method="split"/>
                <camel:inOnly ref="destination"/>
            </camel:split>
            <process ref="printStuff"/>
        </camel:route>
    </camel:camelContext>

My printStuff processor just prints the message for debug purposes, and
it shows the exact message I want returned (and doesn't change
anything). So if all I needed to do is make the last message the one I
want returned, I've already done that.

The producer side is like this:

    Exchange exchange = this.producerTemplate.send(this.endpoint,
    ExchangePattern.InOut, new Processor() {
        @Override
        public void process(Exchange exchange) throws Exception {
            exchange.setIn(message);
        }
    });

Can anyone help me out with this? I can't figure out what I'm missing.

Re: Having trouble with an InOut route

Posted by Brendan Long <br...@realgo.com>.
Sorry it looks like my problem was fairly simple. My producer side looks
like this:

    Exchange exchange = this.producerTemplate.send(this.endpoint,
    ExchangePattern.InOut, new Processor() {
       @Override
       public void process(Exchange exchange) throws Exception {
           exchange.setIn(message);
       }
    });
    return exchange.getIn(MyClass.class);

When what I needed was exchange.getOut(MyClass.class);

Thanks for all of the help though!


Re: Having trouble with an InOut route

Posted by Claus Ibsen <cl...@gmail.com>.
On Wed, Jul 6, 2011 at 1:04 AM, Brendan Long <br...@realgo.com> wrote:
> I've been working on this for a couple days and can't seem to get it
> working. What I want is to send a message using a ProducerTemplate, have
> it go to JMS, then another Camel route, then return a response (through
> the ProducerTemplate).
>
> This page seems to indicate that the last message send in the route will
> be returned back to the caller:
> https://cwiki.apache.org/confluence/display/CAMEL/Using+getIn+or+getOut+methods+on+Exchange
>
> But the message that gets returned is the same one that I sent through
> the ProducerTemplate.
>
> My CamelContext looks like this:
>
>    <camel:camelContext xmlns="http://camel.apache.org/schema/spring">
>        <endpoint id="source" uri="jms:${sourceQueue}"/>
>        <endpoint id="destination" uri="jms:${destinationQueue}"/>
>        <camel:route>
>            <from ref="source"/>
>            <transacted/>
>            <process ref="validator"/>
>            <camel:split stopOnException="true" strategyRef="aggregator">
>                <camel:method ref="splitter" method="split"/>
>                <camel:inOnly ref="destination"/>
>            </camel:split>
>            <process ref="printStuff"/>
>        </camel:route>
>    </camel:camelContext>
>
> My printStuff processor just prints the message for debug purposes, and
> it shows the exact message I want returned (and doesn't change
> anything). So if all I needed to do is make the last message the one I
> want returned, I've already done that.
>

Try removing the    <process ref="printStuff"/> to see if it works then.

And post the implementation of the code for your printStufff

> The producer side is like this:
>
>    Exchange exchange = this.producerTemplate.send(this.endpoint,
>    ExchangePattern.InOut, new Processor() {
>        @Override
>        public void process(Exchange exchange) throws Exception {
>            exchange.setIn(message);
>        }
>    });
>
> Can anyone help me out with this? I can't figure out what I'm missing.
>



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

Re: Having trouble with an InOut route

Posted by Brendan Long <br...@realgo.com>.
The splitting and aggregation is working fine. I already got the
splitting working a while ago (other code depends on it and works fine),
and the "printStuff" processor prints out the message I want returned
(so the aggregation strategy is working too).

My problem is that the exact message I send is the one returned, even
though every step along the way returns a different message, so it seems
like it has to be a problem in the JMS endpoint or the ProducerTemplate.

I'm looking at the tracer and the output is kind of confusing. It says
that my message is InOut the entire way but it never sends anything back
to the JMSReplyTo queue..

On 2011-07-05 6:07 PM, Ashwin Karpe wrote:
> Hi,
>
> For starters, I would change the template code to do what is shown in my
> code stub below
>
> Second, You might want to add a trace interceptor to see what is happening
> along the route  http://camel.apache.org/tracer.html
> http://camel.apache.org/tracer.html 
>
> Third, the code you have appended is incomplete since there is insufficient
> information on the aggregation strategy and what it is doing to the message
> and what kind of exchange is expected to be returned.
>
> For ideas on how to craft what you are looking to do, I am appending a
> couple of examples that will help you sort things out.
>
> https://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SplitterTest.java?view=markup
> https://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SplitterTest.java?view=markup 
> https://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringSplitterStopOnExceptionTest.xml?view=markup
> https://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringSplitterStopOnExceptionTest.xml?view=markup 
>
> Cheers,
>
> Ashwin...
>
> -------------------
>     Exchange exchange = this.producerTemplate.send(this.endpoint, 
>     ExchangePattern.InOut, new Processor() { 
>         @Override 
>         public void process(Exchange exchange) throws Exception { 
>             /* exchange.setIn(message); */ 
>             exchange.getIn().setBody(message);
>         } 
>     }); 
> --------------------
>
> -----
> ---------------------------------------------------------
> Ashwin Karpe
> Apache Camel Committer & Sr Principal Consultant
> FUSESource (a Progress Software Corporation subsidiary)
> http://fusesource.com 
>
> Blog: http://opensourceknowledge.blogspot.com 
> ---------------------------------------------------------
> --
> View this message in context: http://camel.465427.n5.nabble.com/Having-trouble-with-an-InOut-route-tp4555130p4555229.html
> Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Having trouble with an InOut route

Posted by Ashwin Karpe <ak...@fusesource.com>.
Hi,

For starters, I would change the template code to do what is shown in my
code stub below

Second, You might want to add a trace interceptor to see what is happening
along the route  http://camel.apache.org/tracer.html
http://camel.apache.org/tracer.html 

Third, the code you have appended is incomplete since there is insufficient
information on the aggregation strategy and what it is doing to the message
and what kind of exchange is expected to be returned.

For ideas on how to craft what you are looking to do, I am appending a
couple of examples that will help you sort things out.

https://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SplitterTest.java?view=markup
https://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SplitterTest.java?view=markup 
https://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringSplitterStopOnExceptionTest.xml?view=markup
https://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringSplitterStopOnExceptionTest.xml?view=markup 

Cheers,

Ashwin...

-------------------
    Exchange exchange = this.producerTemplate.send(this.endpoint, 
    ExchangePattern.InOut, new Processor() { 
        @Override 
        public void process(Exchange exchange) throws Exception { 
            /* exchange.setIn(message); */ 
            exchange.getIn().setBody(message);
        } 
    }); 
--------------------

-----
---------------------------------------------------------
Ashwin Karpe
Apache Camel Committer & Sr Principal Consultant
FUSESource (a Progress Software Corporation subsidiary)
http://fusesource.com 

Blog: http://opensourceknowledge.blogspot.com 
---------------------------------------------------------
--
View this message in context: http://camel.465427.n5.nabble.com/Having-trouble-with-an-InOut-route-tp4555130p4555229.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Having trouble with an InOut route

Posted by Claus Ibsen <cl...@gmail.com>.
On Wed, Jul 6, 2011 at 1:04 AM, Brendan Long <br...@realgo.com> wrote:
> I've been working on this for a couple days and can't seem to get it
> working. What I want is to send a message using a ProducerTemplate, have
> it go to JMS, then another Camel route, then return a response (through
> the ProducerTemplate).
>
> This page seems to indicate that the last message send in the route will
> be returned back to the caller:
> https://cwiki.apache.org/confluence/display/CAMEL/Using+getIn+or+getOut+methods+on+Exchange
>
> But the message that gets returned is the same one that I sent through
> the ProducerTemplate.
>
> My CamelContext looks like this:
>
>    <camel:camelContext xmlns="http://camel.apache.org/schema/spring">
>        <endpoint id="source" uri="jms:${sourceQueue}"/>
>        <endpoint id="destination" uri="jms:${destinationQueue}"/>
>        <camel:route>
>            <from ref="source"/>
>            <transacted/>
>            <process ref="validator"/>
>            <camel:split stopOnException="true" strategyRef="aggregator">
>                <camel:method ref="splitter" method="split"/>
>                <camel:inOnly ref="destination"/>
>            </camel:split>
>            <process ref="printStuff"/>

Try adding
<setExchangePattern pattern="InOut"/>

as last step in the route to ensure the MEP is InOut so the
JmsConsumer can detect this and return the reply.
I think we recently fixed that using <inOnly> etc. not affecting the
MEP successively on trunk.

>        </camel:route>
>    </camel:camelContext>
>
> My printStuff processor just prints the message for debug purposes, and
> it shows the exact message I want returned (and doesn't change
> anything). So if all I needed to do is make the last message the one I
> want returned, I've already done that.
>
> The producer side is like this:
>
>    Exchange exchange = this.producerTemplate.send(this.endpoint,
>    ExchangePattern.InOut, new Processor() {
>        @Override
>        public void process(Exchange exchange) throws Exception {
>            exchange.setIn(message);
>        }
>    });
>
> Can anyone help me out with this? I can't figure out what I'm missing.
>



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