【问题标题】:Unable to deploy RabbitMQ with gitlab-ci pipeline on google cloud?无法在谷歌云上使用 gitlab-ci 管道部署 RabbitMQ?
【发布时间】:2019-09-04 10:20:30
【问题描述】:

在springboot应用中,application-prod.yml的配置为:

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 管道上遇到以下异常:

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)

在运行构建阶段之前,我还尝试创建一个新阶段并在管道上运行:

docker-image-test:
  stage: test
  script:
    - docker run -d --hostname rabbitmq --name rabbitmq  -p 5672:5672 rabbitmq:management

但是得到了相同的结果,并且无法连接到 RabbitMQ。并且还按照以下链接here 并一无所获。

希望通过 gitlab CI/CD 管道在生产环境中部署 RabbitMQ,目前我们使用的是 docker image rabbitmq:management。我会在那里想念什么,任何帮助将不胜感激,谢谢

【问题讨论】:

    标签: spring-boot docker rabbitmq gitlab gitlab-ci


    【解决方案1】:

    我找到了解决方案,也许它可以帮助某人。问题出在 springboot 应用程序中的连接工厂,当我们上线(产品)时,它无法与 docker image rabbitmq:Management 连接。所以我们需要在我们的 RabbitMQ 配置中覆盖连接工厂。

    请在此处找到源代码:

    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;
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-05
      • 2017-08-15
      • 2021-02-26
      • 1970-01-01
      相关资源
      最近更新 更多