Chat service registration service registration and discovery micro-micro-talk services and discovery services

Excerpt: https://www.cnblogs.com/mayou18/p/9829876.html

Micro-talk service registration and discovery services

Source: Ali middleware team shares more articles please visit  MAYOU18

Micro chatted service registration services and found that many people will immediately blurted out zk, etcd, consul, eureka these components, and then talk to the CAP how to choose, how performance, high availability and disaster recovery is how to achieve.

introduction

Micro chatted service registration services and found that many people will immediately blurted out zk, etcd, consul, eureka these components, and then talk to the CAP how to choose, how performance, high availability and disaster recovery is how to achieve.

Prior to this, standing in the component user's perspective, so I would like to ask a few questions:

  • How to determine the registered IP and port?

  • Implement service management needs what information is registered?

  • How elegant service registered with the service offline?
  • Health check registration services is how to do?
  • When the service has quit node or a new node is added, the subscriber can not receive timely notice?
  • I can easily see an application publish and subscribe to services which, as well as a subscription service which nodes it?

After reading these questions, you may find, for service registration and discovery, first of all should be concerned about is a registered service discovery itself, and then the performance and high availability.

A good registration service discovery middleware should be able to fully meet the basic functions of service development and governance, and then the performance and high availability. If the previous functions not think clearly, then a high availability and performance are the clouds. Finally, security is equally important.

  • How the performance of the server?

  • Disaster recovery service strategy discovery of what?

  • When a problem with my network applications and services of connection appears Discovery Center, I would call what impact?
  • Service registry when the machine is down or down, I would call what impact a whole?
  • Sign up and link security service discovered it, there is no good authority control?

The following from the service registration, service discovery, disaster recovery and high availability to answer three major aspects of mainstream approaches to these questions.

Finally, will introduce the ANS (Alibaba Naming Service), ANS combines the advantages of these solutions, and outputs the EDAS (Ali Baba enterprise distributed application services), the current completely free!

Service Registration

How to determine the registered IP and port?

How to determine the IP

There are mainstream IP acquire these methods.

  • The most simple and crude way, manual configuration required to register the IP. Of course, this way simply can not use in a production environment, since the micro-level support services are basically the expansion of multi-machine deployment, hardcoded IP addresses in the configuration mode code that can not support a level of expansion, operation and maintenance will bring great the cost of.

  • To acquire by way of traversing the network card, first find an address for the local loopback IP address. In most cases, this relatively easy manner, Dubbo like frame is used in this method.

  • In some network planning better standardization in the room, we can also manually specify the name of the NIC that interfaceName way to specify which network card corresponding IP addresses to register.
  • When these three methods are not effectively solve the problem, there is a way to establish a socket connection directly to the service registry, and then socket.getLocalAddress() to get the IP of the machine in this way.

How to determine the port

Gets the port, there is no standardized scheme.

  • If RPC applications to start when there is a configuration specified port listening service, the registered value when either a port configuration item.

  • HTTP application of traditional WEB container provided, there is also a configuration file to configure the listening port of the vessel, registered when either a port value of the configuration items.

  • In particular, in the Spring Boot framework for Java applications, it can  EmbeddedServletContainerInitializedEvent. getEmbeddedServletContainer().getPort()be obtained. (Spring Boot version 1.x).

Implement service management needs what information is registered?

Simply IP and port information registered up to meet the basic needs of the service call, but in business development to a certain extent, we will have these requirements:

  • Want to know an HTTP service is turned on TLS.

  • Provided to different nodes in the same service of different weights, traffic scheduling.

  • The service is divided into pre-development environment and production environment, facilitate AB Test function.
  • Plus room tag different room service registration, routing rules in order to achieve the same room priority.

Implement these advanced features, essentially depends on the load balancing strategy and tactics client calls when the calls, but if the service metadata is not registered up, can only make bricks without straw. A good service registry in the initial design should support these extensions field.

How elegant service registered with the service offline?

Elegant release

Although the service registration generally occurs during start-up services, but the subdivision, then, should have been fully registered service started successfully in service and ready to sign up after external services.

  • Some RPC framework itself provides a method to determine whether the service has been launched to complete, such as Thrift, we can Server.isServing () to determine.

  • Some RPC framework itself does not provide a complete service is the way to start, then we can be judged by whether the port has been detected in a listening state.

  • For the HTTP service, whether to activate the service is completed can also be judged by whether the port is listening.
  • In particular, in the Spring Boot framework for Java applications, you can start to notify the container has been completed, EmbeddedServletContainerInitializedEvent event to notify the container has started completed (Spring Boot version 1.x) in the form of event notification.

