Method and system for realizing enterprise-level api gateway based on netty, nacos and disruption

By adopting netty, nacos and disruptor technologies in the API gateway system, a high-performance, scalable and secure gateway core processor and filter chain is built, which solves the performance bottlenecks, poor scalability and insufficient security of the existing API gateway system. The problem is to achieve an efficient, stable and flexible gateway system.

CN119449530APending Publication Date: 2025-02-14SHANDONG LANGCHAO YUNTOU INFORMATION TECH CO LTD
View PDF 8 Cites 0 Cited by

Patent Information

Application Number
CN202411405855.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-10
Publication Date
2025-02-14

AI Technical Summary

Technical Problem

The existing API gateway systems have problems such as performance bottlenecks, poor scalability, and insufficient security.

Method used

Using a netty, nacos and disruptor-based approach, build a scalable gateway core context interface, Netty core processor, access to Nacos registration center and configuration center, build a pluggable filter chain, and optimize internal messaging using the Disruptor framework. mechanism.

Benefits of technology

It improves the overall processing capacity and throughput of the gateway, enhances the scalability and security of the system, and ensures the stability and performance of the gateway in high concurrency scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119449530A_ABST
    Figure CN119449530A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of gateway systems, in particular to a method and system for achieving an enterprise-level api gateway based on netty, nacos and disruption, and the method comprises the following steps: constructing an extensible gateway core context interface; implementation of construction of a Netty core processor is achieved; accessing a Nacos registration center and a configuration center; constructing a pluggable filter chain; an internal message transmission mechanism is optimized by utilizing a Disruptor framework; the method and the system for realizing the enterprise-level api gateway based on the netty, the nacos and the disruption have the beneficial effects that function customization can be carried out according to specific business requirements of an enterprise through the self-developed gateway, such as supporting a specific protocol, realizing specific business logic and the like, according to the method and the system for realizing the enterprise-level api gateway based on the netty, the nacos and the disruption. Therefore, seamless integration of enterprises and back-end services is facilitated, and the efficiency and accuracy of business processing are improved. Through function customization and expansion of the self-developed gateway, the problems that functions do not meet requirements and source codes need to be modified when an open source gateway is used by an enterprise can be avoided, so that the development efficiency is improved, and the development cost is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of gateway systems, and in particular to a method and system for realizing an enterprise-level API gateway based on Netty, Nacos and Disruptor. Background Art

[0002] With the popularity of microservice architecture, API gateway, as a key component in microservice architecture, plays an increasingly prominent role. API gateway is responsible for processing requests from clients, routing them to corresponding backend services, and providing security, monitoring, current limiting and other functions.

[0003] However, existing API gateway systems often have problems such as performance bottlenecks, poor scalability, and insufficient security. Summary of the invention

[0004] The purpose of the present invention is to provide a method and system for implementing an enterprise-level API gateway based on Netty, Nacos and Disruptor to solve the problems raised in the above background technology.

[0005] To achieve the above object, the present invention provides the following technical solution: a method for implementing an enterprise-level API gateway based on Netty, Nacos and Disruptor, the method comprising the following steps:

[0006] Build the extensible gateway core context interface;

[0007] Build the implementation of Netty core processor;

[0008] Access the Nacos registration center and configuration center;

[0009] Build pluggable filter chains;

[0010] The Disruptor framework is used to optimize the internal message passing mechanism, specifically: High-performance message queue: Use the Disruptor framework to build an efficient message queue to achieve efficient and low-latency message passing between components within the gateway, and improve the overall processing capability and throughput of the gateway; Lock-free concurrency: Disruptor reduces contention between threads through lock-free design, improves concurrent processing capabilities, and ensures the stability and performance of the gateway in high-concurrency scenarios.

[0011] Preferably, constructing the extensible gateway core context interface specifically includes:

[0012] The interface encapsulates the request execution status, request end flag, request protocol and protocol conversion rule attributes, and provides functions for setting the context status to normal operation, obtaining the Netty context, releasing resources and function callback to achieve high customizability and scalability of the gateway processing flow.

[0013] Preferably, the implementation of building the Netty core processor specifically includes:

[0014] Define the NettyProcessor interface: The interface defines routing functions, asynchronous configuration processing, exception handling, response information writing back, and resource release core methods to ensure that the gateway can process network requests efficiently and stably;

[0015] Implement the Complete method: This method is used to complete the request processing flow, including the encapsulation and sending of response data and resource cleanup, to ensure the integrity of the request processing flow and the efficient use of resources.

[0016] Preferably, accessing the Nacos registration center and configuration center specifically includes:

