在spring boot中使用现有的http服务器作为camel端点 [英] Use existing http server in spring boot as camel endpoint

查看:1263
本文介绍了在spring boot中使用现有的http服务器作为camel端点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用spring boot starter web的spring boot应用程序。这将创建一个正在运行的Tomcat实例,并设置在端口上运行的http服务器。在我的骆驼路线中,我想使用这个http服务器作为http请求的组件,但我无法弄清楚如何利用它。我看到许多配置jetty实例并从中消耗的例子,但实际上我不会运行两个http服务器吗?我只想要一个。我假设http服务器已经自动装配,因为我可以使用其他弹簧代码(例如RestController)来使用它,我也可以看到它在我的spring启动日志中启动。

I have a spring boot application that uses the spring boot starter web. This creates a running Tomcat instance and sets up the http server running on a port. Within my camel route, I want to use this http server as the component for http requests, but I can't figure out how to utilize it. I see many many examples of configuring a jetty instance and consuming from it, but then wouldn't I in effect have two http servers running? I only want to have one. I assume the http server is already autowired up since I can consume from it with other spring code (such as a RestController) and I can see it started in my spring boot logs as well.

@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。

You can to register a ServletRegistrationBean that setup the Camel Servlet with Spring Boot.

@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

However for Camel 2.19 we plan on make this simpler and OOTB: https://issues.apache.org/jira/browse/CAMEL-10416

然后你可以从(servlet:foo)做

And then you can do

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

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

Where the HTTP url to call that Camel route will be http:localhost:8080/camel/foo

这篇关于在spring boot中使用现有的http服务器作为camel端点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