英文:
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连接到其他已注册的服务,可以使用RestTemplate
或FeignClient
。
您并未说明您选择了哪种身份验证方式,此文档适用于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 totrue
gets its Ribbon instance configured and can connect to other registered services using service name URL likehttp://<service name>/api/something
using aRestTemplate
or aFeignClient
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论