[0017] Service registration and discovery: Through the Nacos registration center, service providers register service information, and service consumers dynamically discover service instances, thus achieving automatic registration, discovery, and load balancing of services;

[0018] Dynamic configuration management: Nacos configuration center is used to manage the configuration information of gateways and backend services in a centralized, externalized and dynamic manner. It supports dynamic updates of configurations, which can take effect without restarting the service, thus improving the flexibility and response speed of the system.

[0019] Preferably, building a pluggable filter chain specifically includes:

[0020] Adopt the chain of responsibility model: Organize filters through the chain of responsibility model, allowing requests to be processed by multiple filters in sequence when passing through the gateway, such as authentication, authorization, current limiting, circuit breaking, and logging, to enhance the security and functionality of the gateway;

[0021] Dynamic scalability: Supports dynamic addition, deletion or replacement of filters according to business needs without modifying the core code of the gateway, improving the scalability and maintainability of the system.

[0022] A system for implementing an enterprise-level API gateway based on Netty, Nacos and Disruptor, the system comprising:

[0023] The extensibility gateway core context module defines the core context interface, which encapsulates the following functions:

[0024] Request status management: used to record the status of the request being executed and whether the request has been completed;

[0025] Protocol and conversion rules: including the requested protocol type and protocol conversion rules;

[0026] State setting and acquisition: Provides methods to set the context state to normal operation state and allows obtaining the Netty context;

[0027] Resource management and callback: Implement resource release function and function callback mechanism to ensure effective resource management and process control.

[0028] Preferably, a Netty core processor module is also included, which defines the NettyProcessor interface and implements the following main functions:

[0029] Routing function: implement routing functions to direct requests to the correct backend services;

[0030] Asynchronous configuration processing: supports the acquisition and processing of asynchronous configurations to ensure timely update and application of configuration information;

[0031] Exception handling and response: Provides an exception handling mechanism, and can write back response information after processing is completed, while releasing related resources;

[0032] Complete method implementation: Define and implement the Complete method, which is used to complete resource cleanup and status update of the entire request processing flow.

[0033] Preferably, it also includes a module for accessing the Nacos registration center and configuration center, specifically including:

[0034] Service registration and discovery: Service registration and discovery are realized through the Nacos registration center, so that service providers can register service information and service consumers can obtain a list of service instances and make calls;

[0035] Dynamic configuration management: Use Nacos Configuration Center to realize centralized, externalized and dynamic management of application configuration and service configuration, including dynamic update of database connection information, cache configuration, log level and routing rules, which can take effect without restarting the service.

[0036] Preferably, a pluggable filter chain module is also included, including the following functions:

[0037] Implementation of the chain of responsibility model: Filters are organized through the chain of responsibility model, allowing requests to be processed through a series of filters, including authentication, authorization, current limiting, circuit breaking, and logging, to ensure the validity and security of the request;

[0038] Dynamic scalability: Supports dynamic addition, deletion, or replacement of filters based on business needs without large-scale modifications to the overall architecture, improving system flexibility and scalability.

[0039] Preferably, the internal message transmission mechanism is optimized by using the Disruptor framework, specifically:

[0040] High-performance message queue: Use the Disruptor framework to build an efficient message queue, achieve efficient and low-latency message transmission between components within the gateway, and improve the overall processing power and throughput of the system;

[0041] Lock-free concurrent processing: Utilize the lock-free design of Disruptor to reduce contention between threads, improve concurrent processing capabilities, and ensure system stability and performance in high-concurrency scenarios.

[0042] Compared with the prior art, the present invention has the following beneficial effects:

[0043] The method and system for implementing an enterprise-level API gateway based on Netty, Nacos and Disruptor proposed in the present invention can customize functions according to the specific business needs of the enterprise through the self-developed gateway, such as supporting specific protocols, implementing specific business logic, etc. This helps enterprises achieve seamless integration with back-end services and improve the efficiency and accuracy of business processing. Through the function customization and expansion of the self-developed gateway, enterprises can avoid problems such as functions not meeting requirements and the need to modify source code when using open source gateways, thereby improving development efficiency and reducing development costs.

[0044] High performance and low latency Netty adopts an asynchronous event-driven model based on NIO, which can handle a large number of concurrent connections and requests without creating a thread for each connection. This design can make full use of system resources and reduce the overhead of thread switching, thereby improving system throughput and reducing latency. Netty supports zero-copy technology and can directly send file data to the target channel, avoiding frequent data copying and memory allocation in traditional I / O operations, further improving the throughput and processing efficiency of the gateway.

