解析 Spring 中微服务实例的 IP 地址 [jhipster]

huangapple go评论97阅读模式
英文:

Resolve IP Address of microservice instance in spring could [jhipster]

问题

我正在使用Jhipster创建一个简单的微服务架构,基本上我有一个正在运行的Eureka注册中心,有许多微服务实例注册在其中。

一些微服务需要与其他微服务交互或查询一些数据,但每个微服务都有一个动态IP地址,是否可以使用实例名称来解析IP并进行请求?

英文:

I am using Jhipster to create a simple microservices architectures, basically I have an Eureka registry running,to whom a bunch of microservices instances are registered.

Some microservices need to talk to other microservices or query some data, but each microservice has a dynamic IP address, is it possible to use the instanse name to resolve IP and do the request ?

答案1

得分: 2

这已经由JHipster Eureka架构提供。

  • 微服务(Eureka客户端)向注册表(Eureka服务器)注册。
  • 然后,将eureka.client.fetch-registry属性设置为true的每个微服务都会配置其Ribbon实例,并且可以使用类似于http://<service name>/api/something的服务名称URL连接到其他已注册的服务,可以使用RestTemplateFeignClient

您并未说明您选择了哪种身份验证方式,此文档适用于UAA,即使对于纯JWT也可能有所帮助:https://www.jhipster.tech/using-uaa/#inter-service-communication

英文:

This is already provided by the JHipster Eureka architecture.

  • The microservices (Eureka clients) register with the registry (Eureka server).
  • Then, each microservice that sets the eureka.client.fetch-registry property to true gets its Ribbon instance configured and can connect to other registered services using service name URL like http://&lt;service name&gt;/api/something using a RestTemplate or a FeignClient

You did not say what kind of authentication you chose, this doc is for UAA and it might help even for plain JWT: https://www.jhipster.tech/using-uaa/#inter-service-communication

答案2

得分: 0

你可以使用服务器端负载平衡模式。Netflix Zuul作为API网关为您提供了这种类型的负载平衡(使用Netflix Ribbon作为负载均衡器)。
在您的情况下:创建Zuul微服务(不要忘记注解@EnableZuulProxy),并在Eureka中进行注册。

完成这些步骤后,您将能够通过Zuul微服务地址调用在Eureka中注册的您的微服务实例,而无需在客户端了解它们的地址。

英文:

You can use server side load balancing pattern. Netflix Zuul as API gateways offers you that kind of balancing (use Netflix Ribbon as load balancer).
In your case: create Zuul µservice (don't forget annotation@EnableZuulProxy) and register it in Eureka.

After these steps you'll be able to call your µservice instances registred in Eureka via Zuul µservice address without knowing their addresses on the client side.

huangapple
  • 本文由 发表于 2020年8月27日 05:58:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/63606310.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定