【问题标题】:Spring Boot Application issue with rabbitmq in dockerdocker中rabbitmq的Spring Boot应用程序问题
【发布时间】:2017-05-29 01:29:15
【问题描述】:

我正在尝试使用rabbitmq 构建一个带有spring 云流的事件驱动微服务。在我的例子中,rabbitmq 在 docker 中运行。

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

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

然后进入容器的 bash 模式,我在下面的命令中触发: rabbitmq-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上从浏览器访问docker

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

堆栈跟踪

  o.s.i.codec.kryo.CompositeKryoRegistrar  : configured Kryo registration [40, java.io.File] with serializer org.springframework.integration.codec.kryo.FileSerializer
  o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
  o.s.j.e.a.AnnotationMBeanExporter        : Bean with name 'rabbitConnectionFactory' has been autodetected for JMX exposure
  o.s.j.e.a.AnnotationMBeanExporter        : Bean with name 'integrationMbeanExporter' has been autodetected for JMX exposure
  o.s.j.e.a.AnnotationMBeanExporter        : Located managed bean 'integrationMbeanExporter': registering with JMX server as MBean [org.springframework.integration.monitor:name=integrationMbeanExporter,type=IntegrationMBeanExporter]
  o.s.j.e.a.AnnotationMBeanExporter        : Located managed bean 'rabbitConnectionFactory': registering with JMX server as MBean [org.springframework.amqp.rabbit.connection:name=rabbitConnectionFactory,type=CachingConnectionFactory]
  o.s.i.monitor.IntegrationMBeanExporter   : Registering beans for JMX exposure on startup
  o.s.i.monitor.IntegrationMBeanExporter   : Registering MessageChannel nullChannel
  o.s.i.monitor.IntegrationMBeanExporter   : Located managed bean 'org.springframework.integration:type=MessageChannel,name=nullChannel': registering with JMX server as MBean [org.springframework.integration:type=MessageChannel,name=nullChannel]
  o.s.i.monitor.IntegrationMBeanExporter   : Registering MessageChannel output
  o.s.i.monitor.IntegrationMBeanExporter   : Located managed bean 'org.springframework.integration:type=MessageChannel,name=output': registering with JMX server as MBean [org.springframework.integration:type=MessageChannel,name=output]
  o.s.i.monitor.IntegrationMBeanExporter   : Registering MessageChannel errorChannel
  o.s.i.monitor.IntegrationMBeanExporter   : Located managed bean 'org.springframework.integration:type=MessageChannel,name=errorChannel': registering with JMX server as MBean [org.springframework.integration:type=MessageChannel,name=errorChannel]
  o.s.i.monitor.IntegrationMBeanExporter   : Registering MessageHandler errorLogger
  o.s.i.monitor.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]
  o.s.c.support.DefaultLifecycleProcessor  : Starting beans in phase -2147482648
  r.t.b.demo.source.GatewayApplication     : No active profile set, falling back to default profiles: default
  s.c.a.AnnotationConfigApplicationContext : 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
  o.s.c.support.GenericApplicationContext  : Refreshing org.springframework.context.support.GenericApplicationContext@67de7a99: startup date [Mon May 29 15:07:40 JST 2017]; root of context hierarchy
  r.t.b.demo.source.GatewayApplication     : Started GatewayApplication in 0.189 seconds (JVM running for 10.957)
  o.s.amqp.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
  o.s.integration.channel.DirectChannel    : Channel 'gateway:8181.output' has 1 subscriber(s).
  o.s.c.support.DefaultLifecycleProcessor  : Starting beans in phase 0
  o.s.i.endpoint.EventDrivenConsumer       : Adding {logging-channel-adapter:_org.springframework.integration.errorLogger} as a subscriber to the 'errorChannel' channel
  o.s.i.channel.PublishSubscribeChannel    : Channel 'gateway:8181.errorChannel' has 1 subscriber(s).
  o.s.i.endpoint.EventDrivenConsumer       : started _org.springframework.integration.errorLogger
  o.s.c.support.DefaultLifecycleProcessor  : Starting beans in phase 2147482647
  o.s.c.support.DefaultLifecycleProcessor  : Starting beans in phase 2147483647
  s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8181 (http)

提前致谢。

【问题讨论】:

  • 你如何从弹簧靴中指向兔子?什么主机名:端口?
  • 由于rabbitmq使用默认设置运行,所以我在spring boot application.yml中没有做特殊设置
  • 查看 docker 输出,我想说只有端口 15672 可以从外部访问。所有其他端口都没有暴露。你是如何启动容器的。此外,您不仅要添加模糊的消息,还要添加您拥有的完整堆栈跟踪/调试信息。
  • 谢谢,你能解释一下你是如何启动activemq容器的吗?
  • 你搞定了吗?

标签: spring docker spring-boot rabbitmq spring-cloud-stream


【解决方案1】:

您需要为具有管理插件的 RabbitMQ 使用 Docker 映像(请参阅https://hub.docker.com/_/rabbitmq/),在您的情况下为rabbitmq:3-management

【讨论】:

  • 感谢您的回复。但在上面的容器中,我使用rabbitmq-plugins enable rabbitmq_management 添加了插件。请检查问题的编辑版本。
【解决方案2】:

我一直在努力使用在 docker 中运行的 rabbit mq,我认为您需要在 spring boot application.properties 文件中输入一些条目来解决连接问题。

由于连接被拒绝,您的交换似乎没有被创建。你需要克服它。在 rabbit 网络管理控制台中,您需要创建一个具有权限的用户。然后在 application.properties 中添加一些配置:

spring.rabbitmq.port=5672
spring.rabbitmq.username=the_user_name
spring.rabbitmq.password=user_password

祝你好运。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-07
    • 2019-07-25
    • 2020-10-19
    • 2020-07-13
    • 1970-01-01
    • 2017-09-28
    • 2020-01-09
    • 2020-08-28
    相关资源
    最近更新 更多