Integrating Service Discovery and Registration with API7 Enterprise

Zhihuang Lin

Zhihuang Lin

June 13, 2024

Products

With the widespread adoption of microservices architecture, the relationships between services are becoming increasingly complex. In this context, service discovery is particularly important, as it allows services to dynamically locate and interact with each other.

API7 Enterprise, as a feature-rich API management platform, can seamlessly integrate with service discovery registries to achieve automatic discovery and intelligent routing of upstream services.

What Is Service Discovery?

Service discovery is a mechanism for automatically detecting service instances and their addresses within a network so that other services or clients can find and communicate with them. In modern distributed systems and microservices architecture, service discovery is a crucial component, as it enables the dynamic localization and connection to services without the need to hardcode service addresses or manually update configurations.

The Functions of Service Discovery

  1. Dynamic Service Localization: In microservices architecture, service instances may dynamically start, stop, migrate, or scale. Service discovery can automatically track these changes, ensuring that clients can always find available service instances.

  2. Fault Tolerance and Failover: When a service instance fails, service discovery can detect its unavailability and direct clients to connect to other healthy instances, enabling failover and high availability.

  3. Simplified Configuration and Management: Through service discovery, developers do not need to manually configure and manage the network addresses of each service. This reduces the possibility of configuration errors and simplifies the deployment and management of services.

Service Discovery in API7 Enterprise

Service discovery is often used in conjunction with a load balancer or API gateway to ensure that requests are evenly distributed across multiple service instances, thus improving system throughput and response time. In distributed systems, service instances may become unavailable due to various reasons, and the service discovery mechanism can quickly identify these issues and redirect requests to other healthy service instances through the load balancer, ensuring high availability of the services.

In API7 Enterprise, the concept of "upstream" further expands this flexibility. By configuring upstream as a service registry, the API gateway can dynamically retrieve the list of backend service instances and adjust the request distribution strategy as needed. This means that even when the number or state of service instances changes, the API gateway can quickly adapt, without the need for manual configuration updates or service restarts.

The collaboration between service discovery and the API gateway provides powerful dynamic service management and traffic control capabilities for microservices architecture. API7 Enterprise further enhanced and extended this feature, allowing the system to be more flexible and efficient in addressing various complex scenarios and requirements. Moreover, with the widespread adoption of cloud-native and containerization technologies, the deployment and scaling of service instances have become easier and faster.

How to Configure Service Discovery in API7 Enterprise?

Adding Service Registries

In the gateway group, go to the service registry page, click on the "Add Service Registry Connection" button, and you'll see the connection form.

Add Service Registry Connection in API7 Enterprise

In the form, we need to fill in the basic information and relevant connection configurations for the service registry. Currently, API7 Enterprise supports the integration of Kubernetes and Nacos service registries. Here, we'll use Nacos as an example. Select "Nacos" as the discovery type, and then specify how API7 Enterprise will obtain the token for authentication, which can be done through account/password, access key, and secret key, or by directly inputting the token value.

Add Information of Service Registry

In addition to the basic authentication configurations, API7 Enterprise also provides more fine-grained configuration options, such as connection timeout and read/write timeout. These configurations can be flexibly adjusted based on actual needs, effectively avoiding long-pending requests caused by unstable network connections, and reducing the inefficient use of system resources.

After creating the service registry, the new connection item will immediately appear in the list, but the connection status can be marked as healthy after the system's check. Through this connection item, users can conveniently check the service discovery status and the relevant configurations of the service registry.

Add Service Registry Connection

Configuring Service Discovery in the Upstream

The service registry is a resource that belongs to the gateway group. In the gateway group where the service registry has been created, any service published to that gateway group can use the configuration of this service registry. We can configure upstream during the service publishing process or on a published service.

Select a service template, publish it to the gateway group that just added the service registry, choose to use service discovery as the upstream, then select the Nacos service registry we just created, and choose the specific namespace, group, and instance.

Configuring Service Discovery in Upstream

After the service is published, you can view the currently configured service registry on the upstream page of the service details, and make changes to the service discovery configuration at any time.

Service Registry in Upstream Page

View Associated Services, Update and Delete Connection Configurations

In the list of service registries, through the "More" menu on the right, you can conveniently manage the connection configurations, view the connection history, track the usage of the service, or delete the connection configurations that are no longer needed.

Status Checking of Service Registry

The "Associated Services" clearly shows which services have changed their service discovery configurations, allowing us to evaluate the potential impact before making any configuration changes, effectively avoiding operational risks.

Associated Services

Please note that updating the connection configurations of the service registry will affect all upstream services using that registry. If there are already upstream services using it, you cannot change the discovery type of the registry or directly delete the connection. You need to manually adjust the upstream service configurations to use other registries or nodes first, and then perform the deletion operation.

Delete Service Registry Connection When Upstreams Unused

Conclusion

We have walked through the detailed concept of service discovery, its role, and its application in API7 Enterprise. Through service discovery, microservices architecture can dynamically manage and invoke services, greatly improving the flexibility and availability of the system.

As microservices architecture continue to evolve, the importance of service discovery is becoming increasingly evident. We expect that service discovery will focus more on intelligence, automation, and fault tolerance in the future.

API7 Enterprise will explore integration with more types of service registries, and combine health checks to achieve stronger high availability, helping enterprises build more robust and efficient microservice architectures.

Tags:
Service DiscoveryAPI7 Enterprise