[英]Connection Refused to Rabbitmq container from Spring boot app Container
I'm facing an error to connect from my spring boot app container to Rabbitmq.我在从我的 spring 启动应用程序容器连接到 Rabbitmq 时遇到错误。
I have attached the two docker containers ( Rabbitmq and spring boot app) with bridge.network in my docker compose file:我在我的 docker 撰写文件中附加了两个 docker 容器( Rabbitmq和spring 启动应用程序)和 bridge.network:
version: '3.3'
services:
rabbitmq:
image: rabbitmq:3.8-management-alpine
container_name: rabbitmq
ports:
- 5673:5673
- 5672:5672
- 15672:15672
networks:
- orchestrator-rabbitmq
environment:
- RABBITMQ_DEFAULT_USER=adminsi
- RABBITMQ_DEFAULT_PASS=test
orchestrator:
restart: on-failure
build:
context: .
dockerfile: Dockerfile-orchestrator
args:
VERSION: ${VERSION}
environment:
- spring_rabbitmq_host=rabbitmq
- spring_rabbitmq_port=5672
- spring_rabbitmq_username=adminsi
- spring_rabbitmq_password=test
container_name: orchestrator
depends_on:
- rabbitmq
networks:
- orchestrator-rabbitmq
ports:
- 7127:7127
networks:
orchestrator-rabbitmq:
external:
name: orchestrator-rabbitmq
the connection is refused by Rabbitmq when my Spring boot app attempts to connect to this latter.当我的 Spring 引导应用程序尝试连接到后者时,连接被 Rabbitmq 拒绝。 Below the log:
日志下方:
11:35:22.176 [main] WARN oac.c.rabbitmq.RabbitMQProducer - Failed to create connection.
11:35:22.176 [main] WARN oac.c.rabbitmq.RabbitMQProducer - 无法创建连接。 It will attempt to connect again when publishing a message.
它会在发布消息时尝试再次连接。 orchestrator |
配器| java.net.ConnectException: Connection refused orchestrator |
java.net.ConnectException:连接被拒绝at java.base/sun.nio.ch.Net.pollConnect(Native Method) orchestrator |
在 java.base/sun.nio.ch.Net.pollConnect(Native Method) orchestrator | at java.base/sun.nio.ch.Net.pollConnectNow(Net.java:672) orchestrator |
在 java.base/sun.nio.ch.Net.pollConnectNow(Net.java:672) 协调器 | at java.base/sun.nio.ch.NioSocketImpl.timedFinishConnect(NioSocketImpl.java:542) orchestrator |
在 java.base/sun.nio.ch.NioSocketImpl.timedFinishConnect(NioSocketImpl.java:542) 协调器 | at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:597) orchestrator |
在 java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:597) 协调器 | at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:327) orchestrator |
在 java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:327) 协调器 | at java.base/java.net.Socket.connect(Socket.java:633) orchestrator |
在 java.base/java.net.Socket.connect(Socket.java:633) orchestrator |
at com.rabbitmq.client.impl.SocketFrameHandlerFactory.create(SocketFrameHandlerFactory.java:60) orchestrator |在 com.rabbitmq.client.impl.SocketFrameHandlerFactory.create(SocketFrameHandlerFactory.java:60) orchestrator | at com.rabbitmq.client.impl.recovery.RecoveryAwareAMQConnectionFactory.newConnection(RecoveryAwareAMQConnectionFactory.java:62) orchestrator |
在 com.rabbitmq.client.impl.recovery.RecoveryAwareAMQConnectionFactory.newConnection(RecoveryAwareAMQConnectionFactory.java:62) orchestrator | at com.rabbitmq.client.impl.recovery.AutorecoveringConnection.init(AutorecoveringConnection.java:156) orchestrator |
在 com.rabbitmq.client.impl.recovery.AutorecoveringConnection.init(AutorecoveringConnection.java:156) orchestrator | at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:1213) orchestrator |
在 com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:1213) orchestrator | at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:1170) orchestrator |
在 com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:1170) orchestrator | at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:1128) orchestrator |
在 com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:1128) orchestrator | at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:1321) orchestrator |
在 com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:1321) orchestrator | at org.apache.camel.component.rabbitmq.RabbitMQEndpoint.connect(RabbitMQEndpoint.java:247) orchestrator |
在 org.apache.camel.component.rabbitmq.RabbitMQEndpoint.connect(RabbitMQEndpoint.java:247) 协调器 | at org.apache.camel.component.rabbitmq.RabbitMQProducer.openConnectionAndChannelPool(RabbitMQProducer.java:108) orchestrator |
在 org.apache.camel.component.rabbitmq.RabbitMQProducer.openConnectionAndChannelPool(RabbitMQProducer.java:108) 协调器 | at org.apache.camel.component.rabbitmq.RabbitMQProducer.doStart(RabbitMQProducer.java:163) orchestrator |
在 org.apache.camel.component.rabbitmq.RabbitMQProducer.doStart(RabbitMQProducer.java:163) 协调器 | at org.apache.camel.support.service.BaseService.start(BaseService.java:119) orchestrator |
在 org.apache.camel.support.service.BaseService.start(BaseService.java:119) orchestrator | at org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:113) orchestrator |
在 org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:113) orchestrator | at org.apache.camel.impl.engine.AbstractCamelContext.internalAddService(AbstractCamelContext.java:1554) orchestrator |
在 org.apache.camel.impl.engine.AbstractCamelContext.internalAddService(AbstractCamelContext.java:1554) 协调器 | at org.apache.camel.impl.engine.AbstractCamelContext.addService(AbstractCamelContext.java:1475) orchestrator |
在 org.apache.camel.impl.engine.AbstractCamelContext.addService(AbstractCamelContext.java:1475) 协调器 | at org.apache.camel.processor.SendProcessor.doStart(SendProcessor.java:247) orchestrator |
在 org.apache.camel.processor.SendProcessor.doStart(SendProcessor.java:247) 协调器 | at org.apache.camel.support.service.BaseService.start(BaseService.java:119) orchestrator |
在 org.apache.camel.support.service.BaseService.start(BaseService.java:119) orchestrator | at org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:113) orchestrator |
在 org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:113) orchestrator | at org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:130) orchestrator |
在 org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:130) 协调器 | at org.apache.camel.processor.errorhandler.RedeliveryErrorHandler.doStart(RedeliveryErrorHandler.java:1655) orchestrator |
在 org.apache.camel.processor.errorhandler.RedeliveryErrorHandler.doStart(RedeliveryErrorHandler.java:1655) orchestrator | at org.apache.camel.support.ChildServiceSupport.start(ChildServiceSupport.java:60) orchestrator |
在 org.apache.camel.support.ChildServiceSupport.start(ChildServiceSupport.java:60) 协调器 | at org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:113) orchestrator |
在 org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:113) orchestrator | at org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:130) orchestrator |
在 org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:130) 协调器 | at org.apache.camel.impl.engine.DefaultChannel.doStart(DefaultChannel.java:126) orchestrator |
在 org.apache.camel.impl.engine.DefaultChannel.doStart(DefaultChannel.java:126) 协调器 | at org.apache.camel.support.service.BaseService.start(BaseService.java:119) orchestrator |
在 org.apache.camel.support.service.BaseService.start(BaseService.java:119) orchestrator | at org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:113) orchestrator |
在 org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:113) orchestrator | at org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:116) orchestrator |
在 org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:116) 协调器 | at org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:130) orchestrator |
在 org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:130) 协调器 | at org.apache.camel.processor.Pipeline.doStart(Pipeline.java:221) orchestrator |
在 org.apache.camel.processor.Pipeline.doStart(Pipeline.java:221)协调器 | at org.apache.camel.support.service.BaseService.start(BaseService.java:119) orchestrator |
在 org.apache.camel.support.service.BaseService.start(BaseService.java:119) orchestrator | at org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:113) orchestrator |
在 org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:113) orchestrator | at org.apache.camel.support.processor.DelegateAsyncProcessor.doStart(DelegateAsyncProcessor.java:89) orchestrator |
在 org.apache.camel.support.processor.DelegateAsyncProcessor.doStart(DelegateAsyncProcessor.java:89)协调器 | at org.apache.camel.processor.FilterProcessor.doStart(FilterProcessor.java:138) orchestrator |
在 org.apache.camel.processor.FilterProcessor.doStart(FilterProcessor.java:138)协调器 | at org.apache.camel.support.service.BaseService.start(BaseService.java:119) orchestrator |
在 org.apache.camel.support.service.BaseService.start(BaseService.java:119) orchestrator | at org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:113) orchestrator |
在 org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:113) orchestrator | at org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:116) orchestrator |
在 org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:116) 协调器 | at org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:130) orchestrator |
在 org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:130) 协调器 | at org.apache.camel.processor.ChoiceProcessor.doStart(ChoiceProcessor.java:185) orchestrator |
在 org.apache.camel.processor.ChoiceProcessor.doStart(ChoiceProcessor.java:185)协调器 | at org.apache.camel.support.service.BaseService.start(BaseService.java:119) orchestrator |
在 org.apache.camel.support.service.BaseService.start(BaseService.java:119) orchestrator | at org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:113) orchestrator |
在 org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:113) orchestrator | at org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:130) orchestrator |
在 org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:130) 协调器 | at org.apache.camel.processor.errorhandler.RedeliveryErrorHandler.doStart(RedeliveryErrorHandler.java:1655) orchestrator |
在 org.apache.camel.processor.errorhandler.RedeliveryErrorHandler.doStart(RedeliveryErrorHandler.java:1655) orchestrator | at org.apache.camel.support.ChildServiceSupport.start(ChildServiceSupport.java:60) orchestrator |
在 org.apache.camel.support.ChildServiceSupport.start(ChildServiceSupport.java:60) 协调器 | at org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:113) orchestrator |
在 org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:113) orchestrator | at org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:130) orchestrator |
在 org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:130) 协调器 | at org.apache.camel.impl.engine.DefaultChannel.doStart(DefaultChannel.java:126) orchestrator |
在 org.apache.camel.impl.engine.DefaultChannel.doStart(DefaultChannel.java:126) 协调器 | at org.apache.camel.support.service.BaseService.start(BaseService.java:119) orchestrator |
在 org.apache.camel.support.service.BaseService.start(BaseService.java:119) orchestrator | at org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:113) orchestrator |
在 org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:113) orchestrator | at org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:116) orchestrator |
在 org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:116) 协调器 | at org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:130) orchestrator |
在 org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:130) 协调器 | at org.apache.camel.processor.Pipeline.doStart(Pipeline.java:221) orchestrator |
在 org.apache.camel.processor.Pipeline.doStart(Pipeline.java:221)协调器 | at org.apache.camel.support.service.BaseService.start(BaseService.java:119) orchestrator |
在 org.apache.camel.support.service.BaseService.start(BaseService.java:119) orchestrator | at org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:113) orchestrator |
在 org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:113) orchestrator | at org.apache.camel.support.processor.DelegateAsyncProcessor.doStart(DelegateAsyncProcessor.java:89) orchestrator |
在 org.apache.camel.support.processor.DelegateAsyncProcessor.doStart(DelegateAsyncProcessor.java:89)协调器 | at org.apache.camel.support.service.BaseService.start(BaseService.java:119) orchestrator |
在 org.apache.camel.support.service.BaseService.start(BaseService.java:119) orchestrator | at org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:113) orchestrator |
在 org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:113) orchestrator | at org.apache.camel.impl.engine.RouteService.startChildServices(RouteService.java:396) orchestrator |
在 org.apache.camel.impl.engine.RouteService.startChildServices(RouteService.java:396) 协调器 | at org.apache.camel.impl.engine.RouteService.doWarmUp(RouteService.java:193) orchestrator |
在 org.apache.camel.impl.engine.RouteService.doWarmUp(RouteService.java:193) 协调器 | at org.apache.camel.impl.engine.RouteService.warmUp(RouteService.java:121) orchestrator |
在 org.apache.camel.impl.engine.RouteService.warmUp(RouteService.java:121) 协调器 | at org.apache.camel.impl.engine.InternalRouteStartupManager.doWarmUpRoutes(InternalRouteStartupManager.java:306) orchestrator |
在 org.apache.camel.impl.engine.InternalRouteStartupManager.doWarmUpRoutes(InternalRouteStartupManager.java:306) 协调器 | at org.apache.camel.impl.engine.InternalRouteStartupManager.safelyStartRouteServices(InternalRouteStartupManager.java:189) orchestrator |
在 org.apache.camel.impl.engine.InternalRouteStartupManager.safelyStartRouteServices(InternalRouteStartupManager.java:189) 协调器 | at org.apache.camel.impl.engine.InternalRouteStartupManager.doStartOrResumeRoutes(InternalRouteStartupManager.java:147) orchestrator |
在 org.apache.camel.impl.engine.InternalRouteStartupManager.doStartOrResumeRoutes(InternalRouteStartupManager.java:147) 协调器 | at org.apache.camel.impl.engine.AbstractCamelContext.doStartCamel(AbstractCamelContext.java:3300) orchestrator |
在 org.apache.camel.impl.engine.AbstractCamelContext.doStartCamel(AbstractCamelContext.java:3300) 协调器 | at org.apache.camel.impl.engine.AbstractCamelContext.doStartContext(AbstractCamelContext.java:2952) orchestrator |
在 org.apache.camel.impl.engine.AbstractCamelContext.doStartContext(AbstractCamelContext.java:2952) 协调器 | at org.apache.camel.impl.engine.AbstractCamelContext.doStart(AbstractCamelContext.java:2903) orchestrator |
在 org.apache.camel.impl.engine.AbstractCamelContext.doStart(AbstractCamelContext.java:2903) 协调器 | at org.apache.camel.spring.boot.SpringBootCamelContext.doStart(SpringBootCamelContext.java:43) orchestrator |
在 org.apache.camel.spring.boot.SpringBootCamelContext.doStart(SpringBootCamelContext.java:43) 协调器 | at org.apache.camel.support.service.BaseService.start(BaseService.java:119) orchestrator |
在 org.apache.camel.support.service.BaseService.start(BaseService.java:119) orchestrator | at org.apache.camel.impl.engine.AbstractCamelContext.start(AbstractCamelContext.java:2587) orchestrator |
在 org.apache.camel.impl.engine.AbstractCamelContext.start(AbstractCamelContext.java:2587) 协调器 | at org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:247) orchestrator |
在 org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:247) orchestrator | at org.apache.camel.spring.SpringCamelContext.start(SpringCamelContext.java:119) orchestrator |
在 org.apache.camel.spring.SpringCamelContext.start(SpringCamelContext.java:119) 协调器 | at org.apache.camel.spring.SpringCamelContext.onApplicationEvent(SpringCamelContext.java:151) orchestrator |
在 org.apache.camel.spring.SpringCamelContext.onApplicationEvent(SpringCamelContext.java:151) 协调器 | at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176) orchestrator |
在 org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176) 协调器 | at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169) orchestrator |
在 org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169) 协调器 | at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143) orchestrator |
在 org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143) 协调器 | at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:421) orchestrator |
在 org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:421) 协调器 | at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:378) orchestrator |
在 org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:378) 协调器 | at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:938) orchestrator |
在 org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:938) 协调器 | at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:586) orchestrator |
在 org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:586) 协调器 | at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) orchestrator |
在 org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) 协调器 | at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:732) orchestrator |
在 org.springframework.boot.SpringApplication.refresh(SpringApplication.java:732) 协调器 | at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:414) orchestrator |
在 org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:414) 协调器 | at org.springframework.boot.SpringApplication.run(SpringApplication.java:302) orchestrator |
在 org.springframework.boot.SpringApplication.run(SpringApplication.java:302) orchestrator | at org.springframework.boot.SpringApplication.run(SpringApplication.java:1303) orchestrator |
在 org.springframework.boot.SpringApplication.run(SpringApplication.java:1303) 协调器 | at org.springframework.boot.SpringApplication.run(SpringApplication.java:1292) orchestrator |
在 org.springframework.boot.SpringApplication.run(SpringApplication.java:1292) 协调器 | at fr.orange.oab.sie.service.orchestrator.OrchestratorApplication.main(OrchestratorApplication.java:31) orchestrator |
在 fr.orange.oab.sie.service.orchestrator.OrchestratorApplication.main(OrchestratorApplication.java:31) 协调器 | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) orchestrator |
在 java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) orchestrator | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) orchestrator |
在 java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) 协调器 | at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) orchestrator |
在 java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) orchestrator | at java.base/java.lang.reflect.Method.invoke(Method.java:568) orchestrator |
在 java.base/java.lang.reflect.Method.invoke(Method.java:568) orchestrator | at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49) orchestrator |
在 org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49) 协调器 | at org.springframework.boot.loader.Launcher.launch(Launcher.java:108) orchestrator |
在 org.springframework.boot.loader.Launcher.launch(Launcher.java:108) orchestrator | at org.springframework.boot.loader.Launcher.launch(Launcher.java:58) orchestrator |
在 org.springframework.boot.loader.Launcher.launch(Launcher.java:58) orchestrator | at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88)
在 org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88)
When I execute the below command inside my spring boot app container (orchestrator in my case) I get the following response:当我在我的 spring 启动应用程序容器(在我的例子中是协调器)中执行以下命令时,我得到以下响应:
nc -vz rabbitmq 5672
The response is:响应是:
Connection to rabbitmq (172.19.0.2) 5672 port [tcp/*] succeeded!
连接rabbitmq(172.19.0.2)5672端口[tcp/*]成功!
So the tcp connection is succeeded between the two containers, but when I curl to rabbitmq inside my orchestrator container with the credentials that are defined in the above docker compose file, I get the connection refused:因此,两个容器之间的 tcp 连接成功,但是当我使用上述 docker 撰写文件中定义的凭据在我的orchestrator 容器中将 curl 连接到 rabbitmq 时,连接被拒绝:
curl -u "adminsi:test" http://localhost:15672
But when I change localhost with rabbitmq as a host like below:但是当我将本地主机更改为 rabbitmq 作为主机时,如下所示:
curl -u "adminsi:test" http://rabbitmq:15672
The response is succeeded !响应成功!
Below my properties config in spring boot app ( orchestrator ):在 spring 启动应用程序 ( orchestrator ) 中我的属性配置下面:
spring.rabbitmq.host=rabbitmq
spring.rabbitmq.port=5672
spring.rabbitmq.username=adminsi
spring.rabbitmq.password=test
I'm using apache camel to publish messages in rabbitmq (below an example of camel route that read from an API and publish the response in rabbitmq topic):我正在使用 apache camel 在 rabbitmq 中发布消息(下面是从 API 读取并在 rabbitmq 主题中发布响应的 camel 路由示例):
from("direct:OrchestratorDtstoreLoadDataRoute")
.routeId("orchestrator-dtstore-route")
.log(LoggingLevel.INFO, "Reading dtstore projects")
.removeHeaders("*")
.setHeader("Content-Type", () -> "application/json")
.setHeader("CamelHttpMethod", () -> "GET")
.setHeader("Authorization", () -> dtstoreToken)
.setHeader("x-apikey", () -> dtstoreXapiKey)
.recipientList(simple("cxfrs:{{cmdb.service.out.dtstore.url}}/projects"))
.log(LoggingLevel.DEBUG, "dtstore projects : ${body}")
.to(ExchangePattern.InOnly, "rabbitmq:q.cmdb.dtstore.projects?routingKey=dtstore&autoDelete=false&exchangeType=topic")
.end();
The Orchestrator Dockerfile:协调员 Dockerfile:
FROM openjdk:17.0.2-jdk-slim
ARG VERSION
ENV ORCHESTRATOR_VERSION=$VERSION
RUN apt-get update && apt-get install -y \
nano \
netcat \
iputils-ping \
curl \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /opt/app
COPY target/orchestrator-$ORCHESTRATOR_VERSION.jar .
EXPOSE 7127
ENTRYPOINT java -jar orchestrator-$ORCHESTRATOR_VERSION.jar
I run mvn clean package before running the docker-compose file.在运行 docker-compose 文件之前,我运行了 mvn clean package。
Thanks a lot for your help.非常感谢你的帮助。
At the end of the journey, I have found the solution, and yes after modifying the spring properties to these below new properties:在旅程结束时,我找到了解决方案,是的,在将 spring 属性修改为以下这些新属性之后:
camel.component.rabbitmq.hostname=localhost
camel.component.rabbitmq.port=5672
camel.component.rabbitmq.username=adminsi
camel.component.rabbitmq.password=test
In this manner, we can tell camel which is bounded to rabbitmq about the host, port, username, and password, before just rabbitmq knows these properties, as a result, camel cannot resolve the rabbitmq's host.通过这种方式,我们可以告诉绑定到 rabbitmq 的 camel 主机、端口、用户名和密码,而只有 rabbitmq 知道这些属性,因此 camel 无法解析 rabbitmq 的主机。
Then I changed the docker-compose environment for the orchestrator container:然后我为 orchestrator 容器更改了 docker-compose 环境:
version: '3.3'
services:
rabbitmq:
image: rabbitmq:3.8-management
container_name: rabbitmq
ports:
- 5673:5673
- 5672:5672
- 15672:15672
networks:
- orchestrator-rabbitmq
environment:
- RABBITMQ_DEFAULT_USER=adminsi
- RABBITMQ_DEFAULT_PASS=test
orchestrator:
restart: on-failure
build:
context: .
dockerfile: Dockerfile
args:
VERSION: ${VERSION}
environment:
- camel_component_rabbitmq_hostname=rabbitmq
- camel_component_rabbitmq_port=5672
- camel_component_rabbitmq_username=adminsi
- camel_component_rabbitmq_password=test
container_name: orchestrator
depends_on:
- rabbitmq
networks:
- orchestrator-rabbitmq
ports:
- 7127:7127
networks:
orchestrator-rabbitmq:
external:
name: orchestrator-rabbitmq
I have modified the rabbitmq's host property (camel_component_rabbitmq_hostname) to rabbitmq for container resolution.我已将 rabbitmq 的主机属性(camel_component_rabbitmq_hostname)修改为 rabbitmq 用于容器解析。
I hope that my solution works for you, enjoy !我希望我的解决方案适合你,享受!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.