Elegant offline

The vast majority of service registry provides health checks, after the application will automatically stop the removal of nodes corresponding to the service. But we can not completely rely on this feature, the application should take the initiative to call the service off the assembly line interface to the service registry when you stop.

  • In Java applications, a common service interface calls off the assembly line in general use JVM Shutdown Hook way to achieve.

  • In particular, Spring Framework Java applications can be implemented by Spring Bean LifeCycle initiative to call the service offline to stop the application interfaces.

  • Of course, the above two methods is not enough grace, because it can not ensure this brutal kill -9 stop mode does not appear, but the application call the service off the assembly line interface is also trying to call for No Network and other abnormal scene did not do exception handling. Therefore, call the client should still be prepared to handle the load balancing and failover.
  • More elegant manner, corresponding to the right application will stop the first resetting to 0, then no call upstream of this application. This time to stop the operation of the application did not affect the service subscribers, of course, this scenario requires subscribers to achieve by the weight of the load balancing operation and maintenance and deployment tools combined depth.

Health Inspection Service is how to do?

Health Check is divided into client and server heartbeat active detection in two ways.

  • The client heartbeat

  • The client sends regular intervals "heartbeat" way to indicate to the server service status of their normal heartbeat may be in the form of TCP, also in the form of HTTP.

  • It can also connect a client to realize his way through the heart to maintain a long socket client and server.

  • ZooKeeper not actively transmitting a heartbeat, but rely on the characteristics of the component itself provides temporary nodes, the nodes maintained by the session ZooKeeper temporary connection.

But the client heartbeat, the heartbeat active and maintain a long connection of clients just show normal on the link, the service status is not necessarily normal.

The server automatically call service health check is a more accurate way to return the results show the success of the service status is indeed normal.

  • Active detection server
  • The server calls the service publisher HTTP interface to complete a health check.
  • For the HTTP service does not provide RPC application, the server call interface service publisher to complete the health check.
  • You can perform a comprehensive inspection by the form of a script.

Server active detection is also problematic. Service registry automatically call RPC service can not be done on an interface versatility; in many scenes service registry to network service publisher is unreasonable, the server can not initiate a health check.

So how to choose, still need to be decided according to the actual situation, according to different scenarios, choose different strategies.

Service Discovery

How to find the address of the service discovery server?

  • Specify the address of the service centers registered in the application's configuration file, similar to the zookeeper and eureka.
  • Specify the address of a server address, and then to get the address of the service registry by this address of the server, the server returns the address of the results will be updated with the service registry of scaling capacity.

When the service nodes with new nodes join or quit, subscribers receive timely notice how?

Classic Push and Pull problem.

Push two of the Classical, notify socket connection length, such as the typical implementation based ZooKeeper; Long Polling is another HTTP connections.

However notify message loss problem based on long socket connection notify and HTTP-based protocol Long Polling will.

It is also necessary, by way of the timing polling Pull choose also critical time interval, the higher the frequency of the service registry greater the pressure. Scale requires a combination of performance and service side of the business of trade-offs.

There is another way, true Push, the client opens a UDP server, service registry data to push through UDP way, of course, this is also limited by the connectivity of the network.

I can easily see what I publish and subscribe to the service, a subscription service which nodes it?

  • A good product, user experience and operation and maintenance experience must be elegant, to see if the machine publish and subscribe to the service, only by looking at the logs, even jmap way to get, obviously very bad experience.

  • Service registry should provide a rich interface, support depending on the application name, IP, subscribe to the service name, service name published, to carry out multi-level combined query.

  • At the same time, the client's memory, should also publish various information and reservation service subscriptions, and provide a way for people to easily query.
  • For example, in Java applications Spring Boot, and can be combined actuator endpoint, to provide native HTTP service queries by the way, check this application publishing services, as well as the corresponding node subscription services and various services.

Disaster recovery and high availability

How Performance

When the service nodes rises, the performance of a service registry will become a bottleneck, this time on the need to improve the performance of the cluster service registry through the horizontal expansion. 

  • For those using a strong consistency class Paxos protocol components, such as the ZooKeeper, since more than half of each write operation requires confirmation node. Expansion can not raise the level of the entire cluster write performance can only improve the reading performance of the entire cluster. 
  • As for the use of eventual consistency of components, the level of expansion can improve write performance and read performance of the entire cluster simultaneously.

