FAQ
Hi,
I'm new to camel and i've tried to follow this example of implementation of
the EndPoint Pattern : http://camel.apache.org/tutorial-jmsremoting.html

I'm running an activeMQ on a VM. the producer & the consumer code are on
different pc.
My goal is to send an xml File from the producer to the broker, do some
operation on it and send an acknowledgment to the producer.

here is how i did it :
context = new ClassPathXmlApplicationContext("camel-client.xml");
CamelContext camel = (CamelContext) context.getBean("camel-client");
// get the endpoint from the camel context
endpoint = camel.getEndpoint("jms:topic:"+topicName);//topicName is
an argument of the java Program.
Exchange exchange = endpoint.createExchange(ExchangePattern.InOut);
// set the input on the in body
exchange.getIn().setBody( msg ); //"msg" is the content of my xmlFile
in a String object .
// to send the exchange we need an producer to do it for us
Producer producer = endpoint.createProducer();
// start the producer so it can operate
producer.start();
producer.process(exchange);

And now i'm waiting for the answer before to stop the producer...
System.out.println("... the result is : " + exchange.getOut().getBody());
producer.stop()
I always get the TimedOutException : The OUT message was not received
within: 20000 millis. Exchange[Message: test]
and i don't understand why. The consumer code works fine, the route i
specified is working well (i.e. the message coming from the topic is
consumed in the bean of my choice).
The method that I call in my consumer returns a String "OK" or "KO",
depending on the validity of the XML file and a bunch of other stuff :)

I just don't get it, the exchange.getOut() is always null; how am I supposed
to set the response to the producer ? :/
Any help will be appreciated :)
Bertrand


