2

I want to make a route that will be triggered from client request. For example I have a route http://localhost:8080/get where I have some json object. I want to create a route when I send a request to http://localhost:8080/get to send the data to ActiveMQ. Like event listener. I want to send to activeMq only when there is request to that URL. I have searched that I cant use http or http4 in from() and that makes me a problem. I have tried from timer to url and then to activemq, but that is not what I really need. This is what I have tried.

@GetMapping(value = "/shit")
public String getIt(@RequestParam(value = "url") String url, @RequestParam(value = "activemq") String activeMq) throws Exception {
CamelContext camelContext = new DefaultCamelContext();
RouteBuilder builder = new RouteBuilder() {
  public void configure() {
    from(url).convertBodyTo(String.class)
         .process(exchange -> {
          String body = exchange.getIn()
              .getBody()
              .toString();
          System.out.println("The body is: " + body);
        })
        .pollEnrich()
        .simple("activemq://" + activeMq);
  }
};
builder.addRoutesToCamelContext(camelContext);
camelContext.start();
return "";
}

And I want the route to be active untill I stop it.

xmlParser
  • 1,903
  • 4
  • 19
  • 48

1 Answers1

1

Yeah, camel-http4 is to produce only, it is not usable as a consumer because it is based an Apache HTTP client.

But you don't need special things like a timer or enricher. You can just use another Camel http-component that can act as a server. For example camel-jetty.

After a long discussion I finally realized that you would like to "branch off" requests within your other, already existing applications, i.e. you would like to send an incoming request, additionally to process them, to ActiveMQ.

Unfortunately you cannot do this from outside your applications because you do not know about incoming requests in other applications without modifying those other applications.

However, if you can modify your other applications so that they send their payloads to your new Camel application, the route would be quite simple:

from("jetty:http://localhost:[port]/yourApp")
    .to("activemq:queue:myQueueName")
burki
  • 6,741
  • 1
  • 15
  • 31
  • When the route is starting I am getting: Caused by: java.net.BindException: Cannot assign requested address: bind Error.... I have tried with endpoint from other machine and I get the same error: – xmlParser Apr 03 '19 at 14:00
  • Is port 8080 already used by something else? Are there more infos in a stacktrace or similar? – burki Apr 03 '19 at 14:14
  • Yeah its taken by the application that expose: http://localhost:8080/get ... I can access it... – xmlParser Apr 03 '19 at 14:19
  • Wait, another application has endpoint `localhost:8080/get` and you want your route listen on the same endpoint? Now I am confused. Can you try to explain this setup? They cannot listen on the same endpoint. – burki Apr 03 '19 at 14:42
  • Yeah... For example i have three applications with three endpoints. Every of them respond: Hello from Service One, Hello from Service Two and Hello from Service Three.... Now I want to do this. To send request with (URL) and (ACTIVEMQ) where url can be the endpoint of one of the services, and to watch it. If I send request to http://service-one:8080/get I want that message to be sent on the (ACTIVEMQ). Also when I send request with another url, another url will be created and when i access that url I want it content to be sent on the activeMq... Did you get it? – xmlParser Apr 03 '19 at 14:46
  • Let me try: you have whatever other applications (the Camel route you try to build is not part of them). Let's say they are available under `http://one:8080/` and `http://two:8080/`. Now you try to build another application (with a Camel route) that acts as a web service, takes a URL, for example `http://one:8080/`, calls this URL as a client and then "saves" the response of the HTTP call to ActiveMQ. Is this correct? – burki Apr 04 '19 at 13:32
  • I have rewritten my answer to the scenario I describe in the last comment. Hope I understood that correct. – burki Apr 04 '19 at 14:21
  • Well this is same as rest.. The point is not to call that app. The point is to create a route that will send every request from the (URL that I am sending as a request Param) to the activeMq. – xmlParser Apr 05 '19 at 08:34
  • Sorry, I still do not understand your goal. You send HTTP requests to your route. These requests have a URL of another App as request param. And you just want to send that URL to activemq? – burki Apr 05 '19 at 09:15
  • I just want to watch that URL for requests and If there is request on that URL,then to send the data from that request to the activeMq – xmlParser Apr 05 '19 at 09:48
  • 1
    But that sounds like you want to be **inside** an existing application and send every incoming request to ActiveMQ (beside processing the request normally). This is not possible from outside. – burki Apr 05 '19 at 11:27
  • Thank you. You can change the answer, and explain that my question does not have possible answer, and I will accept it. – xmlParser Apr 05 '19 at 11:30