如何使用Bluemix Liberty应用程序侦听自定义端口?

时间:2016-05-11 13:09:34

标签: ibm-cloud websphere-liberty

我有一个spring boot camel hello world应用程序,我想部署到Bluemix:

import org.apache.camel.spring.boot.*
import org.springframework.boot.*
import org.springframework.boot.autoconfigure.*
import org.springframework.context.*
import org.springframework.context.annotation.*
import org.springframework.scheduling.annotation.*

@Configuration
@ComponentScan
@EnableAutoConfiguration
@SpringBootApplication
class Application extends FatJarRouter {

    public static void main(String... args) {
        ApplicationContext applicationContext = new SpringApplication(Application.class).run(args);
        CamelSpringBootApplicationController applicationController =
                applicationContext.getBean(CamelSpringBootApplicationController.class);
        applicationController.run();
    }

    @Override
    public void configure() throws Exception {
        from("netty4-http:http://0.0.0.0:18080").
            setBody().simple("ref:helloWorld");
    }

    @Bean
    String helloWorld() {
        return "helloWorld";
    }
}

我也发布了我的build.gradle以防它有用:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.3.RELEASE")
    }
}
apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'spring-boot'
apply plugin: 'eclipse'

jar {
    baseName = 'EAI_Service'
    version =  '0.1.0'
}
repositories {
    mavenCentral()
}
dependencies {
    compile("org.codehaus.groovy:groovy-all:2.2.1")
    compile("org.springframework.boot:spring-boot-starter-web:1.2.3.RELEASE")

    compile("org.apache.camel:camel-core:2.17.0")
    compile("org.apache.camel:camel-spring-boot-starter:2.17.0")
    compile('org.apache.camel:camel-netty4-http:2.17.0')
}
task wrapper(type: Wrapper) {
   gradleVersion = '2.0'
}

在Bluemix日志文件中,我可以看到camel绑定到端口:

ServerBootstrap binding to 0.0.0.0:18080
Netty consumer bound to: 0.0.0.0:18080
Route: route1 started and consuming from: Endpoint[http://0.0.0.0:18080]
Total 1 routes, of which 1 are started.
Apache Camel 2.17.0 (CamelContext: camel-1) started in 0.590 seconds
Tomcat started on port(s): 61649 (http)
Started Application in 7.345 seconds (JVM running for 9.164)
Apache Camel 2.17.0 (CamelContext: camel-1) is starting
Total 1 routes, of which 1 are started.
 Apache Camel 2.17.0 (CamelContext: camel-1) started in 0.000 seconds

但是,当我尝试连接时,会返回“拒绝连接”消息。

snowch$ curl <<myapp>>.mybluemix.net:18080
curl: (7) Failed to connect to <myapp>>.mybluemix.net port 18080: Connection refused

在我的用例中,camel使用netty侦听端口18080.我看到{{3}}表示无法绑定到Bluemix Liberty应用程序上的自定义端口。是否有其他方法可以在不使用Docker或VM的情况下支持此用例?

1 个答案:

答案 0 :(得分:1)

Bluemix运行时实际上不允许使用自定义端口,唯一允许使用的是http / https,通过TCP使用80和443

IBM容器允许来自端口子集的自定义端口,无论如何都必须在docker文件上公开它们。

虚拟服务器测试版允许您使用自定义端口,您必须相应地在openstack上设置安全策略(或者只是打开所有端口,即使不是很安全)