Client disaster recovery strategy

  1. First, the local memory cache, and the connection is lost when running the service registry or registry service completely down, still normal call service.

  2. The local cache files, applications and services when the registration center network partition or registered service center is fully down, the application is restarted operations, memory is no data, then the application may be obtained by reading the data in the local cache file last subscriptions to content.

  3. Finally, local disaster recovery folder. Under normal circumstances, disaster recovery folder is not the content. When the server is fully and prolonged downtime can not be restored, while the service provider has undergone great changes, you can turn a local disaster recovery by adding a file in the file folder disaster recovery mode. At this point the client will ignore the original local cache file, just read the configuration file from the local disaster recovery.

Disaster recovery and high availability server

  • When a new node joins the cluster, the node starts automatically added to the address of the server, and find the address of the server through other nodes automatically synchronize data from other nodes to reach the final data consistency. 
  • When a node goes down, the information will be automatically registered for this service center address of the server node removal, the client can promptly perceive this node offline. 

Stateless server ensures thin disaster recovery and high availability services can do.

How secure is the server do?

Link security, service registry for use HTTP connection, the best way to protect the security of the link is using HTTPS. The service registry using TCP connections, because the application layer protocol generally used by private agreement, there is not necessarily ready TLS support programs.

In the security business, it should be in every release, subscriptions, heartbeat, authentication information are put on the line to sign inspection and authentication to ensure the security of business information.

Alibaba Naming Service

ANS (Alibaba Naming Service) is the middleware team for many years Alibaba business practices precipitation polished open-source products. Service registration and discovery in respect, ANS combines the advantages of these solutions is the most suitable for cloud-native application service registration and discovery components.
ANS has been in service on the line EDAS (Ali Baba enterprise distributed application services), is now available for Spring Cloud Ans Starter Spring Cloud convenient user directly using a secure and reliable commercial version of the service registration and discovery. ANS perfectly support the characteristics of Eureka, and is now completely free! For more information see  EDAS help documentation .

Seeking attention: www.mayou18.com JAVA technology exchange group: 516348359 Jstorm technical exchange group: 199 260 183
 
Category:  Technology Column

Source: Ali middleware team shares more articles please visit  MAYOU18

Micro chatted service registration services and found that many people will immediately blurted out zk, etcd, consul, eureka these components, and then talk to the CAP how to choose, how performance, high availability and disaster recovery is how to achieve.

introduction

Micro chatted service registration services and found that many people will immediately blurted out zk, etcd, consul, eureka these components, and then talk to the CAP how to choose, how performance, high availability and disaster recovery is how to achieve.

Prior to this, standing in the component user's perspective, so I would like to ask a few questions:

  • How to determine the registered IP and port?

  • Implement service management needs what information is registered?

  • How elegant service registered with the service offline?
  • Health check registration services is how to do?
  • When the service has quit node or a new node is added, the subscriber can not receive timely notice?
  • I can easily see an application publish and subscribe to services which, as well as a subscription service which nodes it?

After reading these questions, you may find, for service registration and discovery, first of all should be concerned about is a registered service discovery itself, and then the performance and high availability.

A good registration service discovery middleware should be able to fully meet the basic functions of service development and governance, and then the performance and high availability. If the previous functions not think clearly, then a high availability and performance are the clouds. Finally, security is equally important.

  • How the performance of the server?

  • Disaster recovery service strategy discovery of what?

  • When a problem with my network applications and services of connection appears Discovery Center, I would call what impact?
  • Service registry when the machine is down or down, I would call what impact a whole?
  • Sign up and link security service discovered it, there is no good authority control?

The following from the service registration, service discovery, disaster recovery and high availability to answer three major aspects of mainstream approaches to these questions.

Finally, will introduce the ANS (Alibaba Naming Service), ANS combines the advantages of these solutions, and outputs the EDAS (Ali Baba enterprise distributed application services), the current completely free!

Service Registration

How to determine the registered IP and port?

How to determine the IP

