我正在使用 Spring Boot 构建一个微服务应用程序,以下是我的配置文件(serviceregistry、configserver、cloudgateway)
云网关
cloudgateway:
port: 9090
spring:
application:
name: API-GATEWAY
config:
import: configserver:http://${CONFIG_SERVER_URL:localhost}:9296
cloud:
gateway:
routes:
- id : CONSULTATION-SERVICE
uri: lb://CONSULTATION-SERVICE
predicates:
- Path=/consultation/**
filters:
- name: CircuitBreaker
args:
name: CONSULTATION-SERVICE
fallbackuri: forward:/consultationServiceFallBack
#- name: RequestRateLimiter
#args:
#redis-rate-limiter.replenishRate: 1
#redis-rate-limiter.burstCapacity: 1
- id: PATIENT-SERVICE
uri: lb://PATIENT-SERVICE
predicates:
- Path=/patient/**
filters:
- name: CircuitBreaker
args:
name: PATIENT-SERVICE
fallbackuri: forward:/patientServiceFallBack
#- name: RequestRateLimiter
#args:
#redis-rate-limiter.replenishRate: 1
#redis-rate-limiter.burstCapacity: 1
- id: DOCTOR-SERVICE
uri: lb://DOCTOR-SERVICE
predicates:
- Path=/doctor/**
filters:
- name: CircuitBreaker
args:
name: DOCTOR-SERVICE
fallbackuri: forward:/doctorServiceFallBack
#- name: RequestRateLimiter
#args:
#redis-rate-limiter.replenishRate: 1
#redis-rate-limiter.burstCapacity: 1
configserver定义为:
server:
port: 9296
spring:
application:
name: CONFIG-SERVER
cloud:
config:
server:
git:
uri: https://github.com/cimoDevOps/ConfigServer
clone-on-start: true
eureka:
instance:
prefer-ip-address: true
client:
fetch-registry: true
register-with-eureka: true
service-url:
defaultZone: ${EUREKA_SERVER_ADDRESS:http://localhost:8761/eureka}
服务注册表
server:
port: 8761
eureka:
instance:
hostname: localhost
client:
register-with-eureka: false
fetch-registry: false
我用来构建镜像并作为容器运行的 docker 命令是:
docker build -t pfs2023/serviceregistry:latest .
docker build -t pfs2023/configserver:latest .
docker build -t pfs2023/cloudgateway:latest .
docker run -d -p8761:8761 --name serviceregistry e68b3d0e99b8
docker run -d -p9296:9296 -e EUREKA_SERVER_ADDRESS=http://host.docker.internal:8761/eureka --name configserver d5edc4d23bb2
docker run -d -p9090:9090 -e CONFIG_SERVER_URL=host.docker.internal -e EUREKA_SERVER_ADDRESS=http://host.docker.internal:8761/eureka --name cloudgateway 5b844ba6178e
这是我遇到的问题错误(请注意,serviceragistry&configserver 运行没有问题)
2023-05-27 20:02:35 2023-05-27 19:02:35.266 WARN [API-GATEWAY,,] 1 --- [ main] c.n.d.s.t.d.RetryableEurekaHttpClient : Request execution failed with message: I/O error on GET request for "http://localhost:8761/eureka/apps/": Connect to localhost:8761 [localhost/127.0.0.1] failed: Connection refused (Connection refused); nested exception is org.apache.http.conn.HttpHostConnectException: Connect to localhost:8761 [localhost/127.0.0.1] failed: Connection refused (Connection refused)
2023-05-27 20:02:35 2023-05-27 19:02:35.273 INFO [API-GATEWAY,,] 1 --- [ main] com.netflix.discovery.DiscoveryClient : DiscoveryClient_API-GATEWAY/3fababcaddac:API-GATEWAY:9090 - was unable to refresh its cache! This periodic background refresh will be retried in 30 seconds. status = Cannot execute request on any known server stacktrace = com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server (give a correct solution)
请建议解决此问题“连接被拒绝”。
有人应该回答这个问题..我到处谷歌都找不到适合我的解决方案