docker中的rabbitmq的Spring Boot应用程序问题

我正在尝试使用rabbitmq构build一个由spring云stream驱动的事件驱动的微服务。 在我的情况下,rabbitmq正在docker中运行。

用于在容器下运行的Docker命令

docker run -d --hostname my-rabbit --name some-rabbit --publish 15672:15672 rabbitmq:3

然后去容器的bash模式,我在下面的命令中rabbitmq-plugins enable rabbitmq_managementrabbitmq-plugins enable rabbitmq_management以启动management-plugin

 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES b2bc315c44aa rabbitmq:3 "docker-entrypoint..." 7 minutes ago Up 7 minutes 4369/tcp, 5671-5672/tcp, 25672/tcp, 0.0.0.0:15672->15672/tcp some-rabbit 

所以我可以通过localhost:15672浏览器访问localhost:15672

但是当我启动Spring Boot应用程序时,它并没有进行排队和交换。 请检查堆栈跟踪。

堆栈跟踪

  osicodec.kryo.CompositeKryoRegistrar : configured Kryo registration [40, java.io.File] with serializer org.springframework.integration.codec.kryo.FileSerializer osjeaAnnotationMBeanExporter : Registering beans for JMX exposure on startup osjeaAnnotationMBeanExporter : Bean with name 'rabbitConnectionFactory' has been autodetected for JMX exposure osjeaAnnotationMBeanExporter : Bean with name 'integrationMbeanExporter' has been autodetected for JMX exposure osjeaAnnotationMBeanExporter : Located managed bean 'integrationMbeanExporter': registering with JMX server as MBean [org.springframework.integration.monitor:name=integrationMbeanExporter,type=IntegrationMBeanExporter] osjeaAnnotationMBeanExporter : Located managed bean 'rabbitConnectionFactory': registering with JMX server as MBean [org.springframework.amqp.rabbit.connection:name=rabbitConnectionFactory,type=CachingConnectionFactory] osimonitor.IntegrationMBeanExporter : Registering beans for JMX exposure on startup osimonitor.IntegrationMBeanExporter : Registering MessageChannel nullChannel osimonitor.IntegrationMBeanExporter : Located managed bean 'org.springframework.integration:type=MessageChannel,name=nullChannel': registering with JMX server as MBean [org.springframework.integration:type=MessageChannel,name=nullChannel] osimonitor.IntegrationMBeanExporter : Registering MessageChannel output osimonitor.IntegrationMBeanExporter : Located managed bean 'org.springframework.integration:type=MessageChannel,name=output': registering with JMX server as MBean [org.springframework.integration:type=MessageChannel,name=output] osimonitor.IntegrationMBeanExporter : Registering MessageChannel errorChannel osimonitor.IntegrationMBeanExporter : Located managed bean 'org.springframework.integration:type=MessageChannel,name=errorChannel': registering with JMX server as MBean [org.springframework.integration:type=MessageChannel,name=errorChannel] osimonitor.IntegrationMBeanExporter : Registering MessageHandler errorLogger osimonitor.IntegrationMBeanExporter : Located managed bean 'org.springframework.integration:type=MessageHandler,name=errorLogger,bean=internal': registering with JMX server as MBean [org.springframework.integration:type=MessageHandler,name=errorLogger,bean=internal] oscsupport.DefaultLifecycleProcessor : Starting beans in phase -2147482648 rtbdemo.source.GatewayApplication : No active profile set, falling back to default profiles: default scaAnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@56cfe111: startup date [Mon May 29 15:07:40 JST 2017]; parent: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@4fe767f3 oscsupport.GenericApplicationContext : Refreshing org.springframework.context.support.GenericApplicationContext@67de7a99: startup date [Mon May 29 15:07:40 JST 2017]; root of context hierarchy rtbdemo.source.GatewayApplication : Started GatewayApplication in 0.189 seconds (JVM running for 10.957) osamqp.rabbit.core.RabbitAdmin : Failed to declare exchange: Exchange [name=output, type=topic, durable=true, autoDelete=false, internal=false, arguments={}], continuing... org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused osintegration.channel.DirectChannel : Channel 'gateway:8181.output' has 1 subscriber(s). oscsupport.DefaultLifecycleProcessor : Starting beans in phase 0 osiendpoint.EventDrivenConsumer : Adding {logging-channel-adapter:_org.springframework.integration.errorLogger} as a subscriber to the 'errorChannel' channel osichannel.PublishSubscribeChannel : Channel 'gateway:8181.errorChannel' has 1 subscriber(s). osiendpoint.EventDrivenConsumer : started _org.springframework.integration.errorLogger oscsupport.DefaultLifecycleProcessor : Starting beans in phase 2147482647 oscsupport.DefaultLifecycleProcessor : Starting beans in phase 2147483647 sbcetTomcatEmbeddedServletContainer : Tomcat started on port(s): 8181 (http) 

提前致谢。

您需要使用具有pipe理插件的RabbitMQ的Docker镜像(请参阅https://hub.docker.com/_/rabbitmq/ ),在您的案例rabbitmq:3-management