There are mainstream IP acquire these methods.

  • The most simple and crude way, manual configuration required to register the IP. Of course, this way simply can not use in a production environment, since the micro-level support services are basically the expansion of multi-machine deployment, hardcoded IP addresses in the configuration mode code that can not support a level of expansion, operation and maintenance will bring great the cost of.

  • To acquire by way of traversing the network card, first find an address for the local loopback IP address. In most cases, this relatively easy manner, Dubbo like frame is used in this method.

  • In some network planning better standardization in the room, we can also manually specify the name of the NIC that interfaceName way to specify which network card corresponding IP addresses to register.
  • When these three methods are not effectively solve the problem, there is a way to establish a socket connection directly to the service registry, and then socket.getLocalAddress() to get the IP of the machine in this way.

How to determine the port

Gets the port, there is no standardized scheme.

  • If RPC applications to start when there is a configuration specified port listening service, the registered value when either a port configuration item.

  • HTTP application of traditional WEB container provided, there is also a configuration file to configure the listening port of the vessel, registered when either a port value of the configuration items.

  • In particular, in the Spring Boot framework for Java applications, it can  EmbeddedServletContainerInitializedEvent. getEmbeddedServletContainer().getPort()be obtained. (Spring Boot version 1.x).

Implement service management needs what information is registered?

Simply IP and port information registered up to meet the basic needs of the service call, but in business development to a certain extent, we will have these requirements:

  • Want to know an HTTP service is turned on TLS.

  • Provided to different nodes in the same service of different weights, traffic scheduling.

  • The service is divided into pre-development environment and production environment, facilitate AB Test function.
  • Plus room tag different room service registration, routing rules in order to achieve the same room priority.

Implement these advanced features, essentially depends on the load balancing strategy and tactics client calls when the calls, but if the service metadata is not registered up, can only make bricks without straw. A good service registry in the initial design should support these extensions field.

How elegant service registered with the service offline?

Elegant release

Although the service registration generally occurs during start-up services, but the subdivision, then, should have been fully registered service started successfully in service and ready to sign up after external services.

  • Some RPC framework itself provides a method to determine whether the service has been launched to complete, such as Thrift, we can Server.isServing () to determine.

  • Some RPC framework itself does not provide a complete service is the way to start, then we can be judged by whether the port has been detected in a listening state.

  • For the HTTP service, whether to activate the service is completed can also be judged by whether the port is listening.
  • In particular, in the Spring Boot framework for Java applications, you can start to notify the container has been completed, EmbeddedServletContainerInitializedEvent event to notify the container has started completed (Spring Boot version 1.x) in the form of event notification.

Elegant offline

The vast majority of service registry provides health checks, after the application will automatically stop the removal of nodes corresponding to the service. But we can not completely rely on this feature, the application should take the initiative to call the service off the assembly line interface to the service registry when you stop.

  • In Java applications, a common service interface calls off the assembly line in general use JVM Shutdown Hook way to achieve.

  • In particular, Spring Framework Java applications can be implemented by Spring Bean LifeCycle initiative to call the service offline to stop the application interfaces.

  • Of course, the above two methods is not enough grace, because it can not ensure this brutal kill -9 stop mode does not appear, but the application call the service off the assembly line interface is also trying to call for No Network and other abnormal scene did not do exception handling. Therefore, call the client should still be prepared to handle the load balancing and failover.
  • More elegant manner, corresponding to the right application will stop the first resetting to 0, then no call upstream of this application. This time to stop the operation of the application did not affect the service subscribers, of course, this scenario requires subscribers to achieve by the weight of the load balancing operation and maintenance and deployment tools combined depth.

Health Inspection Service is how to do?

Health Check is divided into client and server heartbeat active detection in two ways.

  • The client heartbeat

  • The client sends regular intervals "heartbeat" way to indicate to the server service status of their normal heartbeat may be in the form of TCP, also in the form of HTTP.

  • It can also connect a client to realize his way through the heart to maintain a long socket client and server.

  • ZooKeeper not actively transmitting a heartbeat, but rely on the characteristics of the component itself provides temporary nodes, the nodes maintained by the session ZooKeeper temporary connection.

But the client heartbeat, the heartbeat active and maintain a long connection of clients just show normal on the link, the service status is not necessarily normal.

The server automatically call service health check is a more accurate way to return the results show the success of the service status is indeed normal.

  • Active detection server
  • The server calls the service publisher HTTP interface to complete a health check.
  • For the HTTP service does not provide RPC application, the server call interface service publisher to complete the health check.
  • You can perform a comprehensive inspection by the form of a script.

