0
votes

I'm looking for a sample code wich use the Camel RabbitMQ Request Response Pattern.

My use case : - A request message is depose in a RabbitMQ Queue - A Camel route consume the message, invoke an external Web Service, and reply the response based on the reply-to properties of the message

I also implement this use case using Spring AMQP but I want to do it with Camel RabbitMQ too.

Camel Documentation : http://camel.apache.org/rabbitmq.html

Thanks for your help.

Arnaud

2

2 Answers

1
votes

I found the solution :

The Camel RabbitMQ Reply-To functionnality will be in the next Camel Release 2.15.

Cf. https://issues.apache.org/jira/browse/CAMEL-7860

Arnaud

-1
votes

This is a simple example of HTTP proxy. HTTP request passes through Rabbit MQ, there HTTP response is returned to the Rabbit MQ.

Example written on camel 2.17.1 (camel-core, camel-netty4-http, camel-rabbitmq)

Sample call :

curl -H "proxy_url:http://remotehost:port/uri" 127.0.0.1

    context.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {

            from("netty4-http:localhost:80").
                    to("rabbitmq://localhost:5672/async");

            from("rabbitmq://localhost:5672/async").
                    process(exchange -> {

                        // for return not only 200 HTTP STATUS
                        String techParams = "throwExceptionOnFailure=false";
                        String proxyUrl = (String) exchange.getIn().getHeader("proxy_url");

                        proxyUrl = proxyUrl.contains("?") && proxyUrl.contains("=") 
                                ? proxyUrl + "&" + techParams : proxyUrl + "?" + techParams;
                        exchange.getIn().setHeader("proxy_url", proxyUrl);

                        exchange.setProperty(RabbitMQConstants.CORRELATIONID, 
                                exchange.getIn().getHeader(RabbitMQConstants.CORRELATIONID));

                    }).
                    toD("netty4-http:${header.proxy_url}").
                    process(exchange -> {
                        exchange.getIn().setHeader(RabbitMQConstants.CORRELATIONID, exchange.getProperty(RabbitMQConstants.CORRELATIONID));
                    });
        }

    });