[0045] High concurrency performance, lock-free design, memory barrier mechanism, and ring array structure optimization methods provide extremely high concurrent processing capabilities. This enables the self-developed gateway to maintain efficient response speed and throughput when dealing with large-scale concurrent requests, meeting the requirements of real-time and high reliability. Low-latency message processing is achieved. This low-latency feature is crucial for real-time applications that require fast responses. Using Disruptor can ensure that the self-developed gateway has extremely low latency when processing requests and responses, improving user experience and overall system performance. BRIEF DESCRIPTION OF THE DRAWINGS

[0046] Figure 1 The figure is a flow chart of the method of the present invention. DETAILED DESCRIPTION

[0047] In order to make the purpose and technical solution of the present invention clearly and completely described, and the advantages more clearly understood, the embodiments of the present invention are further described in detail with reference to the accompanying drawings. It should be understood that the specific embodiments described herein are part of the embodiments of the present invention, rather than all of the embodiments, and are only used to explain the embodiments of the present invention, and are not used to limit the embodiments of the present invention. All other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0048] For example, see Figure 1 The present invention provides a technical solution: a method for implementing an enterprise-level API gateway based on Netty, Nacos and Disruptor, the method comprising the following steps:

[0049] ①Building the core function of the gateway - context definition of scalability

[0050] Define the core context interface. This interface mainly encapsulates the status of a request being executed, whether the request ends the request protocol, protocol conversion rules and other properties, sets the context status to normal operation, obtains the Netty context, resource release function, function callback function, etc.

[0051] / **

[0052] *A request is in progress

[0053] * /

[0054] int RUNNING = 0;

[0055] / **

[0056] * Get request conversion protocol

[0057] * @return

[0058] * /

[0059] String getProtocol();

[0060] / **

[0061] * Get request conversion protocol

[0062] * @return

[0063] * /

[0064] Rule getRule();

[0065] / **

[0066] *Get Netty context* /

[0067] ur ChannelHandlerContext getNettyCtx();

[0068] / **

[0069] * Release resources

[0070] * /

[0071] void releaseRequest();

[0072] / **

[0073] *Set callback function

[0074] * @param consumer

[0075] * /

[0076] void setCompletedCallBack(Consumer <icontext>consumer);

[0077] / **

[0078] *Set callback function

[0079] * @param consumer

[0080] * /

