无法在Google Cloud上使用gitlab-ci管道部署RabbitMQ? [英] Unable to deploy RabbitMQ with gitlab-ci pipeline on google cloud?
问题描述
在springboot应用程序中,application-prod.yml
的配置为:
In springboot application, the configuration of application-prod.yml
are :
spring:
rabbitmq:
host: rabbitmq
port: 5672
username: guest
password: guest
gitlab-ci.yml
配置为:
services:
- docker:dind
- rabbitmq:management
variables:
RABBITMQ_DEFAULT_USER: guest
RABBITMQ_DEFAULT_PASS: guest
AMQP_URL: 'amqp://guest:guest@rabbitmq:5672'
stages:
- build
maven-foo-build:
stage: build
script:
- cd foo
- ./mvnw package -B -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn
artifacts:
paths:
- foo/target/*.jar
我在gitlab管道上遇到以下异常:
I got the following exception on gitlab pipeline :
org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused (Connection refused)
at org.springframework.amqp.rabbit.support.RabbitExceptionTranslator.convertRabbitAccessException(RabbitExceptionTranslator.java:62)
at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:509)
at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.createConnection(CachingConnectionFactory.java:702)
at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils.createConnection(ConnectionFactoryUtils.java:214)
at org.springframework.amqp.rabbit.core.RabbitTemplate.doExecute(RabbitTemplate.java:2073)
at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:2047)
at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:2027)
at org.springframework.amqp.rabbit.core.RabbitAdmin.getQueueProperties(RabbitAdmin.java:403)
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.attemptDeclarations(AbstractMessageListenerContainer.java:1787)
在运行构建阶段(例如:
I also tried to make a new stage and run on pipeline, before running build stage such as :
docker-image-test:
stage: test
script:
- docker run -d --hostname rabbitmq --name rabbitmq -p 5672:5672 rabbitmq:management
但是得到了相同的结果,并且无法与RabbitMQ连接.并点击以下链接此处,并一无所有.
But got the same result , and unable to connect with RabbitMQ. And also follow the following link here and got nothing.
想要通过gitlab CI/CD管道实现在生产环境中部署RabbitMQ,目前我们正在使用docker image rabbitmq:management
.我在那里会想念的东西,任何帮助将不胜感激,谢谢
Want to achieve to deploy RabbitMQ on production with gitlab CI/CD pipeline which currently we are using docker image rabbitmq:management
. What am I going to miss there, any help would be grateful, Thanks
推荐答案
我已经找到了解决方案,也许它可以对某人有所帮助.问题是springboot应用程序中的连接工厂,当我们使用live(prod)时,它无法与docker image rabbitmq:Management
连接.因此,我们需要在RabbitMQ配置中覆盖连接工厂.
I have found the solution , maybe it may help someone. Problem is with the connection factory in springboot application, which is unable to connect with docker image rabbitmq:Management
when we go for live(prod). So we need to override the connection factory in our RabbitMQ Configurations.
请在此处找到源代码:
private static final String BROKER_URI = "amqp://guest:guest@rabbitmq:5672";
@Bean
public CachingConnectionFactory rabbitConnectionFactory(RabbitProperties config)
throws Exception {
CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
connectionFactory.getRabbitConnectionFactory().setUri(BROKER_URI);
return connectionFactory;
}
这篇关于无法在Google Cloud上使用gitlab-ci管道部署RabbitMQ?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!