Cloud config got Request execution error. endpoint=DefaultEndpoint{ serviceUrl='http://localhost:8761/} from Eureka server

喜夏-厌秋 提交于 2019-12-22 00:24:13

问题


I'm trying to implement Discovery First Bootstrap way for my 4 micro-services. First is a config server that takes config from git, and second is an Eureka server. When i'm running docker-compose up my config server is not able to register with eureka. I've got:

Request execution error. endpoint=DefaultEndpoint{ serviceUrl='http://localhost:8761/} Connection refused

My config server

 @EnableConfigServer
    @EnableEurekaClient
    @SpringBootApplication
    public class ConfigServerApplication {
        public static void main(String[] args) {
            SpringApplication.run(ConfigServerApplication.class, args);
        }

application.yml

   server:
  port: 8888
spring:
  cloud:
    config:
      server:
        encrypt.enabled: false
        git:
          uri: https://github.com/Artuwok/artbook-config-repo/
          searchPaths: userservice
          username: Artuwok
          password: Civilization1986
          timeout: 10
          force-pull: true

bootstrap.yml

spring:
  application:
    name: configserver
  cloud:
    config:
      fail-fast: true
      discovery.enabled: true

eureka:
  client:
    registerWithEureka: true
    fetchRegistry: true
    serviceUrl.defaultZone: http://localhost:8761/eureka/

Eureca class

@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {

    public static void main(String[] args) {
        SpringApplication.run(EurekaServerApplication.class, args);
    }

Eureka bootstrap.yml

server:
  port: 8761
eureka:
  client:
    registerWithEureka: false
    fetchRegistry: false

docker-compose.yml with full config

version: '3'

services:

  configserver:
    image: configserver:1.0
    ports:
      - "8888:8888"
    depends_on:
      - eurekaserver
    restart: on-failure

  eurekaserver:
    image: eurekasvr:1.0
    ports:
      - "8761:8761"


  users_db:
    image: mysql:5.7
    container_name: users_db
    restart: always
    environment:
      - MYSQL_DATABASE=artbook
      - MYSQL_ROOT_PASSWORD=password
      - MYSQL_USER=user
      - MYSQL_PASSWORD=password
    volumes:
      - users_db:/var/lib/mysql
    ports:
      - "3306:3306"
    depends_on:
      - eurekaserver

  user-service:
    image: userservice:1.0
    ports:
      - "8080:8080"
    depends_on:
      - eurekaserver
      - configserver
    restart: on-failure
volumes:
  users_db:

So in the end i was able to start-up the services. Pay huge attention to URL on which you are discovering service. If you are using docker images you must use service name, not localhost in uri and urls's. My working config

spring:
  application:
    name: configserver
  cloud:
    config:
      fail-fast: false
      discovery.enabled: false
      uri: http://configserver:8888

eureka:
  client:
    registerWithEureka: true
    fetchRegistry: true
    serviceUrl.defaultZone: http://eurekaserver:8761/eureka

回答1:


You config server and Eureka server both run in Docker. So they can connect with each other using their names in Docker, not localhost.

So Eureka service URL should be: http://eurekaserver:8761/.

And you should add the code below to your configserver configuration in docker-compose.yml:

links:
    - eurekaserver


来源:https://stackoverflow.com/questions/55336558/cloud-config-got-request-execution-error-endpoint-defaultendpoint-serviceurl

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