官术网_书友最值得收藏!

  • 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:

  1. We created a Maven project and defined the starters and dependencies.
  2. We created the YML files for bootstrapping and application properties.
  3. We created the ProductSpringApp class containing the main method that is the starting point of the applications.
  4. 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:

  1. Run the EurekaApplication class (or run a Maven build on the eureka-server project). Observe the last few lines in the logs:
  1. Run the ProductSpringApp class (or run a Maven build on the product project). Note the last few lines in the the log:
  1. Access the product service directly at: http://localhost:8081/dev/product/4.

    You will see the following response:

{"id":4,"name":"Oranges ","catId":2}
  1. 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:

  1. The HTTP request to get /client/4 was handled by the getProduct method in the ProductClient class.
  2. 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:
  1. 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.

主站蜘蛛池模板: 高雄市| 察雅县| 铜川市| 蒲城县| 高台县| 花莲县| 保定市| 高阳县| 萨嘎县| 安多县| 台东市| 苏尼特左旗| 当阳市| 万全县| 子长县| 龙陵县| 肇源县| 清新县| 抚顺县| 蓝田县| 平乡县| 祁东县| 瓮安县| 衡水市| 郓城县| 盐边县| 嵩明县| 铜梁县| 潞西市| 六枝特区| 天水市| 尚义县| 博野县| 白玉县| 夏邑县| 新疆| 宜良县| 西盟| 读书| 永春县| 旬阳县|