在PCF中的Docker – 无法通过AMQP(spring cloud bus)连接到rabbitmq

我在玩Pivotal cloudfoundry和docker。 目前,我有一个春季启动应用程序,这是一个configuration服务器客户端连同spring的cloudbus。 如果我使用cf push demo-application target/my-jar-file.jar直接推送到PCF,这将cf push demo-application target/my-jar-file.jar

我现在正在尝试打包我的应用程序作为docker容器,并推入到PCF与cf push demo2 -o rraghur/demo 。 PCF创build一个容器并部署它 – 但spring的云端不起作用。 弹簧configuration确实工作,因为我在日志中看到以下内容

 2016-11-30T22:23:58.771+05:30 [APP/0] [OUT] 2016-11-30 16:53:58.770 INFO 12 --- [ main] cccConfigServicePropertySourceLocator : Fetching config from server at: https://config-67936b3e-1626-46b6-8117-480654f34e49.local.pcfdev.io 2016-11-30T22:24:00.588+05:30 [APP/0] [OUT] 2016-11-30 16:54:00.587 INFO 12 --- [ main] cccConfigServicePropertySourceLocator : Located environment: name=demo-application, profiles=[production], label=null, version=45c09f139492055b3a023462c852b82ae0d396a4, state=null 

但是,我的应用程序似乎无法连接到绑定的rabbitmq insntance – exception如下:

 2016-11-30T22:24:01.016+05:30 [APP/0] [OUT] at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.createConnection(CachingConnectionFactory.java:547) ~[spring-rabbit-1.6.5.RELEASE.jar!/:na] 2016-11-30T22:24:01.016+05:30 [APP/0] [OUT] at org.springframework.amqp.rabbit.core.RabbitTemplate.doExecute(RabbitTemplate.java:1389) ~[spring-rabbit-1.6.5.RELEASE.jar!/:na] 2016-11-30T22:24:01.016+05:30 [APP/0] [OUT] 2016-11-30 16:54:01.015 WARN 12 --- [ main] osamqp.rabbit.core.RabbitAdmin : Failed to declare exchange: Exchange [name=springCloudBus, type=topic, durable=true, autoDelete=false, internal=false, arguments={}], continuing... 2016-11-30T22:24:01.016+05:30 [APP/0] [OUT] org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused (Connection refused) 2016-11-30T22:24:01.016+05:30 [APP/0] [OUT] at org.springframework.amqp.rabbit.support.RabbitExceptionTranslator.convertRabbitAccessException(RabbitExceptionTranslator.java:62) ~[spring-rabbit-1.6.5.RELEASE.jar!/:na] 2016-11-30T22:24:01.016+05:30 [APP/0] [OUT] at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:306) ~[spring-rabbit-1.6.5.RELEASE.jar!/:na] 2016-11-30T22:24:01.016+05:30 [APP/0] [OUT] at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:1370) ~[spring-rabbit-1.6.5.RELEASE.jar!/:na] 2016-11-30T22:24:01.016+05:30 [APP/0] [OUT] at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:1346) ~[spring-rabbit-1.6.5.RELEASE.jar!/:na] 2016-11-30T22:24:01.016+05:30 [APP/0] [OUT] at org.springframework.amqp.rabbit.core.RabbitAdmin.declareExchange(RabbitAdmin.java:157) ~[spring-rabbit-1.6.5.RELEASE.jar!/:na] 2016-11-30T22:24:01.016+05:30 [APP/0] [OUT] at org.springframework.cloud.stream.binder.rabbit.RabbitMessageChannelBinder.declareExchange(RabbitMessageChannelBinder.java:457) [spring-cloud-stream-binder-rabbit-1.1.1.RELEASE.jar!/:1.1.1.RELEASE] 2016-11-30T22:24:01.016+05:30 [APP/0] [OUT] at org.springframework.cloud.stream.binder.rabbit.RabbitMessageChannelBinder.createProducerDestinationIfNecessary(RabbitMessageChannelBinder.java:336) [spring-cloud-stream-binder-rabbit-1.1.1.RELEASE.jar!/:1.1.1.RELEASE] 2016-11-30T22:24:01.016+05:30 [APP/0] [OUT] at org.springframework.cloud.stream.binder.rabbit.RabbitMessageChannelBinder.createProducerDestinationIfNecessary(RabbitMessageChannelBinder.java:85) [spring-cloud-stream-binder-rabbit-1.1.1.RELEASE.jar!/:1.1.1.RELEASE] 2016-11-30T22:24:01.016+05:30 [APP/0] [OUT] at org.springframework.cloud.stream.binder.AbstractMessageChannelBinder.doBindProducer(AbstractMessageChannelBinder.java:98) [spring-cloud-stream-1.1.0.RELEASE.jar!/:1.1.0.RELEASE] 2016-11-30T22:24:01.016+05:30 [APP/0] [OUT] at org.springframework.cloud.stream.binder.AbstractMessageChannelBinder.doBindProducer(AbstractMessageChannelBinder.java:53) [spring-cloud-stream-1.1.0.RELEASE.jar!/:1.1.0.RELEASE] 2016-11-30T22:24:01.016+05:30 [APP/0] [OUT] at org.springframework.cloud.stream.binder.AbstractBinder.bindProducer(AbstractBinder.java:148) [spring-cloud-stream-1.1.0.RELEASE.jar!/:1.1.0.RELEASE] 2016-11-30T22:24:01.016+05:30 [APP/0] [OUT] at org.springframework.cloud.stream.binding.ChannelBindingService.bindProducer(ChannelBindingService.java:113) [spring-cloud-stream-1.1.0.RELEASE.jar!/:1.1.0.RELEASE] 2016-11-30T22:24:01.016+05:30 [APP/0] [OUT] at org.springframework.cloud.stream.binding.BindableProxyFactory.bindOutputs(BindableProxyFactory.java:208) [spring-cloud-stream-1.1.0.RELEASE.jar!/:1.1.0.RELEASE] 2016-11-30T22:24:01.016+05:30 [APP/0] [OUT] at org.springframework.cloud.stream.binding.OutputBindingLifecycle.start(OutputBindingLifecycle.java:57) [spring-cloud-stream-1.1.0.RELEASE.jar!/:1.1.0.RELEASE] 2016-11-30T22:24:01.016+05:30 [APP/0] [OUT] at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:173) [spring-context-4.3.4.RELEASE.jar!/:4.3.4.RELEASE] 2016-11-30T22:24:01.016+05:30 [APP/0] [OUT] at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:51) [spring-context-4.3.4.RELEASE.jar!/:4.3.4.RELEASE] 2016-11-30T22:24:01.016+05:30 [APP/0] [OUT] at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:346) [spring-context-4.3.4.RELEASE.jar!/:4.3.4.RELEASE] 2016-11-30T22:24:01.016+05:30 [APP/0] [OUT] at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:149) [spring-context-4.3.4.RELEASE.jar!/:4.3.4.RELEASE] 2016-11-30T22:24:01.016+05:30 [APP/0] [OUT] at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:112) [spring-context-4.3.4.RELEASE.jar!/:4.3.4.RELEASE] 2016-11-30T22:24:01.016+05:30 [APP/0] [OUT] at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:879) [spring-context-4.3.4.RELEASE.jar!/:4.3.4.RELEASE] 2016-11-30T22:24:01.016+05:30 [APP/0] [OUT] at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:144) [spring-boot-1.4.2.RELEASE.jar!/:1.4.2.RELEASE] 2016-11-30T22:24:01.016+05:30 [APP/0] [OUT] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:545) [spring-context-4.3.4.RELEASE.jar!/:4.3.4.RELEASE] 2016-11-30T22:24:01.016+05:30 [APP/0] [OUT] at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) [spring-boot-1.4.2.RELEASE.jar!/:1.4.2.RELEASE] 2016-11-30T22:24:01.016+05:30 [APP/0] [OUT] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:761) [spring-boot-1.4.2.RELEASE.jar!/:1.4.2.RELEASE] 2016-11-30T22:24:01.016+05:30 [APP/0] [OUT] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:371) [spring-boot-1.4.2.RELEASE.jar!/:1.4.2.RELEASE] 2016-11-30T22:24:01.016+05:30 [APP/0] [OUT] at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-1.4.2.RELEASE.jar!/:1.4.2.RELEASE] 2016-11-30T22:24:01.016+05:30 [APP/0] [OUT] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1186) [spring-boot-1.4.2.RELEASE.jar!/:1.4.2.RELEASE] 2016-11-30T22:24:01.016+05:30 [APP/0] [OUT] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1175) [spring-boot-1.4.2.RELEASE.jar!/:1.4.2.RELEASE] 2016-11-30T22:24:01.016+05:30 [APP/0] [OUT] at com.example.DemoApplication.main(DemoApplication.java:24) [classes!/:0.0.1-SNAPSHOT] 2016-11-30T22:24:01.016+05:30 [APP/0] [OUT] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_111-internal] 2016-11-30T22:24:01.016+05:30 [APP/0] [OUT] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_111-internal] 2016-11-30T22:24:01.016+05:30 [APP/0] [OUT] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_111-internal] 2016-11-30T22:24:01.016+05:30 [APP/0] [OUT] at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_111-internal] 2016-11-30T22:24:01.016+05:30 [APP/0] [OUT] at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) [app.jar:0.0.1-SNAPSHOT] 2016-11-30T22:24:01.016+05:30 [APP/0] [OUT] at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) [app.jar:0.0.1-SNAPSHOT] 2016-11-30T22:24:01.016+05:30 [APP/0] [OUT] at org.springframework.boot.loader.Launcher.launch(Launcher.java:50) [app.jar:0.0.1-SNAPSHOT] 2016-11-30T22:24:01.016+05:30 [APP/0] [OUT] at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:58) [app.jar:0.0.1-SNAPSHOT] 2016-11-30T22:24:01.016+05:30 [APP/0] [OUT] Caused by: java.net.ConnectException: Connection refused (Connection refused) 2016-11-30T22:24:01.016+05:30 [APP/0] [OUT] at java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:1.8.0_111-internal] 2016-11-30T22:24:01.016+05:30 [APP/0] [OUT] at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) ~[na:1.8.0_111-internal] 2016-11-30T22:24:01.016+05:30 [APP/0] [OUT] at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) ~[na:1.8.0_111-internal] 2016-11-30T22:24:01.016+05:30 [APP/0] [OUT] at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) ~[na:1.8.0_111-internal] 2016-11-30T22:24:01.016+05:30 [APP/0] [OUT] at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[na:1.8.0_111-internal] 2016-11-30T22:24:01.016+05:30 [APP/0] [OUT] at java.net.Socket.connect(Socket.java:589) ~[na:1.8.0_111-internal] 2016-11-30T22:24:01.016+05:30 [APP/0] [OUT] at com.rabbitmq.client.impl.FrameHandlerFactory.create(FrameHandlerFactory.java:47) ~[amqp-client-3.6.5.jar!/:na] 2016-11-30T22:24:01.016+05:30 [APP/0] [OUT] at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:822) ~[amqp-client-3.6.5.jar!/:na] 2016-11-30T22:24:01.016+05:30 [APP/0] [OUT] at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:736) ~[amqp-client-3.6.5.jar!/:na] 2016-11-30T22:24:01.016+05:30 [APP/0] [OUT] at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:293) ~[spring-rabbit-1.6.5.RELEASE.jar!/:na] 2016-11-30T22:24:01.016+05:30 [APP/0] [OUT] ... 37 common frames omitted 2016-11-30T22:24:01.051+05:30 [APP/0] [OUT] 2016-11-30 16:54:01.051 INFO 12 --- [ main] osintegration.channel.DirectChannel : Channel 'demo-application:production:0.springCloudBusOutput' has 1 subscriber(s). 

