You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Frank Wein <fr...@fau.de> on 2016/11/25 11:34:04 UTC

How to use the InOut (Request-Reply) pattern in combination with REST/Jetty?

Hi all,
I have a problem setting up the correct Camel routes in Java for a 
problem I'm having. I'm still quite new to Camel and ActiveMQ, so please 
be patient with me :)

What I want to accomplish is the following:
* Provide a REST (HTTP GET) endpoint with Camel (Jetty) and send the 
request (message) to an ActiveMQ queue (the ActiveMQ queue is a 
requirement, probably would be easier without)
* Consume the message (with a second route?), take some of the 
parameters from the HTTP URL (so message properties) and send a 
HTTP/REST request to another REST service.
* Take the response from the other REST service and send it back to the 
REST client (from the beginning)

 From my understanding I'm providing some kind of proxy server (with URL 
rewriting), which needs to use the InOut pattern in this case. Later I 
also want to provide other REST operations (e.g. POST) with message body 
transformations, which again get forwarded to other REST services.


My attempts were something like this (simplified code, more or less; so 
don't wonder why the {ID} part disappeared):

getContext().addComponent("activemq",
ActiveMQComponent.activeMQComponent("tcp://localhost:61616"));
restConfiguration().component("jetty").host("localhost").port(8080)
                 .dataFormatProperty("prettyPrint", "true");
rest("/API/").get("/{ID}/").to("direct:getObject");
from("direct:getObject").setExchangePattern(ExchangePattern.InOut).to("activemq:testQueue");
from("activemq:testQueue")
     .setHeader(Exchange.HTTP_PATH,
                simple("/getObject/"))
     .setHeader(Exchange.HTTP_METHOD, simple("GET"))
     .to("jetty:http://localhost:8888?bridgeEndpoint=true");

Probably that's not correct (as I don't really send the REST reply 
back/store somewhere?), I'm a bit lost how to continue here. I found 
http://camel.apache.org/how-to-use-camel-as-a-http-proxy-between-a-client-and-server.html, 
but additionally I need to involve the ActiveMQ queue there (and modify 
the HTTP URL). Maybe I need to get the message out body from the message 
exchange and store the reply there...?


Best regards

Frank


AW: How to use the InOut (Request-Reply) pattern in combination with REST/Jetty?