--
View this message in context: http://camel.465427.n5.nabble.com/ExchangePattern-InOut-I-Can-t-get-any-response-tp5056301p5056301.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Search Discussions

  • Claus Ibsen at Dec 8, 2011 at 12:27 pm
    Hi

    You need the consumer on the other side, to send back the reply on the
    given JMSReplyTo queue that has been enlisted in the JMS message.
    And if the consumer does not do that without 20 sec, the producer will time out.

    See for example this unit test
    https://svn.apache.org/repos/asf/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsSimpleRequestReplyTest.java
    On Wed, Dec 7, 2011 at 5:55 PM, Gnarf wrote:
    Hi,
    I'm new to camel and i've tried to follow this example of implementation of
    the EndPoint Pattern : http://camel.apache.org/tutorial-jmsremoting.html

    I'm running an activeMQ on a VM. the producer & the consumer code are on
    different pc.
    My goal is to send an xml File from the producer to the broker, do some
    operation on it and send an acknowledgment to the producer.

    here is how i did it :
    context = new ClassPathXmlApplicationContext("camel-client.xml");
    CamelContext camel = (CamelContext) context.getBean("camel-client");
    // get the endpoint from the camel context
    endpoint = camel.getEndpoint("jms:topic:"+topicName);//topicName is
    an argument of the java Program.
    Exchange exchange = endpoint.createExchange(ExchangePattern.InOut);
    // set the input on the in body
    exchange.getIn().setBody( msg ); //"msg" is the content of my xmlFile
    in a String object .
    // to send the exchange we need an producer to do it for us
    Producer producer = endpoint.createProducer();
    // start the producer so it can operate
    producer.start();
    producer.process(exchange);

    And now i'm waiting for the answer before to stop the producer...
    System.out.println("... the result is : " + exchange.getOut().getBody());
    producer.stop()
    I always get the TimedOutException : The OUT message was not received
    within: 20000 millis. Exchange[Message: test]
    and i don't understand why. The consumer code works fine, the route i
    specified is working well (i.e. the message coming from the topic is
    consumed in the bean of my choice).
    The method that I call in my consumer returns a String "OK" or "KO",
    depending on the validity of the XML file and a bunch of other stuff :)

    I just don't get it, the exchange.getOut() is always null; how am I supposed
    to set the response to the producer ? :/
    Any help will be appreciated :)
    Bertrand


    --
    View this message in context: http://camel.465427.n5.nabble.com/ExchangePattern-InOut-I-Can-t-get-any-response-tp5056301p5056301.html
    Sent from the Camel - Users mailing list archive at Nabble.com.


    --
    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/
  • Gnarf at Dec 8, 2011 at 2:30 pm
    Thank you for the answer Claus :)
    I've solved my problem, now i've got another one :(
    I'm trying to do something like this : The Producer is on a pc, sending
    message to a specified topic. He's using the camelTemplate Component to do
    so.
    The Broker (ActiveMQ) is on another pc. I'm trying to define my camels
    routes in the "camel.xml" file contained in the /activeMQ/conf directory.
    example:
    <route>
    <from uri="activemq:topic:ticket"/>
    <to uri="recorder"/>
    </route>
    The broker starts fine, and the route seems to be OK in the camel console.
    My question is : How can I link my consumer Program to interface with camel
    route (i.e. for the moment, if I try to send a message, Camel throw an
    exception cause he don't know the bean "recorder" of destination). Is there
    a way to do so ? Or am I totally insane ? In simple words, I would like to
    have the three programs(producer,broker and consumer) on three separate pc,
    interfacing with each other.
    Thanks in advance,
    Bertrand.

    --
    View this message in context: http://camel.465427.n5.nabble.com/ExchangePattern-InOut-I-Can-t-get-any-response-tp5056301p5058959.html
    Sent from the Camel - Users mailing list archive at Nabble.com.
  • Willem Jiang at Dec 9, 2011 at 2:41 am
    Hi,

    Can I have a look at the recorder definition in your camel context?
    You need to specify a endpoint instance in the camel context.

    On Thu Dec 8 22:29:34 2011, Gnarf wrote:
    Thank you for the answer Claus :)
    I've solved my problem, now i've got another one :(
    I'm trying to do something like this : The Producer is on a pc, sending
    message to a specified topic. He's using the camelTemplate Component to do
    so.
    The Broker (ActiveMQ) is on another pc. I'm trying to define my camels
    routes in the "camel.xml" file contained in the /activeMQ/conf directory.
    example:
    <route>
    <from uri="activemq:topic:ticket"/>
    <to uri="recorder"/>
    </route>
    The broker starts fine, and the route seems to be OK in the camel console.
    My question is : How can I link my consumer Program to interface with camel
    route (i.e. for the moment, if I try to send a message, Camel throw an
    exception cause he don't know the bean "recorder" of destination). Is there
    a way to do so ? Or am I totally insane ? In simple words, I would like to
    have the three programs(producer,broker and consumer) on three separate pc,
    interfacing with each other.
    Thanks in advance,
    Bertrand.

    --
    View this message in context: http://camel.465427.n5.nabble.com/ExchangePattern-InOut-I-Can-t-get-any-response-tp5056301p5058959.html
    Sent from the Camel - Users mailing list archive at Nabble.com.

    --
    Willem
    ----------------------------------
    FuseSource
    Web: http://www.fusesource.com
    Blog: http://willemjiang.blogspot.com (English)
    http://jnn.javaeye.com (Chinese)
    Twitter: willemjiang
    Weibo: willemjiang
  • Gnarf at Dec 12, 2011 at 8:26 am
    Recorder is a bean i've implemented like this :
    @Service(value = "recorder")
    public class RecorderImpl implements Recorder{

    @Handler
    public String recordAndAcknowledge(final String originalMessage, Exchange
    exchange) {
    System.out.println("Recu : " + originalMessage);
    return "Acknowledged !!";
    }


    }

    My camel's route is defined as follow, in a separate class :
    from("jms:topic:ticket").bean(RecorderImpl.class,"recordAndAcknowledge");

    I would like to define my route in the applicationContext.xml, and run a
    consumer "outside the box", i.e. on another pc than the activeMq & Camel
    server.
    For example, my activeMQ is running on pc A, with camel's route defined like
    this :
    <route id="maRoute">
    <from uri="jms:topic:ticket"/>
    <to uri="bean:recorder"/>
    </route>
    And my consumer is running on a pc B, and implement the recorder bean.
    Is there a way do that, or something similar ?
    thanks in advance
    Bertrand



    --
    View this message in context: http://camel.465427.n5.nabble.com/ExchangePattern-InOut-I-Can-t-get-any-response-tp5056301p5067570.html
    Sent from the Camel - Users mailing list archive at Nabble.com.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupusers @
categoriescamel
postedDec 7, '11 at 4:58p
activeDec 12, '11 at 8:26a
posts5
users3
websitecamel.apache.org

People

Translate

site design / logo © 2022 Grokbase