如何将请求数据从spring引导控制器传递到apachecamel路由
用例:在我的应用程序中有一个REST控制器,在Spring boot的帮助下开发,我的要求是,我必须将请求数据从控制器传递到路由,从路由再次需要将数据传递到MQ 在这里,我如何将inputReq数据从控制器传递到路由?谁能帮忙吗如何将请求数据从spring引导控制器传递到apachecamel路由,spring,spring-boot,apache-camel,Spring,Spring Boot,Apache Camel,用例:在我的应用程序中有一个REST控制器,在Spring boot的帮助下开发,我的要求是,我必须将请求数据从控制器传递到路由,从路由再次需要将数据传递到MQ 在这里,我如何将inputReq数据从控制器传递到路由?谁能帮忙吗 @Controller public class RequestController { @PostMapping("/request") public String requestMapping(@RequestBody Stri
@Controller
public class RequestController {
@PostMapping("/request")
public String requestMapping(@RequestBody String inputReq) {
new ProduceRouter(); // instance of the apache camel route
return null;
}
}
下面是一条apache camel路线:
@Component
public class ProduceRouter extends RouteBuilder {
@Override
public void configure() throws Exception {
.from("jms:RequestQueue?disableReplyTo=true")
.log("Received Body is ${body} and header info is ${headers} ");
}
}
在控制器中,自动连接CamelContext和ProducerTemplate的实例
@Autowired
private CamelContext camelContext;
@Autowired
private ProducerTemplate producer;
然后,您需要使用ExchangeBuilder创建一个exchange请求,并添加请求正文
Exchange exchangeRequest = ExchangeBuilder.anExchange(camelContext)
.withBody(inputReq).build();
然后,您可以调用producer对象上的send方法来点击路由并捕获响应
Exchange exchangeResponse = producer.send("direct:startRoute", exchangeRequest).
然后在路由文件中,您可以从
direct:startRoute
消费producer对象是预定义的吗?你能推荐一些关于spring boot和apache camel的资料/书籍吗?谢谢你的回复,你能推荐一些关于apache camel和spring boot的资料/书籍吗?我在开发过程中遇到了很多问题。不,制作人也需要自动连线。我会修正我的答案。没有特定于spring引导的资源。骆驼网站在这方面相当全面!