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));
});
}
});