考虑到所有的服务都是通过VCAP_SERVICES注入到PCF中的,我的想法是,无论应用程序是通过构build包还是Docker容器推送,服务的parsing/绑定都应该没有区别。此外, connection refused表示networking问题 -有什么关于docker的容器,在PCF中有不同的作用?

UPDATE

cf ssh了两个版本的cf ssh并安装了amqp-utils 。 然后在springCloudBus交换机上echo $VCAP_SERVICES然后是amqp-spy ,等待我rest。 仍然不知道为什么春季引导会抛出连接拒绝!

 root@2udd2sffmip:~# echo $VCAP_APPLICATION {"limits":{"fds":16384,"mem":256,"disk":512},"application_name":"new-openjdk8","application_uris":["new-openjdk8.local.pcfdev.io"],"name":"new-openjdk8","space_name":"dev","spac e_id":"87680353-58ca-4250-84d1-91d1955acee1","uris":["new-openjdk8.local.pcfdev.io"],"application_id":"9c1244b5-70a1-4275-8d0d-bf9b54958054","version":"9710aaf6-588f-41b8-964d-3 422c6fb525d","application_version":"9710aaf6-588f-41b8-964d-3422c6fb525d"} root@2udd2sffmip:~# echo $VCAP_SERVICES {"p-rabbitmq":[{ "credentials": { "http_api_uris": [ "https://13f80867-b5cb-4f36-a689-9c4215a79ef7:if4odk9jshcda7sn74vss8vlh0@rabbitmq-management.local.pcfdev.io/api/" ], "ssl": false, "dashboard_url": "https://rabbitmq-management.local.pcfdev.io/#/login/13f80867-b5cb-4f36-a689-9c4215a79ef7/if4odk9jshcda7sn74vss8vlh0", "password": "if4odk9jshcda7sn74vs s8vlh0", "protocols": { "management": { "path": "/api/", "ssl": false, "hosts": [ "rabbitmq.local.pcfdev.io" ], "password": "if4odk9jshcda7sn74vss8vlh0", "username": "13f80867-b 5cb-4f36-a689-9c4215a79ef7", "port": 15672, "host": "rabbitmq.local.pcfdev.io", "uri": "http://13f80867-b5cb-4f36-a689-9c4215a79ef7:if4odk9jshcda7sn74vss8vlh0@rabbitmq.local.pcf dev.io:15672/api/", "uris": [ "http://13f80867-b5cb-4f36-a689-9c4215a79ef7:if4odk9jshcda7sn74vss8vlh0@rabbitmq.local.pcfdev.io:15672/api/" ] }, "amqp": { "vhost": "2fb4345b-9268 -4865-8340-98e949067d8d", "username": "13f80867-b5cb-4f36-a689-9c4215a79ef7", "password": "if4odk9jshcda7sn74vss8vlh0", "port": 5672, "host": "rabbitmq.local.pcfdev.io", "hosts" : [ "rabbitmq.local.pcfdev.io" ], "ssl": false, "uri": "amqp://13f80867-b5cb-4f36-a689-9c4215a79ef7:if4odk9jshcda7sn74vss8vlh0@rabbitmq.local.pcfdev.io:5672/2fb4345b-9268-4865-8 340-98e949067d8d", "uris": [ "amqp://13f80867-b5cb-4f36-a689-9c4215a79ef7:if4odk9jshcda7sn74vss8vlh0@rabbitmq.local.pcfdev.io:5672/2fb4345b-9268-4865-8340-98e949067d8d" ] } }, " username": "13f80867-b5cb-4f36-a689-9c4215a79ef7", "hostname": "rabbitmq.local.pcfdev.io", "hostnames": [ "rabbitmq.local.pcfdev.io" ], "vhost": "2fb4345b-9268-4865-8340-98e9490 67d8d", "http_api_uri": "https://13f80867-b5cb-4f36-a689-9c4215a79ef7:if4odk9jshcda7sn74vss8vlh0@rabbitmq-management.local.pcfdev.io/api/", "uri": "amqp://13f80867-b5cb-4f36-a68 9-9c4215a79ef7:if4odk9jshcda7sn74vss8vlh0@rabbitmq.local.pcfdev.io/2fb4345b-9268-4865-8340-98e949067d8d", "uris": [ "amqp://13f80867-b5cb-4f36-a689-9c4215a79ef7:if4odk9jshcda7sn 74vss8vlh0@rabbitmq.local.pcfdev.io/2fb4345b-9268-4865-8340-98e949067d8d" ] }, "syslog_drain_url": null, "volume_mounts": [ ], "label": "p-rabbitmq", "provider": null, "plan": " standard", "name": "rabbitmq", "tags": [ "rabbitmq", "messaging", "message-queue", "amqp", "stomp", "mqtt", "pivotal" ] }],"p-config-server":[{ "credentials": { "uri": "https:// config-67936b3e-1626-46b6-8117-480654f34e49.local.pcfdev.io", "client_secret": "qSB9z4tI0Vix", "client_id": "p-config-server-f5c46df9-08f0-4779-bac1-3e2096a5efd6", "access_token _uri": "https://p-spring-cloud-services.uaa.local.pcfdev.io/oauth/token" }, "syslog_drain_url": null, "volume_mounts": [ ], "label": "p-config-server", "provider": null, "plan": "standard", "name": "config-server", "tags": [ "configuration", "spring-cloud" ] }]} root@2udd2sffmip:~# /usr/local/bin/amqp-spy -H rabbitmq.local.pcfdev.io -u 13f80867-b5cb-4f36-a689-9c4215a79ef7 --password if4odk9jshcda7sn74vss8vlh0 -V 2fb4345b-9268-4865-8340 -98e949067d8d springCloudBus ^Ccan't be called from trap context 

@Raghu从你已经发布的日志看来,似乎活动configuration文件似乎没有包含“云”,这是重新configuration和绑定你的应用程序到rabbitmq服务的关键。