使用 Eureka 和 OpenFeign 部署 Heroku 微服务的延迟问题

时间:2021-02-27 12:46:31

标签: spring-boot heroku netflix-eureka spring-cloud-feign

我正在尝试使用 Eureka Server 和 Open Feign 将一个简单的微服务 hello world 测试部署到 Heroku...

我可以使用以下配置部署 Eureka 服务器

尤里卡服务器

应用属性

server.port=${PORT:5000}
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
eureka.client.service-url.default-zone=http://${eureka.instance.hostname}:${server.port}/eureka/

尤里卡服务器应用程序

@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {

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

}

以及以下客户

Client1

application.properties

server.port=${PORT:5000}
spring.application.name=eureka-client1
eureka.client.serviceUrl.defaultZone  = https://<app>.herokuapp.com/eureka/
# Trying to increase the connect and read timeout values without success
feign.client.config.default.connectTimeout=60000
feign.client.config.default.readTimeout=30000

EurekaClient1Application

@SpringBootApplication
@EnableEurekaClient
@EnableFeignClients
public class EurekaClient1Application {

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

}

FeignClient

@FeignClient(name = "eureka-client2")
public interface EurekaClient2Client {
    @GetMapping("/students")
    String world();
}

HelloWorldController

@RestController
public class HelloWorldController {

    @Autowired
    private EurekaClient2Client eurekaClient2Client;

    @GetMapping("/hello-world")
    public String helloWorld() {
        return "Hello " + eurekaClient2Client.world();
    }

}

Client2

application.properties

server.port=${PORT:5000}
spring.application.name=eureka-client2
eureka.client.serviceUrl.defaultZone  = https://<app>.herokuapp.com/eureka/

控制器

@GetMapping("/students")
public String world() {
    return "world";
 }

所以,一切似乎都正确部署在 heroku 中 enter image description here

如果我单独调用它们,两个服务(eureka-client1 和 eureka-client2)都可以正常工作。但是,如果我想使用 OpenFeing 从一个微服务调用另一个微服务,则会出现此错误

enter image description here

这是日志

enter image description here

所以一切都指向一个延迟问题,但我不知道一个简单的 hello-world 与微服务(使用 eureka 服务器和使用 openFeign 的客户端通信)在通过 Eureka 服务器时会如此缓慢。因为如果我只是在 Feign Client 中添加 URL,它就可以完美运行。我不知道为什么当我尝试拨打电话时,如果识别我的 Eureka Clients 无法提供给 Feing Client 的参考。

希望你能帮助我理解发生了什么:C

0 个答案:

没有答案
相关问题