gpt4 book ai didi

java - 在 spring boot 中使用现有的 http 服务器作为 Camel 端点

转载 作者:行者123 更新时间:2023-11-28 22:11:27 24 4
gpt4 key购买 nike

我有一个使用 spring boot starter web 的 spring boot 应用程序。这将创建一个正在运行的 Tomcat 实例并设置在端口上运行的 http 服务器。在我的 Camel route ,我想使用这个 http 服务器作为 http 请求的组件,但我不知道如何使用它。我看到很多配置 jetty 实例并从中使用的示例,但实际上我不会运行两个 http 服务器吗?我只想拥有一个。我假设 http 服务器已经自动连接,因为我可以使用其他 spring 代码(例如 RestController)使用它,并且我也可以在我的 spring 引导日志中看到它启动。

@Component
public class ExampleRoute extends RouteBuilder
{
@Override
public void configure() throws Exception
{

//@formatter:off

from( <want to take in an http request here> )
.log( LoggingLevel.INFO, log, "Hello World!" );

//@formatter:on

}
}

最佳答案

这里有一个例子:https://github.com/camelinaction/camelinaction2/tree/master/chapter7/springboot-camel

您可以注册一个 ServletRegistrationBean 来使用 Spring Boot 设置 Camel Servlet。

@Bean
ServletRegistrationBean camelServlet() {
// use a @Bean to register the Camel servlet which we need to do
// because we want to use the camel-servlet component for the Camel REST service
ServletRegistrationBean mapping = new ServletRegistrationBean();
mapping.setName("CamelServlet");
mapping.setLoadOnStartup(1);
// CamelHttpTransportServlet is the name of the Camel servlet to use
mapping.setServlet(new CamelHttpTransportServlet());
mapping.addUrlMappings("/camel/*");
return mapping;
}

然而,对于 Camel 2.19,我们计划让这更简单并且 OOTB:https://issues.apache.org/jira/browse/CAMEL-10416

然后你可以做

from("servlet:foo")
.to("bean:foo");

调用 Camel 路由的 HTTP url 将是 http:localhost:8080/camel/foo

关于java - 在 spring boot 中使用现有的 http 服务器作为 Camel 端点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40492458/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com