- Cloud-Native Applications in Java
- Ajay Mahajan Munish Kumar Gupta Shyam Sundar
- 392字
- 2021-06-24 19:07:18
Seeing the lookup in action
Now, we are all set to run the product client. To recap, at this stage, we have a Eureka server project and a product project with the following structure:

Let's take a few minutes to review what we did:
- We created a Maven project and defined the starters and dependencies.
- We created the YML files for bootstrapping and application properties.
- We created the ProductSpringApp class containing the main method that is the starting point of the applications.
- For the product project, we had the following classes:
- Product: The domain or entity which we will enhance later
- ProductService: The microservice responsible for implementing the services and APIs
- ProductClient: The client to test out the service lookup
Now, let's see it in action:
- Run the EurekaApplication class (or run a Maven build on the eureka-server project). Observe the last few lines in the logs:

- Run the ProductSpringApp class (or run a Maven build on the product project). Note the last few lines in the the log:

- Access the product service directly at: http://localhost:8081/dev/product/4.
You will see the following response:
{"id":4,"name":"Oranges ","catId":2}
- Now, access the client URL, http://localhost:8081/client/4 , which does a lookup of the product service from the service registry and directs it to the respective product service.
You will see the following response:
{"id":4,"name":"Oranges ","catId":2}
You may see an internal server error (No instances available for PRODUCT). This can happen while the heartbeat completes and the addresses are re-picked by the Ribbon load balancer. Wait a few seconds for the registry to update and then try again.
A lot has happened under the hood in getting this response:
- The HTTP request to get /client/4 was handled by the getProduct method in the ProductClient class.
- It did a lookup of the service from the Eureka registry. This is where we find log statements as follows:
c.n.l.DynamicServerListLoadBalancer: Using serverListUpdater PollinServerListUpdater
c.netflix.config.ChainedDynamicProperty: Flipping property: PRODUCT.ribbon.ActiveConnectionsLimit to use NEXT property: niws.loadbalancer
c.n.l.DynamicServerListLoadBalancer: DynamicServerListLoadBalancer for client PRODUCT intiated: DynamicServerListLoadBalancer:
- After it did the lookup, it forwarded the request to the actual ProductService through the Ribbon load balancer library.
This was just a simple mechanism of a client invoking services through a dynamic lookup. In later chapters, we will add functionality to make it resilient and functional in terms of getting data from the database.
- 通信工程辦公實(shí)務(wù)
- 雷達(dá)微波新技術(shù)
- 分布式系統(tǒng)常用技術(shù)及案例分析(第2版)
- 電子技術(shù)(第3版)
- WCDMA基站系統(tǒng)原理與裝調(diào)維護(hù)
- 聲發(fā)射信號(hào)處理算法研究
- 艦船尾跡的電磁成像機(jī)理及特征提取技術(shù)
- 電磁場(chǎng)與電磁波
- 手繪圖說電子電路圖
- 5G 移動(dòng)性管理技術(shù)
- 電子組裝先進(jìn)工藝
- Premiere Pro CC2018中文版基礎(chǔ)培訓(xùn)教程
- NFC技術(shù)原理與應(yīng)用
- 任務(wù)驅(qū)動(dòng)學(xué)電視機(jī)維修技術(shù)
- 開關(guān)電源設(shè)計(jì)與制作基礎(chǔ)