Posted by "Wein, Frank (RRZE)" <fr...@fau.de>.
Hi,
ok, more or less got what was the problem (user mistake): I used SSH port forwarding on 61616 for the application/client to be able to connect to ActiveMQ (runs on a server that's hidden inside a private network). This does not work (of course) because ActiveMQ uses tcp sockets (at least I did in this case). I guess the confusing thing was that it was able to send messages to the ActiveMQ bus, that is why I did not assume a connection problem at first. Lesson learned, case closed!

Frank
________________________________________
Von: Quinn Stevenson [quinn@pronoia-solutions.com]
Gesendet: Mittwoch, 30. November 2016 16:45
An: users@camel.apache.org
Betreff: Re: How to use the InOut (Request-Reply) pattern in combination with REST/Jetty?

Strange - the ActiveMQ configuration shouldn’t have anything to do with this.  What versions of Camel and ActiveMQ are you using?  I’ve had to use more/different URI options in the JMS URIs in older versions of Camel - I just don’t remember what they are right off hand.

> On Nov 30, 2016, at 3:58 AM, Wein, Frank (RRZE) <fr...@fau.de> wrote:
>
> Hi all,
> just a short update: It looks like I made a mistake on the activemq configuration(?) itself, with an embedded ActiveMQ instance it seems to work fine ("ActiveMQComponent.activeMQComponent("vm://localhost?broker.persistent=false"));). I will take a look at this then. Thanks for everyone who thought about this.
>
> Best regards
> Frank
> ________________________________________
> Von: Wein, Frank (RRZE) [frank.wein@fau.de]
> Gesendet: Dienstag, 29. November 2016 21:49
> An: users@camel.apache.org
> Betreff: AW: How to use the InOut (Request-Reply) pattern in combination with REST/Jetty?
>
> Hi Claus,
> unfortunately this still results in a the same error message (The OUT message was not received...).
> Route now looks like this, rest of the code stayed the same:
>
>        rest("/API/")
>                .get("/object/{ID}/")
>                .to("direct:objectGet");
>
>        from("direct:objectGet").to(ExchangePattern.InOut, "activemq:test");
>
>        from("activemq:test").process(resultProcessor);
>
> The message history tells me:
> RouteId              ProcessorId          Processor                                                                        Elapsed (ms)
> [route1            ] [route1            ] [jetty:http://0.0.0.0:8080/API/object/%7BID%7D?httpMethodRestrict=GET   ] [     21035]
> [route1            ] [restBinding1      ] [                                                                              ] [         6]
> [route1            ] [route1            ] [direct:objectGet                                                              ] [     21019]
> [route2            ] [to1               ] [activemq:test                                                               ] [     21018]
>
> So somehow the messages do not get fetched from the activemq bus, do I see this correctly? Could this also be an ActiveMQ configuration problem? I'm a little bit stuck at this point.
>
> Regards
> Frank
> ________________________________________
> Von: Claus Ibsen [claus.ibsen@gmail.com]
> Gesendet: Dienstag, 29. November 2016 18:49
> An: users@camel.apache.org
> Betreff: Re: How to use the InOut (Request-Reply) pattern in combination with REST/Jetty?
>
> Ah you need to break this up into two separate routes
>
>
> from direct foo
>   to activemq test
>
>
> from activemq test
>   process replyProcessor
>
>
> On Tue, Nov 29, 2016 at 6:21 PM, Wein, Frank (RRZE) <fr...@fau.de> wrote:
>> Hi,
>> thanks for the link, unfortunately it still doesn't seem to work. The Exchange does not receive a reply message:
>> "org.apache.camel.ExchangeTimedOutException: The OUT message was not received within: 20000 millis due reply message with correlationID: [...]-33309-1480438574020-0-3 not received on destination: temp-queue://ID:[...]-35217-1480438579489-1:1:1. Exchange[ID-[...]-33309-1480438574020-0-1]"
>>
>> The incoming messages on the ActiveMQ queue from the REST endpoint end up in the dead-letter queue:
>> dlqDeliveryFailureCause         java.lang.Throwable: Message Expired. Expiration:1480439266246
>>
>> I tried quite a few things (inOut at different position in the route description, getIn, getOut, shared queue, ...), but nothing seems to work (always timeout waiting for the reply). Is it possible at all what I want to accomplish (reminder: Jetty REST endpoint passes message to queue, other route fetches from queue, modifies message and the original endpoint should reply with modified message).
>>
>> Is there a mistake in my current code?
>>
>> Processor resultProcessor = new Processor() {
>>            @Override
>>            public void process(Exchange exchange) throws Exception {
>>                    exchange.getIn().setBody( "response");
>>                return;
>>            }
>>        };
>>
>>        getContext().addComponent("activemq", ActiveMQComponent.activeMQComponent("tcp://localhost:61616"));
>>
>>        restConfiguration().component("jetty").host("0.0.0.0").port(8080).dataFormatProperty("prettyPrint", "true");
>>
>>        rest("/API/").get("/object/{ID}/").to("direct:objectGet");
>>
>>        from("direct:objectGet").to(ExchangePattern.InOut, "activemq:test").process(resultProcessor).to("activemq:test");
>>
>>
>> Is my "to("activemq:test")" not the correct way to send back the modified message to the producer? Actually I thought the message exchange will automatically take care of sending back to the modified message body to the producer (doesn't seem to make a difference here anyway).
>>
>>
>> Thanks for any suggestions!
>>
>> Frank
>>
>> ________________________________________
>> Von: Quinn Stevenson [quinn@pronoia-solutions.com]
>> Gesendet: Montag, 28. November 2016 17:35
>> An: users@camel.apache.org
>> Betreff: Re: How to use the InOut (Request-Reply) pattern in combination with REST/Jetty?
>>
>> Yes - this is possible.  Look at "Request-Reply” in the JMS docs ( http://camel.apache.org/jms.html <http://camel.apache.org/jms.html> ).
>>
>>
>>> On Nov 28, 2016, at 12:51 AM, Frank Wein <fr...@fau.de> wrote:
>>>
>>> Hi all,
>>> some additional info/Java code: What I have currently working is some code without the ActiveMQ part:
>>>
>>> restConfiguration().component("jetty").host("0.0.0.0").port(8080)
>>>               .dataFormatProperty("prettyPrint", "true")
>>>               .bindingMode(RestBindingMode.auto);
>>>
>>>      rest("/API/").get("/object/{ID}/").to("direct:objectGet");
>>>
>>>       from("direct:objectGet")
>>>                .setExchangePattern(ExchangePattern.InOut)
>>>                .setHeader(Exchange.HTTP_PATH, simple(
>>> "/Webservice/RESTService/Object/${header.ID}"))
>>>                .setHeader(Exchange.HTTP_METHOD, simple("GET"))
>>> .to("jetty://http://localhost:8888?bridgeEndpoint=true");
>>>
>>> I send my REST request to localhost:8080/object/[ID]/ and get back the reply from the other webservice running on localhost:8888.
>>>
>>> Now, I want to include an ActiveMQ queue here. Basically the ActiveMQ queue should be between the two routes (from/to("direct:objectGet")). The first route should send the message to the queue, the second route should fetch it, get the response from the other web service and send the response back via the queue to the first route. This one should then reply to the incoming REST request. Is this possible, if yes, how? My attempts at this did not really work.
>>>
>>> Regards
>>> Frank
>
>
>
> --
> Claus Ibsen
> -----------------
> http://davsclaus.com @davsclaus
> Camel in Action 2: https://www.manning.com/ibsen2


Re: How to use the InOut (Request-Reply) pattern in combination with REST/Jetty?

Posted by Quinn Stevenson <qu...@pronoia-solutions.com>.
Strange - the ActiveMQ configuration shouldn’t have anything to do with this.  What versions of Camel and ActiveMQ are you using?  I’ve had to use more/different URI options in the JMS URIs in older versions of Camel - I just don’t remember what they are right off hand.

> On Nov 30, 2016, at 3:58 AM, Wein, Frank (RRZE) <fr...@fau.de> wrote:
> 
> Hi all,
> just a short update: It looks like I made a mistake on the activemq configuration(?) itself, with an embedded ActiveMQ instance it seems to work fine ("ActiveMQComponent.activeMQComponent("vm://localhost?broker.persistent=false"));). I will take a look at this then. Thanks for everyone who thought about this.
> 
> Best regards
> Frank
> ________________________________________
> Von: Wein, Frank (RRZE) [frank.wein@fau.de]
> Gesendet: Dienstag, 29. November 2016 21:49
> An: users@camel.apache.org
> Betreff: AW: How to use the InOut (Request-Reply) pattern in combination with REST/Jetty?
> 
> Hi Claus,
> unfortunately this still results in a the same error message (The OUT message was not received...).
> Route now looks like this, rest of the code stayed the same:
> 
>        rest("/API/")
>                .get("/object/{ID}/")
>                .to("direct:objectGet");
> 
>        from("direct:objectGet").to(ExchangePattern.InOut, "activemq:test");
> 
>        from("activemq:test").process(resultProcessor);
> 
> The message history tells me:
> RouteId              ProcessorId          Processor                                                                        Elapsed (ms)
> [route1            ] [route1            ] [jetty:http://0.0.0.0:8080/API/object/%7BID%7D?httpMethodRestrict=GET   ] [     21035]
> [route1            ] [restBinding1      ] [                                                                              ] [         6]
> [route1            ] [route1            ] [direct:objectGet                                                              ] [     21019]
> [route2            ] [to1               ] [activemq:test                                                               ] [     21018]
> 
> So somehow the messages do not get fetched from the activemq bus, do I see this correctly? Could this also be an ActiveMQ configuration problem? I'm a little bit stuck at this point.
> 
> Regards
> Frank
> ________________________________________
> Von: Claus Ibsen [claus.ibsen@gmail.com]
> Gesendet: Dienstag, 29. November 2016 18:49
> An: users@camel.apache.org
> Betreff: Re: How to use the InOut (Request-Reply) pattern in combination with REST/Jetty?
> 
> Ah you need to break this up into two separate routes
> 
> 
> from direct foo
>   to activemq test
> 
> 
> from activemq test
>   process replyProcessor
> 
> 
> On Tue, Nov 29, 2016 at 6:21 PM, Wein, Frank (RRZE) <fr...@fau.de> wrote:
>> Hi,
>> thanks for the link, unfortunately it still doesn't seem to work. The Exchange does not receive a reply message:
>> "org.apache.camel.ExchangeTimedOutException: The OUT message was not received within: 20000 millis due reply message with correlationID: [...]-33309-1480438574020-0-3 not received on destination: temp-queue://ID:[...]-35217-1480438579489-1:1:1. Exchange[ID-[...]-33309-1480438574020-0-1]"
>> 
>> The incoming messages on the ActiveMQ queue from the REST endpoint end up in the dead-letter queue:
>> dlqDeliveryFailureCause         java.lang.Throwable: Message Expired. Expiration:1480439266246
>> 
>> I tried quite a few things (inOut at different position in the route description, getIn, getOut, shared queue, ...), but nothing seems to work (always timeout waiting for the reply). Is it possible at all what I want to accomplish (reminder: Jetty REST endpoint passes message to queue, other route fetches from queue, modifies message and the original endpoint should reply with modified message).
>> 
>> Is there a mistake in my current code?
>> 
>> Processor resultProcessor = new Processor() {
>>            @Override
>>            public void process(Exchange exchange) throws Exception {
>>                    exchange.getIn().setBody( "response");
>>                return;
>>            }
>>        };
>> 
>>        getContext().addComponent("activemq", ActiveMQComponent.activeMQComponent("tcp://localhost:61616"));
>> 
>>        restConfiguration().component("jetty").host("0.0.0.0").port(8080).dataFormatProperty("prettyPrint", "true");
>> 
>>        rest("/API/").get("/object/{ID}/").to("direct:objectGet");
>> 
>>        from("direct:objectGet").to(ExchangePattern.InOut, "activemq:test").process(resultProcessor).to("activemq:test");
>> 
>> 
>> Is my "to("activemq:test")" not the correct way to send back the modified message to the producer? Actually I thought the message exchange will automatically take care of sending back to the modified message body to the producer (doesn't seem to make a difference here anyway).
>> 
>> 
>> Thanks for any suggestions!
>> 
>> Frank
>> 
>> ________________________________________
>> Von: Quinn Stevenson [quinn@pronoia-solutions.com]
>> Gesendet: Montag, 28. November 2016 17:35
>> An: users@camel.apache.org
>> Betreff: Re: How to use the InOut (Request-Reply) pattern in combination with REST/Jetty?
>> 
>> Yes - this is possible.  Look at "Request-Reply” in the JMS docs ( http://camel.apache.org/jms.html <http://camel.apache.org/jms.html> ).
>> 
>> 
>>> On Nov 28, 2016, at 12:51 AM, Frank Wein <fr...@fau.de> wrote:
>>> 
>>> Hi all,
>>> some additional info/Java code: What I have currently working is some code without the ActiveMQ part:
>>> 
>>> restConfiguration().component("jetty").host("0.0.0.0").port(8080)
>>>               .dataFormatProperty("prettyPrint", "true")
>>>               .bindingMode(RestBindingMode.auto);
>>> 
>>>      rest("/API/").get("/object/{ID}/").to("direct:objectGet");
>>> 
>>>       from("direct:objectGet")
>>>                .setExchangePattern(ExchangePattern.InOut)
>>>                .setHeader(Exchange.HTTP_PATH, simple(
>>> "/Webservice/RESTService/Object/${header.ID}"))
>>>                .setHeader(Exchange.HTTP_METHOD, simple("GET"))
>>> .to("jetty://http://localhost:8888?bridgeEndpoint=true");
>>> 
>>> I send my REST request to localhost:8080/object/[ID]/ and get back the reply from the other webservice running on localhost:8888.
>>> 
>>> Now, I want to include an ActiveMQ queue here. Basically the ActiveMQ queue should be between the two routes (from/to("direct:objectGet")). The first route should send the message to the queue, the second route should fetch it, get the response from the other web service and send the response back via the queue to the first route. This one should then reply to the incoming REST request. Is this possible, if yes, how? My attempts at this did not really work.
>>> 
>>> Regards
>>> Frank
> 
> 
> 
> --
> Claus Ibsen
> -----------------
> http://davsclaus.com @davsclaus
> Camel in Action 2: https://www.manning.com/ibsen2


AW: How to use the InOut (Request-Reply) pattern in combination with REST/Jetty?

Posted by "Wein, Frank (RRZE)" <fr...@fau.de>.
Hi all,
just a short update: It looks like I made a mistake on the activemq configuration(?) itself, with an embedded ActiveMQ instance it seems to work fine ("ActiveMQComponent.activeMQComponent("vm://localhost?broker.persistent=false"));). I will take a look at this then. Thanks for everyone who thought about this.

Best regards
Frank
________________________________________
Von: Wein, Frank (RRZE) [frank.wein@fau.de]
Gesendet: Dienstag, 29. November 2016 21:49
An: users@camel.apache.org
Betreff: AW: How to use the InOut (Request-Reply) pattern in combination with REST/Jetty?

Hi Claus,
unfortunately this still results in a the same error message (The OUT message was not received...).
Route now looks like this, rest of the code stayed the same:

        rest("/API/")
                .get("/object/{ID}/")
                .to("direct:objectGet");

        from("direct:objectGet").to(ExchangePattern.InOut, "activemq:test");

        from("activemq:test").process(resultProcessor);

The message history tells me:
RouteId              ProcessorId          Processor                                                                        Elapsed (ms)
[route1            ] [route1            ] [jetty:http://0.0.0.0:8080/API/object/%7BID%7D?httpMethodRestrict=GET   ] [     21035]
[route1            ] [restBinding1      ] [                                                                              ] [         6]
[route1            ] [route1            ] [direct:objectGet                                                              ] [     21019]
[route2            ] [to1               ] [activemq:test                                                               ] [     21018]

So somehow the messages do not get fetched from the activemq bus, do I see this correctly? Could this also be an ActiveMQ configuration problem? I'm a little bit stuck at this point.

Regards
Frank
________________________________________
Von: Claus Ibsen [claus.ibsen@gmail.com]
Gesendet: Dienstag, 29. November 2016 18:49
An: users@camel.apache.org
Betreff: Re: How to use the InOut (Request-Reply) pattern in combination with REST/Jetty?

Ah you need to break this up into two separate routes


from direct foo
   to activemq test


from activemq test
   process replyProcessor


On Tue, Nov 29, 2016 at 6:21 PM, Wein, Frank (RRZE) <fr...@fau.de> wrote:
> Hi,
> thanks for the link, unfortunately it still doesn't seem to work. The Exchange does not receive a reply message:
> "org.apache.camel.ExchangeTimedOutException: The OUT message was not received within: 20000 millis due reply message with correlationID: [...]-33309-1480438574020-0-3 not received on destination: temp-queue://ID:[...]-35217-1480438579489-1:1:1. Exchange[ID-[...]-33309-1480438574020-0-1]"
>
> The incoming messages on the ActiveMQ queue from the REST endpoint end up in the dead-letter queue:
> dlqDeliveryFailureCause         java.lang.Throwable: Message Expired. Expiration:1480439266246
>
> I tried quite a few things (inOut at different position in the route description, getIn, getOut, shared queue, ...), but nothing seems to work (always timeout waiting for the reply). Is it possible at all what I want to accomplish (reminder: Jetty REST endpoint passes message to queue, other route fetches from queue, modifies message and the original endpoint should reply with modified message).
>
> Is there a mistake in my current code?
>
>  Processor resultProcessor = new Processor() {
>             @Override
>             public void process(Exchange exchange) throws Exception {
>                     exchange.getIn().setBody( "response");
>                 return;
>             }
>         };
>
>         getContext().addComponent("activemq", ActiveMQComponent.activeMQComponent("tcp://localhost:61616"));
>
>         restConfiguration().component("jetty").host("0.0.0.0").port(8080).dataFormatProperty("prettyPrint", "true");
>
>         rest("/API/").get("/object/{ID}/").to("direct:objectGet");
>
>         from("direct:objectGet").to(ExchangePattern.InOut, "activemq:test").process(resultProcessor).to("activemq:test");
>
>
> Is my "to("activemq:test")" not the correct way to send back the modified message to the producer? Actually I thought the message exchange will automatically take care of sending back to the modified message body to the producer (doesn't seem to make a difference here anyway).
>
>
> Thanks for any suggestions!
>
> Frank
>
> ________________________________________
> Von: Quinn Stevenson [quinn@pronoia-solutions.com]
> Gesendet: Montag, 28. November 2016 17:35
> An: users@camel.apache.org
> Betreff: Re: How to use the InOut (Request-Reply) pattern in combination with REST/Jetty?
>
> Yes - this is possible.  Look at "Request-Reply” in the JMS docs ( http://camel.apache.org/jms.html <http://camel.apache.org/jms.html> ).
>
>
>> On Nov 28, 2016, at 12:51 AM, Frank Wein <fr...@fau.de> wrote:
>>
>> Hi all,
>> some additional info/Java code: What I have currently working is some code without the ActiveMQ part:
>>
>> restConfiguration().component("jetty").host("0.0.0.0").port(8080)
>>                .dataFormatProperty("prettyPrint", "true")
>>                .bindingMode(RestBindingMode.auto);
>>
>>       rest("/API/").get("/object/{ID}/").to("direct:objectGet");
>>
>>        from("direct:objectGet")
>>                 .setExchangePattern(ExchangePattern.InOut)
>>                 .setHeader(Exchange.HTTP_PATH, simple(
>> "/Webservice/RESTService/Object/${header.ID}"))
>>                 .setHeader(Exchange.HTTP_METHOD, simple("GET"))
>> .to("jetty://http://localhost:8888?bridgeEndpoint=true");
>>
>> I send my REST request to localhost:8080/object/[ID]/ and get back the reply from the other webservice running on localhost:8888.
>>
>> Now, I want to include an ActiveMQ queue here. Basically the ActiveMQ queue should be between the two routes (from/to("direct:objectGet")). The first route should send the message to the queue, the second route should fetch it, get the response from the other web service and send the response back via the queue to the first route. This one should then reply to the incoming REST request. Is this possible, if yes, how? My attempts at this did not really work.
>>
>> Regards
>> Frank



--
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2

AW: How to use the InOut (Request-Reply) pattern in combination with REST/Jetty?

Posted by "Wein, Frank (RRZE)" <fr...@fau.de>.
Hi Claus,
unfortunately this still results in a the same error message (The OUT message was not received...).
Route now looks like this, rest of the code stayed the same:

        rest("/API/")
                .get("/object/{ID}/")
                .to("direct:objectGet");

        from("direct:objectGet").to(ExchangePattern.InOut, "activemq:test");
        
        from("activemq:test").process(resultProcessor);

The message history tells me:
RouteId              ProcessorId          Processor                                                                        Elapsed (ms)
[route1            ] [route1            ] [jetty:http://0.0.0.0:8080/API/object/%7BID%7D?httpMethodRestrict=GET   ] [     21035]
[route1            ] [restBinding1      ] [                                                                              ] [         6]
[route1            ] [route1            ] [direct:objectGet                                                              ] [     21019]
[route2            ] [to1               ] [activemq:test                                                               ] [     21018]

So somehow the messages do not get fetched from the activemq bus, do I see this correctly? Could this also be an ActiveMQ configuration problem? I'm a little bit stuck at this point.

Regards
Frank
________________________________________
Von: Claus Ibsen [claus.ibsen@gmail.com]
Gesendet: Dienstag, 29. November 2016 18:49
An: users@camel.apache.org
Betreff: Re: How to use the InOut (Request-Reply) pattern in combination with REST/Jetty?

Ah you need to break this up into two separate routes


from direct foo
   to activemq test


from activemq test
   process replyProcessor


On Tue, Nov 29, 2016 at 6:21 PM, Wein, Frank (RRZE) <fr...@fau.de> wrote:
> Hi,
> thanks for the link, unfortunately it still doesn't seem to work. The Exchange does not receive a reply message:
> "org.apache.camel.ExchangeTimedOutException: The OUT message was not received within: 20000 millis due reply message with correlationID: [...]-33309-1480438574020-0-3 not received on destination: temp-queue://ID:[...]-35217-1480438579489-1:1:1. Exchange[ID-[...]-33309-1480438574020-0-1]"
>
> The incoming messages on the ActiveMQ queue from the REST endpoint end up in the dead-letter queue:
> dlqDeliveryFailureCause         java.lang.Throwable: Message Expired. Expiration:1480439266246
>
> I tried quite a few things (inOut at different position in the route description, getIn, getOut, shared queue, ...), but nothing seems to work (always timeout waiting for the reply). Is it possible at all what I want to accomplish (reminder: Jetty REST endpoint passes message to queue, other route fetches from queue, modifies message and the original endpoint should reply with modified message).
>
> Is there a mistake in my current code?
>
>  Processor resultProcessor = new Processor() {
>             @Override
>             public void process(Exchange exchange) throws Exception {
>                     exchange.getIn().setBody( "response");
>                 return;
>             }
>         };
>
>         getContext().addComponent("activemq", ActiveMQComponent.activeMQComponent("tcp://localhost:61616"));
>
>         restConfiguration().component("jetty").host("0.0.0.0").port(8080).dataFormatProperty("prettyPrint", "true");
>
>         rest("/API/").get("/object/{ID}/").to("direct:objectGet");
>
>         from("direct:objectGet").to(ExchangePattern.InOut, "activemq:test").process(resultProcessor).to("activemq:test");
>
>
> Is my "to("activemq:test")" not the correct way to send back the modified message to the producer? Actually I thought the message exchange will automatically take care of sending back to the modified message body to the producer (doesn't seem to make a difference here anyway).
>
>
> Thanks for any suggestions!
>
> Frank
>
> ________________________________________
> Von: Quinn Stevenson [quinn@pronoia-solutions.com]
> Gesendet: Montag, 28. November 2016 17:35
> An: users@camel.apache.org
> Betreff: Re: How to use the InOut (Request-Reply) pattern in combination with REST/Jetty?
>
> Yes - this is possible.  Look at "Request-Reply” in the JMS docs ( http://camel.apache.org/jms.html <http://camel.apache.org/jms.html> ).
>
>
>> On Nov 28, 2016, at 12:51 AM, Frank Wein <fr...@fau.de> wrote:
>>
>> Hi all,
>> some additional info/Java code: What I have currently working is some code without the ActiveMQ part:
>>
>> restConfiguration().component("jetty").host("0.0.0.0").port(8080)
>>                .dataFormatProperty("prettyPrint", "true")
>>                .bindingMode(RestBindingMode.auto);
>>
>>       rest("/API/").get("/object/{ID}/").to("direct:objectGet");
>>
>>        from("direct:objectGet")
>>                 .setExchangePattern(ExchangePattern.InOut)
>>                 .setHeader(Exchange.HTTP_PATH, simple(
>> "/Webservice/RESTService/Object/${header.ID}"))
>>                 .setHeader(Exchange.HTTP_METHOD, simple("GET"))
>> .to("jetty://http://localhost:8888?bridgeEndpoint=true");
>>
>> I send my REST request to localhost:8080/object/[ID]/ and get back the reply from the other webservice running on localhost:8888.
>>
>> Now, I want to include an ActiveMQ queue here. Basically the ActiveMQ queue should be between the two routes (from/to("direct:objectGet")). The first route should send the message to the queue, the second route should fetch it, get the response from the other web service and send the response back via the queue to the first route. This one should then reply to the incoming REST request. Is this possible, if yes, how? My attempts at this did not really work.
>>
>> Regards
>> Frank



--
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2

Re: How to use the InOut (Request-Reply) pattern in combination with REST/Jetty?

Posted by Claus Ibsen <cl...@gmail.com>.
Ah you need to break this up into two separate routes


from direct foo
   to activemq test


from activemq test
   process replyProcessor


On Tue, Nov 29, 2016 at 6:21 PM, Wein, Frank (RRZE) <fr...@fau.de> wrote:
> Hi,
> thanks for the link, unfortunately it still doesn't seem to work. The Exchange does not receive a reply message:
> "org.apache.camel.ExchangeTimedOutException: The OUT message was not received within: 20000 millis due reply message with correlationID: [...]-33309-1480438574020-0-3 not received on destination: temp-queue://ID:[...]-35217-1480438579489-1:1:1. Exchange[ID-[...]-33309-1480438574020-0-1]"
>
> The incoming messages on the ActiveMQ queue from the REST endpoint end up in the dead-letter queue:
> dlqDeliveryFailureCause         java.lang.Throwable: Message Expired. Expiration:1480439266246
>
> I tried quite a few things (inOut at different position in the route description, getIn, getOut, shared queue, ...), but nothing seems to work (always timeout waiting for the reply). Is it possible at all what I want to accomplish (reminder: Jetty REST endpoint passes message to queue, other route fetches from queue, modifies message and the original endpoint should reply with modified message).
>
> Is there a mistake in my current code?
>
>  Processor resultProcessor = new Processor() {
>             @Override
>             public void process(Exchange exchange) throws Exception {
>                     exchange.getIn().setBody( "response");
>                 return;
>             }
>         };
>
>         getContext().addComponent("activemq", ActiveMQComponent.activeMQComponent("tcp://localhost:61616"));
>
>         restConfiguration().component("jetty").host("0.0.0.0").port(8080).dataFormatProperty("prettyPrint", "true");
>
>         rest("/API/").get("/object/{ID}/").to("direct:objectGet");
>
>         from("direct:objectGet").to(ExchangePattern.InOut, "activemq:test").process(resultProcessor).to("activemq:test");
>
>
> Is my "to("activemq:test")" not the correct way to send back the modified message to the producer? Actually I thought the message exchange will automatically take care of sending back to the modified message body to the producer (doesn't seem to make a difference here anyway).
>
>
> Thanks for any suggestions!
>
> Frank
>
> ________________________________________
> Von: Quinn Stevenson [quinn@pronoia-solutions.com]
> Gesendet: Montag, 28. November 2016 17:35
> An: users@camel.apache.org
> Betreff: Re: How to use the InOut (Request-Reply) pattern in combination with REST/Jetty?
>
> Yes - this is possible.  Look at "Request-Reply” in the JMS docs ( http://camel.apache.org/jms.html <http://camel.apache.org/jms.html> ).
>
>
>> On Nov 28, 2016, at 12:51 AM, Frank Wein <fr...@fau.de> wrote:
>>
>> Hi all,
>> some additional info/Java code: What I have currently working is some code without the ActiveMQ part:
>>
>> restConfiguration().component("jetty").host("0.0.0.0").port(8080)
>>                .dataFormatProperty("prettyPrint", "true")
>>                .bindingMode(RestBindingMode.auto);
>>
>>       rest("/API/").get("/object/{ID}/").to("direct:objectGet");
>>
>>        from("direct:objectGet")
>>                 .setExchangePattern(ExchangePattern.InOut)
>>                 .setHeader(Exchange.HTTP_PATH, simple(
>> "/Webservice/RESTService/Object/${header.ID}"))
>>                 .setHeader(Exchange.HTTP_METHOD, simple("GET"))
>> .to("jetty://http://localhost:8888?bridgeEndpoint=true");
>>
>> I send my REST request to localhost:8080/object/[ID]/ and get back the reply from the other webservice running on localhost:8888.
>>
>> Now, I want to include an ActiveMQ queue here. Basically the ActiveMQ queue should be between the two routes (from/to("direct:objectGet")). The first route should send the message to the queue, the second route should fetch it, get the response from the other web service and send the response back via the queue to the first route. This one should then reply to the incoming REST request. Is this possible, if yes, how? My attempts at this did not really work.
>>
>> Regards
>> Frank



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2

AW: How to use the InOut (Request-Reply) pattern in combination with REST/Jetty?

Posted by "Wein, Frank (RRZE)" <fr...@fau.de>.
Hi,
thanks for the link, unfortunately it still doesn't seem to work. The Exchange does not receive a reply message:
"org.apache.camel.ExchangeTimedOutException: The OUT message was not received within: 20000 millis due reply message with correlationID: [...]-33309-1480438574020-0-3 not received on destination: temp-queue://ID:[...]-35217-1480438579489-1:1:1. Exchange[ID-[...]-33309-1480438574020-0-1]"

The incoming messages on the ActiveMQ queue from the REST endpoint end up in the dead-letter queue:
dlqDeliveryFailureCause 	java.lang.Throwable: Message Expired. Expiration:1480439266246

I tried quite a few things (inOut at different position in the route description, getIn, getOut, shared queue, ...), but nothing seems to work (always timeout waiting for the reply). Is it possible at all what I want to accomplish (reminder: Jetty REST endpoint passes message to queue, other route fetches from queue, modifies message and the original endpoint should reply with modified message).

Is there a mistake in my current code?

 Processor resultProcessor = new Processor() {
            @Override
            public void process(Exchange exchange) throws Exception {
                    exchange.getIn().setBody( "response");
                return;
            }
        };
      
        getContext().addComponent("activemq", ActiveMQComponent.activeMQComponent("tcp://localhost:61616"));

        restConfiguration().component("jetty").host("0.0.0.0").port(8080).dataFormatProperty("prettyPrint", "true");

        rest("/API/").get("/object/{ID}/").to("direct:objectGet");

        from("direct:objectGet").to(ExchangePattern.InOut, "activemq:test").process(resultProcessor).to("activemq:test");


Is my "to("activemq:test")" not the correct way to send back the modified message to the producer? Actually I thought the message exchange will automatically take care of sending back to the modified message body to the producer (doesn't seem to make a difference here anyway).


Thanks for any suggestions!

Frank

________________________________________
Von: Quinn Stevenson [quinn@pronoia-solutions.com]
Gesendet: Montag, 28. November 2016 17:35
An: users@camel.apache.org
Betreff: Re: How to use the InOut (Request-Reply) pattern in combination with REST/Jetty?

Yes - this is possible.  Look at "Request-Reply” in the JMS docs ( http://camel.apache.org/jms.html <http://camel.apache.org/jms.html> ).


> On Nov 28, 2016, at 12:51 AM, Frank Wein <fr...@fau.de> wrote:
>
> Hi all,
> some additional info/Java code: What I have currently working is some code without the ActiveMQ part:
>
> restConfiguration().component("jetty").host("0.0.0.0").port(8080)
>                .dataFormatProperty("prettyPrint", "true")
>                .bindingMode(RestBindingMode.auto);
>
>       rest("/API/").get("/object/{ID}/").to("direct:objectGet");
>
>        from("direct:objectGet")
>                 .setExchangePattern(ExchangePattern.InOut)
>                 .setHeader(Exchange.HTTP_PATH, simple(
> "/Webservice/RESTService/Object/${header.ID}"))
>                 .setHeader(Exchange.HTTP_METHOD, simple("GET"))
> .to("jetty://http://localhost:8888?bridgeEndpoint=true");
>
> I send my REST request to localhost:8080/object/[ID]/ and get back the reply from the other webservice running on localhost:8888.
>
> Now, I want to include an ActiveMQ queue here. Basically the ActiveMQ queue should be between the two routes (from/to("direct:objectGet")). The first route should send the message to the queue, the second route should fetch it, get the response from the other web service and send the response back via the queue to the first route. This one should then reply to the incoming REST request. Is this possible, if yes, how? My attempts at this did not really work.
>
> Regards
> Frank

Re: How to use the InOut (Request-Reply) pattern in combination with REST/Jetty?

Posted by Quinn Stevenson <qu...@pronoia-solutions.com>.
I created a simple example of JMS request-response with Camel a while ago - it may help ( https://github.com/hqstevenson/camel-jms-request-response-example.git <https://github.com/hqstevenson/camel-jms-request-response-example.git> )

> On Nov 28, 2016, at 9:35 AM, Quinn Stevenson <qu...@pronoia-solutions.com> wrote:
> 
> Yes - this is possible.  Look at "Request-Reply” in the JMS docs ( http://camel.apache.org/jms.html <http://camel.apache.org/jms.html> ).
> 
> 
>> On Nov 28, 2016, at 12:51 AM, Frank Wein <frank.wein@fau.de <ma...@fau.de>> wrote:
>> 
>> Hi all,
>> some additional info/Java code: What I have currently working is some code without the ActiveMQ part:
>> 
>> restConfiguration().component("jetty").host("0.0.0.0").port(8080)
>>                .dataFormatProperty("prettyPrint", "true")
>>                .bindingMode(RestBindingMode.auto);
>> 
>>       rest("/API/").get("/object/{ID}/").to("direct:objectGet");
>> 
>>        from("direct:objectGet")
>>                 .setExchangePattern(ExchangePattern.InOut)
>>                 .setHeader(Exchange.HTTP_PATH, simple(
>> "/Webservice/RESTService/Object/${header.ID}"))
>>                 .setHeader(Exchange.HTTP_METHOD, simple("GET"))
>> .to("jetty://http://localhost:8888?bridgeEndpoint=true <jetty://http//localhost:8888?bridgeEndpoint=true>");
>> 
>> I send my REST request to localhost:8080/object/[ID]/ and get back the reply from the other webservice running on localhost:8888.
>> 
>> Now, I want to include an ActiveMQ queue here. Basically the ActiveMQ queue should be between the two routes (from/to("direct:objectGet")). The first route should send the message to the queue, the second route should fetch it, get the response from the other web service and send the response back via the queue to the first route. This one should then reply to the incoming REST request. Is this possible, if yes, how? My attempts at this did not really work.
>> 
>> Regards
>> Frank
>> 
>> 
>> Frank Wein wrote:
>>> Hi all,
>>> I have a problem setting up the correct Camel routes in Java for a problem I'm having. I'm still quite new to Camel and ActiveMQ, so please be patient with me :)
>>> 
>>> What I want to accomplish is the following:
>>> * Provide a REST (HTTP GET) endpoint with Camel (Jetty) and send the request (message) to an ActiveMQ queue (the ActiveMQ queue is a requirement, probably would be easier without)
>>> * Consume the message (with a second route?), take some of the parameters from the HTTP URL (so message properties) and send a HTTP/REST request to another REST service.
>>> * Take the response from the other REST service and send it back to the REST client (from the beginning)
>> 
>> 
>> -- 
>> Frank Wein
>> Forschungsgruppe Netz
>> Friedrich-Alexander-Universitaet Erlangen-Nuernberg
>> Regionales Rechenzentrum Erlangen (RRZE)
>> Martensstrasse 1, 91058 Erlangen, Germany
>> Tel. +49 9131/85-29983, Fax +49 9131/302941
>> frank.wein@fau.de <ma...@fau.de>
>> www.rrze.fau.de
>> 
>> 
> 


Re: How to use the InOut (Request-Reply) pattern in combination with REST/Jetty?

Posted by Quinn Stevenson <qu...@pronoia-solutions.com>.
Yes - this is possible.  Look at "Request-Reply” in the JMS docs ( http://camel.apache.org/jms.html <http://camel.apache.org/jms.html> ).


> On Nov 28, 2016, at 12:51 AM, Frank Wein <fr...@fau.de> wrote:
> 
> Hi all,
> some additional info/Java code: What I have currently working is some code without the ActiveMQ part:
> 
> restConfiguration().component("jetty").host("0.0.0.0").port(8080)
>                .dataFormatProperty("prettyPrint", "true")
>                .bindingMode(RestBindingMode.auto);
> 
>       rest("/API/").get("/object/{ID}/").to("direct:objectGet");
> 
>        from("direct:objectGet")
>                 .setExchangePattern(ExchangePattern.InOut)
>                 .setHeader(Exchange.HTTP_PATH, simple(
> "/Webservice/RESTService/Object/${header.ID}"))
>                 .setHeader(Exchange.HTTP_METHOD, simple("GET"))
> .to("jetty://http://localhost:8888?bridgeEndpoint=true");
> 
> I send my REST request to localhost:8080/object/[ID]/ and get back the reply from the other webservice running on localhost:8888.
> 
> Now, I want to include an ActiveMQ queue here. Basically the ActiveMQ queue should be between the two routes (from/to("direct:objectGet")). The first route should send the message to the queue, the second route should fetch it, get the response from the other web service and send the response back via the queue to the first route. This one should then reply to the incoming REST request. Is this possible, if yes, how? My attempts at this did not really work.
> 
> Regards
> Frank
> 
> 
> Frank Wein wrote:
>> Hi all,
>> I have a problem setting up the correct Camel routes in Java for a problem I'm having. I'm still quite new to Camel and ActiveMQ, so please be patient with me :)
>> 
>> What I want to accomplish is the following:
>> * Provide a REST (HTTP GET) endpoint with Camel (Jetty) and send the request (message) to an ActiveMQ queue (the ActiveMQ queue is a requirement, probably would be easier without)
>> * Consume the message (with a second route?), take some of the parameters from the HTTP URL (so message properties) and send a HTTP/REST request to another REST service.
>> * Take the response from the other REST service and send it back to the REST client (from the beginning)
> 
> 
> -- 
> Frank Wein
> Forschungsgruppe Netz
> Friedrich-Alexander-Universitaet Erlangen-Nuernberg
> Regionales Rechenzentrum Erlangen (RRZE)
> Martensstrasse 1, 91058 Erlangen, Germany
> Tel. +49 9131/85-29983, Fax +49 9131/302941
> frank.wein@fau.de
> www.rrze.fau.de
> 
> 


Re: How to use the InOut (Request-Reply) pattern in combination with REST/Jetty?

Posted by Frank Wein <fr...@fau.de>.
Hi all,
some additional info/Java code: What I have currently working is some 
code without the ActiveMQ part:

restConfiguration().component("jetty").host("0.0.0.0").port(8080)
                 .dataFormatProperty("prettyPrint", "true")
                 .bindingMode(RestBindingMode.auto);

        rest("/API/").get("/object/{ID}/").to("direct:objectGet");

         from("direct:objectGet")
                  .setExchangePattern(ExchangePattern.InOut)
                  .setHeader(Exchange.HTTP_PATH, simple(
"/Webservice/RESTService/Object/${header.ID}"))
                  .setHeader(Exchange.HTTP_METHOD, simple("GET"))
.to("jetty://http://localhost:8888?bridgeEndpoint=true");

I send my REST request to localhost:8080/object/[ID]/ and get back the 
reply from the other webservice running on localhost:8888.

Now, I want to include an ActiveMQ queue here. Basically the ActiveMQ 
queue should be between the two routes (from/to("direct:objectGet")). 
The first route should send the message to the queue, the second route 
should fetch it, get the response from the other web service and send 
the response back via the queue to the first route. This one should then 
reply to the incoming REST request. Is this possible, if yes, how? My 
attempts at this did not really work.

Regards
Frank


Frank Wein wrote:
> Hi all,
> I have a problem setting up the correct Camel routes in Java for a 
> problem I'm having. I'm still quite new to Camel and ActiveMQ, so 
> please be patient with me :)
>
> What I want to accomplish is the following:
> * Provide a REST (HTTP GET) endpoint with Camel (Jetty) and send the 
> request (message) to an ActiveMQ queue (the ActiveMQ queue is a 
> requirement, probably would be easier without)
> * Consume the message (with a second route?), take some of the 
> parameters from the HTTP URL (so message properties) and send a 
> HTTP/REST request to another REST service.
> * Take the response from the other REST service and send it back to 
> the REST client (from the beginning)


-- 
Frank Wein
Forschungsgruppe Netz
Friedrich-Alexander-Universitaet Erlangen-Nuernberg
Regionales Rechenzentrum Erlangen (RRZE)
Martensstrasse 1, 91058 Erlangen, Germany
Tel. +49 9131/85-29983, Fax +49 9131/302941
frank.wein@fau.de
www.rrze.fau.de