如何解决如何使用Apache Camel将2个REST API的响应返回到第3个REST API
我是Apache Camel的新手,我想集成或合并2个API GET请求的结果并将其响应路由到第3个API。
第一个API-http:// localhost:8080 / students / Student1(GET方法返回{“ id”:“ 1”,“ name”:xyz“})
第二个API-http:// localhost:8081 / students / Student1(GET方法返回{“ id”:“ 1”,“ subject”:“ maths”})
第3个API-http:// localhost:8082 / students / combine(GET方法应产生
{“ id”:“ 1”,“主题”:“数学”,“名称”:“ xyz”}
我实际上要执行的操作是使用GET请求访问第三个API,以便它可以隐式调用API1和API2并以以下形式返回输出: {“ id”:“ 1”,“ subject”:“ maths”,“ name”:“ xyz”}
这是我编写的代码。
CamelContext context =新的DefaultCamelContext(); JacksonDataFormat jsonDataFormat =新的JacksonDataFormat(Output.class);
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("jetty:http://localhost:8080/students/Student1")
.to("direct:merge)
from("jetty:http://localhost:8081/students/Student1")
.to("direct:merge")
from("direct:merge")
.to("jetty:http://localhost:8082/students/combine")
}
});
context.start();
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。