eureka向springgateway提供死服务

des4xlb0  于 2021-07-13  发布在  Java
关注(0)|答案(0)|浏览(226)

我对微服务架构很陌生。我已经建立了一个springgateway、springeureka服务器和一个连接到mongodb的简单springweb微服务。
当我开始所有三个,他们似乎工作和重定向正确。但是如果我启动两个微服务而不是一个,然后关闭一个,我会得到一个500:内部服务器错误。
网关中的错误:

2021-04-08 17:23:05.648 ERROR 14088 --- [ctor-http-nio-3] a.w.r.e.AbstractErrorWebExceptionHandler : [1ff6b9d0-28]  500 Server Error for HTTP GET "/spots/606ee9fd912b5c28b4dc8968"

io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: no further information: host.docker.internal/192.168.178.185:60161
    Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException: 
Error has been observed at the following site(s):
    |_ checkpoint ⇢ org.springframework.web.cors.reactive.CorsWebFilter [DefaultWebFilterChain]
    |_ checkpoint ⇢ org.springframework.cloud.gateway.filter.WeightCalculatorWebFilter [DefaultWebFilterChain]
    |_ checkpoint ⇢ HTTP GET "/spots/606ee9fd912b5c28b4dc8968" [ExceptionHandlingWebHandler]
Stack trace:
Caused by: java.net.ConnectException: Connection refused: no further information
    at java.base/sun.nio.ch.SocketChannelImpl.checkConnect(Native Method) ~[na:na]
    at java.base/sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:779) ~[na:na]
    at io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:330) ~[netty-transport-4.1.60.Final.jar:4.1.60.Final]
    at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:334) ~[netty-transport-4.1.60.Final.jar:4.1.60.Final]
    at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:707) ~[netty-transport-4.1.60.Final.jar:4.1.60.Final]
    at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:655) ~[netty-transport-4.1.60.Final.jar:4.1.60.Final]
    at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:581) ~[netty-transport-4.1.60.Final.jar:4.1.60.Final]
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493) ~[netty-transport-4.1.60.Final.jar:4.1.60.Final]
    at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989) ~[netty-common-4.1.60.Final.jar:4.1.60.Final]
    at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-common-4.1.60.Final.jar:4.1.60.Final]
    at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[netty-common-4.1.60.Final.jar:4.1.60.Final]

网关:

网关中的application.properties:

server.port=8080
spring.application.name=spots-gateway

# Eureka

eureka.client.serviceUrl.defaultZone  = http://localhost:8761/eureka
eureka.client.instance.preferIpAddress = true
eureka.instance.instance-id=${spring.application.name}:${random.uuid}

应用程序:

@SpringBootApplication
public class SpotsGatewayApplication {

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

    @Bean
    public RouteLocator routes(RouteLocatorBuilder builder, AuthFilter authFilter) {
        return builder.routes()
                .route(r -> r.path("/spots/**")
                        .filters(f -> f.filter(authFilter.apply(new AuthFilter.Config())))
                        .uri("lb://SPOT-SERVICE"))
                .build();
    }
}

eureka服务器:

在Eureka 的应用特性:

server.port=8761
spring.application.name=spots-eureka

eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
eureka.server.eviction-interval-timer-in-ms=1000

微服务:

使用中的应用程序属性:

server.port=0
spring.application.name=spot-service

# MongoDB

spring.data.mongodb.database=Spots

# Eureka

eureka.client.serviceUrl.defaultZone  = http://localhost:8761/eureka
eureka.client.instance.preferIpAddress = true
eureka.instance.instance-id=${spring.application.name}:${random.uuid}

应用程序:

@EnableDiscoveryClient
@SpringBootApplication
public class SpotserviceApplication {

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

}

rest代码段:

@RestController
public class SpotsController {

    @Autowired
    private ISpotsRepository repository;

    @GetMapping(value="/spots")
    public @ResponseBody
    ResponseEntity<List<Spot>> spots() {
        return new ResponseEntity<>(repository.findAll(), HttpStatus.OK);
    }

我希望并期望Eureka 只为网关提供工作服务。如何做到这一点?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题