Server active detection is also problematic. Service registry automatically call RPC service can not be done on an interface versatility; in many scenes service registry to network service publisher is unreasonable, the server can not initiate a health check.

So how to choose, still need to be decided according to the actual situation, according to different scenarios, choose different strategies.

Service Discovery

How to find the address of the service discovery server?

  • Specify the address of the service centers registered in the application's configuration file, similar to the zookeeper and eureka.
  • Specify the address of a server address, and then to get the address of the service registry by this address of the server, the server returns the address of the results will be updated with the service registry of scaling capacity.

When the service nodes with new nodes join or quit, subscribers receive timely notice how?

Classic Push and Pull problem.

Push two of the Classical, notify socket connection length, such as the typical implementation based ZooKeeper; Long Polling is another HTTP connections.

However notify message loss problem based on long socket connection notify and HTTP-based protocol Long Polling will.

It is also necessary, by way of the timing polling Pull choose also critical time interval, the higher the frequency of the service registry greater the pressure. Scale requires a combination of performance and service side of the business of trade-offs.

There is another way, true Push, the client opens a UDP server, service registry data to push through UDP way, of course, this is also limited by the connectivity of the network.

I can easily see what I publish and subscribe to the service, a subscription service which nodes it?

  • A good product, user experience and operation and maintenance experience must be elegant, to see if the machine publish and subscribe to the service, only by looking at the logs, even jmap way to get, obviously very bad experience.

  • Service registry should provide a rich interface, support depending on the application name, IP, subscribe to the service name, service name published, to carry out multi-level combined query.

  • At the same time, the client's memory, should also publish various information and reservation service subscriptions, and provide a way for people to easily query.
  • For example, in Java applications Spring Boot, and can be combined actuator endpoint, to provide native HTTP service queries by the way, check this application publishing services, as well as the corresponding node subscription services and various services.

Disaster recovery and high availability

How Performance

When the service nodes rises, the performance of a service registry will become a bottleneck, this time on the need to improve the performance of the cluster service registry through the horizontal expansion. 

  • For those using a strong consistency class Paxos protocol components, such as the ZooKeeper, since more than half of each write operation requires confirmation node. Expansion can not raise the level of the entire cluster write performance can only improve the reading performance of the entire cluster. 
  • As for the use of eventual consistency of components, the level of expansion can improve write performance and read performance of the entire cluster simultaneously.

Client disaster recovery strategy

  1. First, the local memory cache, and the connection is lost when running the service registry or registry service completely down, still normal call service.

  2. The local cache files, applications and services when the registration center network partition or registered service center is fully down, the application is restarted operations, memory is no data, then the application may be obtained by reading the data in the local cache file last subscriptions to content.

  3. Finally, local disaster recovery folder. Under normal circumstances, disaster recovery folder is not the content. When the server is fully and prolonged downtime can not be restored, while the service provider has undergone great changes, you can turn a local disaster recovery by adding a file in the file folder disaster recovery mode. At this point the client will ignore the original local cache file, just read the configuration file from the local disaster recovery.

Disaster recovery and high availability server

  • When a new node joins the cluster, the node starts automatically added to the address of the server, and find the address of the server through other nodes automatically synchronize data from other nodes to reach the final data consistency. 
  • When a node goes down, the information will be automatically registered for this service center address of the server node removal, the client can promptly perceive this node offline. 

Stateless server ensures thin disaster recovery and high availability services can do.

How secure is the server do?

Link security, service registry for use HTTP connection, the best way to protect the security of the link is using HTTPS. The service registry using TCP connections, because the application layer protocol generally used by private agreement, there is not necessarily ready TLS support programs.

In the security business, it should be in every release, subscriptions, heartbeat, authentication information are put on the line to sign inspection and authentication to ensure the security of business information.

Alibaba Naming Service

ANS (Alibaba Naming Service) is the middleware team for many years Alibaba business practices precipitation polished open-source products. Service registration and discovery in respect, ANS combines the advantages of these solutions is the most suitable for cloud-native application service registration and discovery components.
ANS has been in service on the line EDAS (Ali Baba enterprise distributed application services), is now available for Spring Cloud Ans Starter Spring Cloud convenient user directly using a secure and reliable commercial version of the service registration and discovery. ANS perfectly support the characteristics of Eureka, and is now completely free! For more information see  EDAS help documentation .

Guess you like

Origin www.cnblogs.com/xichji/p/11946768.html