web123456

Java Interview Questions - Nacos Common Interview Questions

Table of contents

1. Getting started with service registration and call

2. Design and implementation of service load balancing

3. Feign-based remote service call

4. Configuration Center

5. Quick Start of Configuration Center

6. Nacos configuration management model


1. Getting started with service registration and call

1. Why register services to nacos? To find these services better

------------------------------------------------------------------------------------------------------
How does a service determine the status of a service instance?
By sending a heartbeat packet, it will be sent once in 5 seconds. If there is no response in 15 seconds, it means that there is a problem with the service.
If there is no response after 30 seconds, the service has stopped.
-----------------------------------------------------------------------------------------------------
3. How does the service consumer call the service provider’s services?
Implemented by creating a RestTemplate object.
-----------------------------------------------------------------------------------------------------
How is the load balancing underlying layer implemented?
Through Ribbon implementation, some load balancing algorithms are defined in Ribbon, and then based on these algorithms, they are used to service
Get an instance from the instance to provide services to the consumer.
-----------------------------------------------------------------------------------------------------
What is it? What problems can Ribbon solve?
Ribbon is a load balancing client provided by Netflix.
Ribbon can make service calls based on load balancing policies, and all policies will implement the IRule interface.
-----------------------------------------------------------------------------------------------------
What are the built-in load strategies?
8 types, you can view the implementation class of the IRule interface.
-----------------------------------------------------------------------------------------------------
7. What is the function of @LoadBalanced?
Describe the RestTemplate object, used to tell the Spring framework, when using RestTempalte
When a service is called, this calling process will be intercepted by an interceptor, and then started inside the interceptor.
Load balancing strategy.
 

2. Design and implementation of service load balancing

    What is the function of @Bean annotation?(Generally used to configure the class, describe related methods, and tell spring that the return value of this method should be handed over to the spring container management. The name of the bean is the method name by default. If you need to specify a name, @Bean("bean's name"), the most application scenarios are to integrate third-party resources-objects)


  What is the function of @Autowired annotation?(This annotation is used to describe attributes, construction methods, set methods, etc., and is used to tell the sprin framework to perform DI operations for attributes according to certain rules. By default, the corresponding objects are found according to attributes and method parameter types. If only one is found, it will be directly injected. When there are multiple types, the value will be injected according to the attribute name or method parameter name. If the name is added differently, an error will be reported)


    How is the load balancing underlying layer implemented in Nacos?(Implemented through Ribbon, some load balancing algorithms are defined in Ribbon, and then based on these algorithms, obtain an instance from the service instance to provide services to the consumption method)


   What is Ribbon?(The load balancing client provided by Netflix, which is generally used for consumption methods for services)


   What problems can Ribbon solve?(Service calls are made based on load balancing policies, and all policies will implement the IRule interface)


   What are the built-in load balancing strategies for Ribbon?(8 types, you can analyze by viewing the implementation class of the IRule interface)


   @LoadBalanced What is the function of?(Description of the RestTemplate object, used to tell the spring framework that when using RestTemplate to make service calls, this calling process will be intercepted by an interceptor, and then the load balancing policy will be started inside the interceptor)


    Can we define our load balancing strategy?(You can define policy based on the IRule interface, or you can refer to NacosRule for implementation)


3. Feign-based remote service call

  Why use feign?(Feign can realize service calls more friendly and simplify service consumers' calls to service provider methods)


    What is the function of FeignClient annotation?(Tell Feign Starte that when the project starts, create an implementation class-agent class for the interface described in this annotation)


   How to implement the underlying load balancing in Feign method?(Ribbon)


    What is the function of EnableFeignClients annotation?(Describe the configuration class, such as the startup class)


4. Configuration Center

  1. What is a configuration center? (a service that stores project configuration information)
  2. Why use the configuration center? (Centralized management of configuration information and dynamically publishing configuration information)
  3. What are the mainstream configuration centers in the market? (Apollo, Nacos,.....)

5. Quick Start of Configuration Center

  1. What content is usually configured in the configuration center?(Configuration information that may change frequently, such as connection pools, logs, thread pools, current limit filtration rules)
  2.    What information is not usually written to the configuration center?(Service port, service name, service registration address, configuration center)
  3.   Why define files in a project?(This file is read with a high priority, and the data from the configuration center can be read when the service starts)
  4.    The Nacos Configuration Center is down. Can our service still read configuration information?(After you can obtain the configuration information of the configuration center from memory and client, you will store a copy of the configuration information locally)
  5.    How do our clients get information from the configuration center in microservice applications?(Our service generally reads configuration information from memory first, and our microservices can also send requests to the Nacos configuration center to pull updated configuration information regularly)
  6.    How do clients perceive data changes in configuration centers in microservice applications?(1. After the version, the Nacos client will obtain configuration information from Nacos based on the long polling mechanism. The so-called long polling means that when there is no configuration update, it will wait in the queue of the Nacos server)
  7.    Why is our configuration data not obtained from the configuration center after the service is started?(Dependency, configuration file name, whether the DataId name in the configuration center is correct, whether the indentation relationship is correct, if it is dynamically published, is there annotation @RefreshScope on the class)
  8. What are the log specifications used in your project?(SLF4J)
  9.     Do you know the log levels in your project?(debug, info, error, can control the output of the log based on the log level)

6. Nacos configuration management model

  1. Nacos configuration management model background? (Different environments, different configurations)
  2. What is the management model in Nacos configuration? (namespace, group, service/data-id)
  3. Can the Nacos client read the shared configuration? (Can)