[0081] void invokeCompletedCallBack(Consumer <icontext>②Build the core function of the gateway-the netty core processor implements the main function

[0082] Building the netty core processor requires defining the nettyprocessor interface, implementing routing functions, obtaining asynchronous configuration implementation complete methods, exception handling, writing back response information, and releasing resources.

[0083] public void process(HttpRequestWrapper wrapper){

[0084] FullHttpRequest request=wrapper.getRequest();

[0085] ChannelHandlerContext ctx=wrapper.getCtx();

[0086] try{

[0087] GatewayContext gatewayContext=RequestHelper.doContext(request,ctx);

[0088] route(gatewayContext);

[0089] }catch(BaseException e){

[0090] log.error("process error{}{}",e.getCode().getCode(),e.getCode().getMessage());

[0091] FullHttpResponse httpResponse=ResponseHelper.getHttpResponse(e.getCode());

[0092] doWriteAndRelease(ctx,request,httpResponse);

[0093] }catch(Throwable t){

[0094] log.error("process unknown error",t);

[0095] FullHttpResponse httpResponse=ResponseHelper.getHttpResponse(ResponseCode.INTERNAL_ERROR);

[0096] doWriteAndRelease(ctx,request,httpResponse);

[0097] }

[0098] }

[0099] private void doWriteAndRelease(ChannelHandlerContext ctx,FullHttpRequest request,FullHttpResponse httpResponse){

[0100] ctx.writeAndFlush(httpResponse)

[0101] .addListener(ChannelFutureListener.CLOSE); / / Close the channel after releasing resources

[0102] ReferenceCountUtil.release(request);

[0103] }

[0104] ③Access the registration center and configuration center

[0105] Gateway access registration center and configuration center Through the Nacos registration center, the gateway can easily manage and maintain various services in the system. Service providers can register their service information in Nacos, and service consumers can obtain a list of available service instances through Nacos and call them as needed.

[0106] Nacos' configuration center allows the gateway to manage application configuration and service configuration of all environments in a centralized, externalized and dynamic manner. This includes database connection information, cache configuration, log level, routing rules, etc.

[0107] Dynamic configuration services eliminate the need to redeploy applications and services when configuration changes occur, making configuration management more efficient and agile. Centralized configuration management makes it easier to implement stateless services and to elastically scale services on demand.

[0108] ④Pluggable filter chain

[0109] By implementing the filter chain through the chain of responsibility pattern, continuous requests can pass through different filters.

[0110] Customized filter chains allow the gateway to dynamically add, delete, or replace filters based on specific needs. This flexibility enables the gateway to adapt to different application scenarios and business needs without large-scale modifications to the overall architecture. At the same time, the functionality of the gateway can be easily expanded by adding new filters. The filter chain can perform a series of processes on requests passing through the gateway, such as authentication, authorization, current limiting, fuses, logging, etc. These processes can be performed before the request reaches the backend service, thereby ensuring the validity and security of the request. .

[0111] Embodiment 2, based on embodiment 1, proposes a system for implementing an enterprise-level API gateway based on Netty, Nacos and Disruptor, the system comprising:

[0112] The extensible gateway core context module defines the core context interface, which encapsulates the following functions: request status management: used to record the status of the request being executed and whether the request has ended; protocol and conversion rules: including the requested protocol type and the rules for protocol conversion; state setting and acquisition: provides a method for setting the context state to the normal operating state and allows obtaining the Netty context; resource management and callback: implements resource release function and function callback mechanism to ensure effective resource management and process control.

[0113] Netty core processor module, and implements the following main functions: routing function: implement routing function to direct requests to the correct backend service; asynchronous configuration processing: support asynchronous configuration acquisition and processing to ensure timely update and application of configuration information; exception handling and response: provide exception handling mechanism, and can write back response information after processing is completed, and release related resources at the same time; Complete method implementation: define and implement the Complete method, which is used to complete resource cleanup and status update of the entire request processing process.

[0114] The modules connected to the Nacos registration center and configuration center include: Service registration and discovery: Service registration and discovery are realized through the Nacos registration center, so that service providers can register service information and service consumers can obtain a list of service instances and call them; Dynamic configuration management: Using the Nacos configuration center, the application configuration and service configuration are centralized, externalized, and dynamic, including the dynamic update of database connection information, cache configuration, log level, and routing rules, which can take effect without restarting the service.

[0115] The pluggable filter chain module includes the following functions: Chain of responsibility pattern implementation: Filters are organized through the chain of responsibility pattern, allowing requests to be processed through a series of filters, including authentication, authorization, current limiting, circuit breaking, and logging, to ensure the validity and security of the request; Dynamic scalability: Supports dynamic addition, deletion, or replacement of filters according to business needs without large-scale modifications to the overall architecture, thereby improving the flexibility and scalability of the system.

[0116] The Disruptor framework is used to optimize the internal message passing mechanism, specifically: High-performance message queue: The Disruptor framework is used to build an efficient message queue to achieve efficient and low-latency message passing between internal components of the gateway, improving the overall processing power and throughput of the system; Lock-free concurrent processing: The lock-free design of the Disruptor is used to reduce contention between threads, improve concurrent processing capabilities, and ensure the stability and performance of the system in high-concurrency scenarios.

[0117] Although embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions and variations may be made to the embodiments without departing from the principles and spirit of the present invention, and that the scope of the present invention is defined by the appended claims and their equivalents.< / icontext> < / icontext>

Claims

1. A method for implementing an enterprise-level API gateway based on Netty, Nacos and Disruptor, characterized in that: The method comprises the following steps: Build the extensible gateway core context interface; Build the implementation of Netty core processor; Access the Nacos registration center and configuration center; Build pluggable filter chains; The Disruptor framework is used to optimize the internal message passing mechanism, specifically: High-performance message queue: Use the Disruptor framework to build an efficient message queue to achieve efficient and low-latency message passing between components within the gateway, and improve the overall processing capability and throughput of the gateway; Lock-free concurrency: Disruptor reduces contention between threads through lock-free design, improves concurrent processing capabilities, and ensures the stability and performance of the gateway in high-concurrency scenarios.

2. According to claim 1, a method for implementing an enterprise-level API gateway based on Netty, Nacos and Disruptor, characterized in that: Building the core context interface of the scalable gateway specifically includes: The interface encapsulates the request execution status, request end flag, request protocol and protocol conversion rule attributes, and provides functions for setting the context status to normal operation, obtaining the Netty context, releasing resources and function callback to achieve high customizability and scalability of the gateway processing flow.

3. According to claim 1, a method for implementing an enterprise-level API gateway based on Netty, Nacos and Disruptor, characterized in that: The implementation of building the Netty core processor specifically includes: Define the NettyProcessor interface: The interface defines routing functions, asynchronous configuration processing, exception handling, response information writing back, and resource release core methods to ensure that the gateway can process network requests efficiently and stably; Implement the Complete method: This method is used to complete the request processing flow, including the encapsulation and sending of response data and resource cleanup, to ensure the integrity of the request processing flow and the efficient use of resources.

4. According to claim 1, a method for implementing an enterprise-level API gateway based on Netty, Nacos and Disruptor, characterized in that: Accessing the Nacos registration center and configuration center specifically includes: Service registration and discovery: Through the Nacos registration center, service providers register service information, and service consumers dynamically discover service instances, thus achieving automatic registration, discovery, and load balancing of services; Dynamic configuration management: Nacos configuration center is used to manage the configuration information of gateways and backend services in a centralized, externalized and dynamic manner. It supports dynamic updates of configurations, which can take effect without restarting the service, thus improving the flexibility and response speed of the system.

5. According to claim 1, a method for implementing an enterprise-level API gateway based on Netty, Nacos and Disruptor, characterized in that: Building a pluggable filter chain specifically involves: Adopt the chain of responsibility model: Organize filters through the chain of responsibility model, allowing requests to be processed by multiple filters in sequence when passing through the gateway, such as authentication, authorization, current limiting, circuit breaking, and logging, to enhance the security and functionality of the gateway; Dynamic scalability: Supports dynamic addition, deletion or replacement of filters according to business needs without modifying the core code of the gateway, improving the scalability and maintainability of the system.

6. A method for implementing an enterprise-level API gateway based on Netty, Nacos and Disruptor according to any one of claims 1 to 5, a system for implementing an enterprise-level API gateway based on Netty, Nacos and Disruptor, characterized in that: The system comprises: The extensibility gateway core context module defines the core context interface, which encapsulates the following functions: Request status management: used to record the status of the request being executed and whether the request has been completed; Protocol and conversion rules: including the requested protocol type and protocol conversion rules; State setting and acquisition: Provides methods to set the context state to normal operation state and allows obtaining the Netty context; Resource management and callback: Implement resource release function and function callback mechanism to ensure effective resource management and process control.

7. According to claim 6, a method and system for implementing an enterprise-level API gateway based on Netty, Nacos and Disruptor, further comprising a Netty core processor module, characterized in that: This module defines the NettyProcessor interface and implements the following main functions: Routing function: implement routing functions to direct requests to the correct backend services; Asynchronous configuration processing: supports the acquisition and processing of asynchronous configurations to ensure timely updating and application of configuration information; Exception handling and response: Provides an exception handling mechanism, and can write back response information after processing is completed, while releasing related resources; Complete method implementation: Define and implement the Complete method, which is used to complete resource cleanup and status update of the entire request processing flow.

8. According to claim 6, a method and system for implementing an enterprise-level API gateway based on Netty, Nacos and Disruptor, further comprising a module for accessing a Nacos registration center and a configuration center, characterized in that: Specifically include: Service registration and discovery: Service registration and discovery are realized through the Nacos registration center, so that service providers can register service information and service consumers can obtain a list of service instances and call them; Dynamic configuration management: Use Nacos Configuration Center to realize centralized, externalized and dynamic management of application configuration and service configuration, including dynamic update of database connection information, cache configuration, log level and routing rules, which can take effect without restarting the service.

9. According to claim 6, a method and system for implementing an enterprise-level API gateway based on Netty, Nacos and Disruptor, further comprising a pluggable filter chain module, characterized in that: Features include: Implementation of the chain of responsibility model: Filters are organized through the chain of responsibility model, allowing requests to be processed through a series of filters, including authentication, authorization, current limiting, circuit breaking, and logging, to ensure the validity and security of the request; Dynamic scalability: Supports dynamic addition, deletion, or replacement of filters based on business needs without large-scale modifications to the overall architecture, improving system flexibility and scalability.

10. According to claim 6, a method and system for implementing an enterprise-level API gateway based on Netty, Nacos and Disruptor, further comprising optimizing the internal message delivery mechanism using the Disruptor framework, characterized in that: Specifically: High-performance message queue: Use the Disruptor framework to build an efficient message queue, achieve efficient and low-latency message transmission between components within the gateway, and improve the overall processing power and throughput of the system; Lock-free concurrent processing: Utilize the lock-free design of Disruptor to reduce contention between threads, improve concurrent processing capabilities, and ensure system stability and performance in high-concurrency scenarios.

Citation Information

Patent Citations

  • Data sending and receiving method based on Disruptor

    CN106802824A

  • Internet of things multifunctional gateway based on NB-IoT

    CN107465608A

  • Message forwarding and receiving gateway system based on bank multi-communication protocol

    CN113612681A

  • Processing method and system of high-performance gateway system based on Netty

    CN113641410A

  • Data pushing method and device

    CN113765984A