Spring Boot Apache Camel应用程序在容器中时无法处理请求

时间:2018-12-13 07:02:13

标签: spring-boot apache-camel spring-camel camel-cxf

我有一个Spring Boot + Apache Camel应用程序,在POM文件中列出了以下依赖项,如下所示。

<properties>
    <fuse-version>fuse-000112-redhat-3</fuse-version>
    <camel-version>2.21.0.${fuse-version}</camel-version>
    <cxf-version>3.2.7</cxf-version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <version>2.0.5.RELEASE</version>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
            </exclusion>
        </exclusions>
    </dependency>



    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-core</artifactId>
        <version>${camel-version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-spring</artifactId>
        <version>${camel-version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-cxf</artifactId>
        <version>${camel-version}</version>
    </dependency>

    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-shiro</artifactId>
        <version>${camel-version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-jms</artifactId>
        <version>${camel-version}</version>
    </dependency>

    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-transports-http-jetty</artifactId>
        <version>${cxf-version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-frontend-jaxrs</artifactId>
        <version>${cxf-version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-rs-extension-providers</artifactId>
        <version>${cxf-version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-rs-security-cors</artifactId>
        <version>${cxf-version}</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.jaxrs</groupId>
        <artifactId>jackson-jaxrs-json-provider</artifactId>
        <version>${jackson2.version}</version>
    </dependency>


    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-autoconfigure</artifactId>
        <version>2.0.5.RELEASE</version>
    </dependency>
</dependencies>

在 现在,我在camel-context.xml

中定义了以下路由
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:camel="http://camel.apache.org/schema/spring"
       xmlns:ctx="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd




       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">



    <camelContext trace="false" id="paymentRestCC" allowUseOriginalMessage="true"
                  xmlns="http://camel.apache.org/schema/spring">

        <propertyPlaceholder id="properties"
                             location="classpath:application.properties"/>

        <threadPoolProfile id="bigPool" defaultProfile="true"
                           poolSize="10" maxPoolSize="{{rest.thread.max.pool.size}}"
                           maxQueueSize="{{rest.thread.max.queue.size}}" allowCoreThreadTimeOut="false"
                           rejectedPolicy="CallerRuns"/>

        <route id="RESTPaymentRoute">
            <from
                    uri="cxfrs:bean:restPaymentService?resourceClass=com.interswitchng.techquest.payment.service.rest.consumer.resources.PaymentRestRequestResource&amp;continuationTimeout={{continuation.timeout}}"/>
            <bean ref="restUtil" method="setRequestStartTime"/>
            <threads executorServiceRef="bigPool" callerRunsWhenRejected="true">
                <bean ref="restUtil" method="printRequestTimeInQueue"/>
                <bean ref="restUtil" method="getGenerateTransIdStartTime"/>
                <to uri="bean-tranIdGenerator-async://tranIdGeneratorEndpoint"/>
                <bean ref="restUtil" method="printGenerateTransIdEndTime"/>
                <!-- <throttle> -->
                <!-- <constant>40</constant> -->
                <to uri="direct-vm:paymentV1Rest"/>
                <!-- </throttle> -->
            </threads>
        </route>
</beans>

我用以下代码启动应用程序

@SpringBootApplication
@EnableAutoConfiguration()
public class PaymentServiceRestApplication {
    private static ClassPathXmlApplicationContext applicationContext;

    public static void main(final String[] args) throws Exception {
        applicationContext = new ClassPathXmlApplicationContext("camel-context.xml");
        applicationContext.start();
        SpringContextHolder.setStaticApplicationContext(applicationContext);
        ((LoggerContext) LoggerFactory.getILoggerFactory()).getLogger("org.mongodb.driver").setLevel(Level.ERROR);
    }
}

该应用程序正常启动,并且可以正常处理请求。现在,当我使用docker打包此应用程序时,就会出现问题。我的docker文件如下

FROM java:8

LABEL maintainer="babajide.apata@interswitchgroup.com"

ENV http_proxy 'http://x.x.x.x:6060/'
ENV https_proxy 'http://x.x.x.x:6060/'
ENV NO_PROXY 'localhost,127.0.0.1,0.0.0.0,192.168.10.0/24,example.com'

RUN apt-get update && apt-get install -y \
    telnet

#Change OS time zone
RUN mv -f /etc/localtime /etc/localtime.bak
RUN ln -s /usr/share/zoneinfo/Africa/Lagos /etc/localtime

ADD payment-service-rest/target/service.jar.jar /opt/p-rest/service.jar

WORKDIR /opt/p-rest

EXPOSE 19080

CMD cat /etc/hosts; java -jar payment-service-rest-4.x.team5-dev.jar;

容器正常启动,但是当我尝试从容器外部通过暴露的端口访问服务时,令人惊讶的是,从日志中我可以看到请求不再到达应用程序。我可以使用暴露的端口成功地将主机从telnet到容器中,但是请求并没有完全到达应用程序。

0 个答案:

没有答案