Unable to deploy RabbitMQ with gitlab-ci pipeline on google cloud?

て烟熏妆下的殇ゞ 提交于 2019-12-13 04:04:13

问题


In springboot application, the configuration of application-prod.yml are :

spring:
  rabbitmq:
    host: rabbitmq
    port: 5672
    username: guest
    password:  guest

gitlab-ci.yml configuration are :

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

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

But got the same result , and unable to connect with RabbitMQ. And also follow the following link here and got nothing.

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


回答1:


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.

Please find the source code here :

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


来源:https://stackoverflow.com/questions/57786388/unable-to-deploy-rabbitmq-with-gitlab-ci-pipeline-on-google-cloud

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!