How can I invoke a RESTful service through Apache Camel?

前端 未结 4 1202
Happy的楠姐
Happy的楠姐 2020-12-31 12:41

I am currently using a HTTP method for invoking some URL which will create a JIRA issue.

Now I want to use Apache Camel, how can I use that?

I need to invoke

4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-31 13:05

    I am using apache camel jetty

    CamelContext context = new DefaultCamelContext();
        public void configure(){
               context.addRoutes(new RouteBuilder(){
               from("jetty:localhost:9000/offers")
               .to("direct:getOffers")
               .end();
    
        }
    
    });
    

    so here when the user will hit http://localhost:9000/offers then the endpoint direct:getOffers will get invoked

    so now defining the getOffers end point

    context.addRoutes(new RouteBuilder(){
         public void configure(){
              from("direct:getOffers")
              .to("jetty:http://localhost:9008/api/v2.0/offers?  
              bridgeEndpoint=true")
             .end();
    
         }
    
    });
    

    Here another service is running at 9008 having a rest resource of http://localhost:9008/api/v2.0/offers and this is the resource that i am trying to consume.

    so when camel instance starts it registers both the routes then it does the processing as described above

    Note Its important to add the option of ?bridgeEndpoint=true for this to work

提交回复
热议问题