CN116633727A - Gateway dynamic routing method, device, computer equipment and computer readable storage medium based on Nacos service - Google Patents

Gateway dynamic routing method, device, computer equipment and computer readable storage medium based on Nacos service Download PDF

Info

Publication number
CN116633727A
CN116633727A CN202310625897.6A CN202310625897A CN116633727A CN 116633727 A CN116633727 A CN 116633727A CN 202310625897 A CN202310625897 A CN 202310625897A CN 116633727 A CN116633727 A CN 116633727A
Authority
CN
China
Prior art keywords
gateway
service
route
configuration
configuration file
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202310625897.6A
Other languages
Chinese (zh)
Inventor
刘欣毅
张波
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Insight Network Co ltd
Original Assignee
Beijing Insight Network Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Insight Network Co ltd filed Critical Beijing Insight Network Co ltd
Priority to CN202310625897.6A priority Critical patent/CN116633727A/en
Publication of CN116633727A publication Critical patent/CN116633727A/en
Pending legal-status Critical Current

Links

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L12/00Data switching networks
    • H04L12/66Arrangements for connecting between networks having differing types of switching systems, e.g. gateways
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L41/00Arrangements for maintenance, administration or management of data switching networks, e.g. of packet switching networks
    • H04L41/08Configuration management of networks or network elements
    • H04L41/0803Configuration setting
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L41/00Arrangements for maintenance, administration or management of data switching networks, e.g. of packet switching networks
    • H04L41/08Configuration management of networks or network elements
    • H04L41/0803Configuration setting
    • H04L41/0813Configuration setting characterised by the conditions triggering a change of settings
    • H04L41/082Configuration setting characterised by the conditions triggering a change of settings the condition being updates or upgrades of network functionality
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L45/00Routing or path finding of packets in data switching networks
    • H04L45/02Topology update or discovery
    • H04L45/028Dynamic adaptation of the update intervals, e.g. event-triggered updates

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Data Exchanges In Wide-Area Networks (AREA)
  • Computer And Data Communications (AREA)

Abstract

The application discloses a gateway dynamic routing method, device, computer equipment and computer readable storage medium based on Nacos service, and relates to the technical field of gateway routing. The method comprises the steps of firstly completing route configuration file creation, gateway micro-service creation, gateway Config. java file creation, interface inheritance class creation and change monitoring class creation in sequence in response to man-machine interaction operation, then monitoring the change of the route configuration file based on an added monitor, and finally triggering and calling a dynamic route definition mode to update the changed route configuration file into an application process of a Gateway when the monitor receives configuration update information, so that the purposes of monitoring the route and automatically effecting without restarting the Gateway service can be achieved based on configuration of the Nacos service, and the operation can be greatly simplified without adding configuration information of a database in the Gateway service, and the actual application and popularization are facilitated.

Description

Gateway dynamic routing method, device, computer equipment and computer readable storage medium based on Nacos service
Technical Field
The application belongs to the technical field of gateway routing, and particularly relates to a gateway dynamic routing method, device, computer equipment and computer readable storage medium based on Nacos service.
Background
The business system refers to business links required by the enterprise to achieve positioning, roles played by each partner, and manners and contents of stakeholders to cooperate and trade. The gateway serves as the only traffic portal for the service system and encapsulates the system internal architecture so that all requests first go through the gateway and then the gateway routes the requests to the appropriate Microservices (Microservices, a style of software architecture that is based on small functional blocks focusing on single responsibilities and functions, combining complex large applications in a modular fashion, each functional block communicating with each other using a language independent API set).
Static Routing is a conventional Routing method, and Routing entries (Routing Entry) are manually configured by users (generally, static Routing is performed by a network administrator to add Routing tables item by item), so that Routing information is fixed and does not change even if network conditions have changed or are reconfigured. Thus, if a new micro service is added, the gateway service needs to be reconfigured and then restarted. Compared with static routing, dynamic routing (which means that a router can automatically establish its own routing table and can adjust timely according to the change of actual conditions) has the advantages of modifying, adding or deleting routing configuration, and can be dynamically effective without restarting gateway services.
Currently, the dynamic routing manner based on the Spring Cloud Gateway gateway (which is a brand new item of Spring Cloud, the item is a gateway developed based on technologies such as Spring 5.0, spring Boot 2.0 and Project Reactor, and the like, and aims to provide a simple, effective and unified API routing management manner for a micro-service architecture) mainly comprises the following two types: a scheme for realizing dynamic routing based on Mysql+API and a scheme for realizing dynamic routing based on Redis+API. The two schemes are basically one scheme, and the data storage modes are different, so that the general implementation thinking is as follows: the route adding, deleting and checking interface is defined through an API (Application Programming Interface ) interface, route information is modified through the API interface, and modified data is stored in a Mysql database or a Redis non-relational database and the route is refreshed to achieve the purpose of dynamic update. However, this method requires adding configuration information of Mysql database or Redis non-relational database in Gateway service, which results in complicated operation, so how to provide a new dynamic routing scheme which is simpler and suitable for Spring Cloud Gateway Gateway is a subject of urgent study for those skilled in the art.
Disclosure of Invention
The application aims to provide a Gateway dynamic routing method, a device, computer equipment and a computer readable storage medium based on Nacos service, which are used for solving the problem that the operation is complicated because of the need of adding the configuration information of a Mysql database or a Redis non-relational database in Gateway service in the existing dynamic routing scheme based on a Spring Cloud Gateway Gateway.
In order to achieve the above purpose, the present application adopts the following technical scheme:
in a first aspect, there is provided a method for dynamically routing a gateway based on a Nacos service, performed by a server communicatively connecting a router based on a Spring Cloud Gateway gateway, comprising:
responding to a first man-machine interaction operation, starting Nacos service, and creating a route configuration file in a NacosConfig configuration center of the Nacos service, wherein the route configuration file contains at least one piece of route information of initial configuration;
responding to a second man-machine interaction operation, creating Gateway micro-service, and adding a service configuration file, wherein the service configuration file comprises a designated storage address of the routing configuration file and configured related data for dynamic routing of the Gateway;
responding to a third man-machine interaction operation, and creating a gateway Config.java file, wherein the gateway Config.java file comprises the storage address and the related data read from the service configuration file;
responding to the fourth man-machine interaction operation, creating a class to inherit an application EventPublisAware interface so as to inject an event publisher for the Gateway micro-service, so that the Gateway micro-service has the event publishing capability, and specifically comprises the following steps: completing initialization of event pushing handles and adding a dynamic route definition mode;
responding to the fifth man-machine interaction operation, creating another class to monitor the change of the routing configuration file, and specifically comprising: designating a current object to depend on the gateway config.java file, initializing configuration content aiming at the Nacos service, designating a route configuration path through the NacosConfig configuration center to acquire the route configuration file, and adding a monitor to the NacosConfig configuration center to monitor the change of the route configuration file;
when the monitor receives configuration updating information for indicating the change of the routing configuration file, triggering and calling the dynamic routing definition mode, and updating the changed routing configuration file into the application process of the Spring Cloud Gateway gateway.
Based on the above summary, a new dynamic routing scheme suitable for Spring Cloud Gateway Gateway is provided, namely, firstly, the creation of a routing configuration file, the creation of Gateway micro-service, the creation of Gateway config.java file, the creation of interface inheritance class and the creation of a change monitoring class are sequentially completed in response to man-machine interaction operation, then, the change of the routing configuration file is monitored based on an added monitor, finally, when the monitor receives configuration update information for indicating the change of the routing configuration file, a dynamic routing definition mode is triggered and invoked, and the changed routing configuration file is updated into the application process of Spring Cloud Gateway Gateway, so that the purposes of automatically effecting based on the configuration of Nacos service and without restarting Gateway service are achieved, and the operation is greatly simplified, thereby being convenient for practical application and popularization.
In one possible design, the related data includes a namespace of the NacosConfig configuration center, a configuration set unique identifier data-id, and/or a configuration group unique identifier group-id.
In one possible design, the initialization of the event push handle is completed, including: the initialization of the event pushing handle is completed by a mode of designating an event publisher application eventpublicher.
In one possible design, the dynamic route definition includes a user definition for adding route information, updating route information, and/or deleting route information.
In one possible design, in the dynamic route definition manner, the operation of reading the route information is implemented by a route definition locator, and the operation of adding, updating and/or deleting the route information is implemented by a route definition editor.
In one possible design, specifying that the current object depends on the gateway config. Java file includes: the current object is specified by @ DependsOn annotation to be dependent on the GateWayConfig.
In one possible design, initializing configuration content for the Nacos service includes: the storage address and a namespace of the NacosConfig configuration center in the related data are obtained as configuration content for the Nacos service.
In a second aspect, a gateway dynamic routing device based on Nacos service is provided, which is suitable for being arranged in a server of a router based on Spring Cloud Gateway gateway in communication connection, and comprises an operation response module and a trigger calling module which are in communication connection;
the operation response module is used for responding to the first man-machine interaction operation, starting the Nacos service, and creating a route configuration file in a NacosConfig configuration center of the Nacos service, wherein the route configuration file contains at least one piece of route information which is initially configured;
the operation response module is also used for responding to the second man-machine interaction operation, creating Gateway micro-service and adding a service configuration file, wherein the service configuration file comprises a designated storage address of the routing configuration file and configured related data for dynamic routing of the Gateway;
the operation response module is further used for responding to a third man-machine interaction operation to create a gateway Config.java file, wherein the gateway Config.java file contains the storage address and the related data read from the service configuration file;
the operation response module is further configured to create a class to inherit an application eventpublicherAware interface in response to the fourth man-machine interaction operation, so as to inject an event publisher application eventpublicher for the Gateway micro-service, so that the Gateway micro-service has the capability of publishing events, and specifically includes: completing initialization of event pushing handles and adding a dynamic route definition mode;
the operation response module is further configured to create another class to monitor a change of the routing configuration file in response to a fifth man-machine interaction operation, and specifically includes: designating a current object to depend on the gateway config.java file, initializing configuration content aiming at the Nacos service, designating a route configuration path through the NacosConfig configuration center to acquire the route configuration file, and adding a monitor to the NacosConfig configuration center to monitor the change of the route configuration file;
and the trigger calling module is used for triggering and calling the dynamic route definition mode when the monitor receives the configuration updating information for indicating the change of the route configuration file, and updating the changed route configuration file into the application process of the Spring Cloud Gateway gateway.
In a third aspect, the present application provides a computer device comprising a memory, a processor and a transceiver in communication connection in sequence, wherein the memory is configured to store a computer program, the transceiver is configured to send and receive messages, and the processor is configured to read the computer program and perform the gateway dynamic routing method according to the first aspect or any of the possible designs of the first aspect.
In a fourth aspect, the present application provides a computer readable storage medium having instructions stored thereon which, when run on a computer, perform the gateway dynamic routing method as described in the first aspect or any of the possible designs of the first aspect.
In a fifth aspect, the application provides a computer program product comprising instructions which, when run on a computer, cause the computer to perform the gateway dynamic routing method as described in the first aspect or any of the possible designs of the first aspect.
The beneficial effect of above-mentioned scheme:
(1) The application creatively provides a new dynamic routing scheme suitable for a Spring Cloud Gateway Gateway, namely, firstly, the creation of a routing configuration file, the creation of Gateway micro-service, the creation of Gateway configuration file, the creation of interface inheritance class and the creation of change monitoring class are sequentially completed in response to man-machine interaction operation, then the change of the routing configuration file is monitored based on an added monitor, finally, when the monitor receives configuration update information for indicating the change of the routing configuration file, a dynamic routing definition mode is triggered and invoked, and the changed routing configuration file is updated into the application process of the Spring Cloud Gateway Gateway, so that the purposes of automatically effecting the monitoring of the routing and the automatic effect without restarting the Gateway service can be realized based on the configuration of Nacos service, the operation is greatly simplified, and the actual application and popularization are facilitated.
Drawings
In order to more clearly illustrate the embodiments of the application or the technical solutions in the prior art, the drawings that are required in the embodiments or the description of the prior art will be briefly described, it being obvious that the drawings in the following description are only some embodiments of the application, and that other drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
Fig. 1 is a flow chart of a dynamic routing method for a gateway based on a Nacos service according to an embodiment of the present application.
Fig. 2 is a schematic structural diagram of a gateway dynamic routing device based on a Nacos service according to an embodiment of the present application.
Fig. 3 is a schematic structural diagram of a computer device according to an embodiment of the present application.
Detailed Description
In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the present application will be briefly described below with reference to the accompanying drawings and the description of the embodiments or the prior art, and it is obvious that the following description of the structure of the drawings is only some embodiments of the present application, and other drawings can be obtained according to these drawings without inventive effort to a person skilled in the art. It should be noted that the description of these examples is for aiding in understanding the present application, but is not intended to limit the present application.
It should be understood that although the terms first and second, etc. may be used herein to describe various objects, these objects should not be limited by these terms. These terms are only used to distinguish one object from another. For example, a first object may be referred to as a second object, and similarly a second object may be referred to as a first object, without departing from the scope of example embodiments of the application.
It should be understood that for the term "and/or" that may appear herein, it is merely one association relationship that describes an associated object, meaning that there may be three relationships, e.g., a and/or B, may represent: three cases of A alone, B alone or both A and B exist; as another example, A, B and/or C, can represent the presence of any one of A, B and C or any combination thereof; for the term "/and" that may appear herein, which is descriptive of another associative object relationship, it means that there may be two relationships, e.g., a/and B, it may be expressed that: the two cases of A and B exist independently or simultaneously; in addition, for the character "/" that may appear herein, it is generally indicated that the context associated object is an "or" relationship.
Examples:
as shown in fig. 1, the method for dynamically routing a gateway based on the Nacos service provided in the first aspect of the present embodiment may be, but is not limited to, executed by a server having a certain computing resource and having a communication connection based on a router of a Spring Cloud Gateway gateway. As shown in fig. 1, the gateway dynamic routing method may include, but is not limited to, the following steps S1 to S6.
S1, responding to first man-machine interaction operation, starting Nacos service, and creating a route configuration file in a NacosConfig configuration center of the Nacos service, wherein the route configuration file contains at least one piece of route information of initial configuration.
In the step S1, the first man-machine interaction operation and the plurality of man-machine interaction operations in the subsequent steps are all manual operations performed on the man-machine interaction interface by the user to achieve the corresponding operation purpose, and may be detected in a conventional manner, for example, the man-machine interaction operation detection purpose may be achieved by preferentially using a view layer in a model-view-controller (Model View Controller, MVC) architecture (which is an existing software architecture for achieving separation of service logic, data and interface display, and sequentially includes a view layer, a control layer and a model layer from top to bottom), so that after the man-machine interaction operation is detected, the man-machine interaction operation may be transmitted to the model layer via the control layer, and finally the operation is responded in the model layer, so that when the man-machine interaction operation is initiated by the user in the man-machine interaction manner, only a simple operation is performed on the control interface provided by the view layer, thereby greatly facilitating the man-machine interaction experience of the user.
In the step S1, the Nacos (i.e. Dynamic Naming and Configuration Service, where Na refers to a registration center of registration/nameServer, co refers to a configuration center of configuration, and service refers to that the registration/configuration center uses services as cores) service is a dynamic service discovery, configuration management and service management platform that is easier to construct a cloud native application; it aims to help users discover, configure and manage micro services, and provides a set of simple and easy-to-use feature sets, which can help users quickly realize dynamic service discovery, service configuration, service metadata, traffic management, etc., so that the routing configuration file can be conventionally created in the NacosConfig configuration center, for example, initially configuring a routing information for routing to reporting micro services. Specific operation codes are exemplified as follows:
s2, responding to the second man-machine interaction operation, creating Gateway micro-service, and adding a service configuration file, wherein the service configuration file comprises a designated storage address of the routing configuration file and configured related data for dynamic routing of the Gateway.
In the step S2, the storage address may be specifically expressed as springclose. The related data can be read through a subsequently created gateway Config. java file so as to realize the monitoring purpose, and the related data specifically comprises, but is not limited to, a namespace (Namespace) with a NacosConfig configuration center, a configuration set unique identifier (data-id) and/or a configuration group unique identifier (group-id) and the like, wherein the namespace is used for carrying out configuration isolation of tenant granularity, so that under different namespaces, the same configuration set unique identifier (data-id) and/or configuration group unique identifier (group-id) and the like can exist; the configuration grouping unique identifier group-id is a group of configuration sets in the Nacos service, and is one of the dimensions of organization configuration; the configuration set unique identification data-id is a unique identification of a certain configuration set and is also one of the dimensions of the organization partition configuration.
S3, responding to a third man-machine interaction operation, and creating a gateway Config. java file, wherein the gateway Config. java file comprises, but is not limited to, the storage address, the related data and the like read from the service configuration file.
In the step S3, the gateway config. Java file may further include a read configuration timeout time set by a user, so that in a subsequent listening process, if the route configuration file is not yet read beyond the read configuration timeout time, a prompt message for indicating that the route configuration file is abnormal in reading is triggered and displayed.
S4, responding to fourth man-machine interaction operation, creating a class to inherit an application EventPublisAware interface so as to inject an event publisher for the Gateway micro-service, so that the Gateway micro-service has the capability of publishing events, and specifically comprises the following steps: initialization of event push handles is completed and dynamic route definition modes are added.
In step S4, the Class is an existing programming term, named Class, which is the basis for implementing information encapsulation by Object-oriented programming (OOP, object-Oriented Programming), i.e. the Class is a type of user-defined reference data, also called Class type, each Class containing a data description and a set of functions for operating data or delivering messages, an instance of the Class being called an Object. The applicationEventPublisExpware interface is a Spring event mechanism (i.e. messages can be pushed, and a listener can monitor the event mechanism, and corresponding logic can be processed once the listener monitors the messages), so that an event push handle (which is used for pushing the messages) is needed to be relied on to realize the application; in order to ensure the correctness and reliability of event pushing (i.e. to ensure that events can be correctly sent to a designated listener when pushing events), some preparation work needs to be performed when initializing the event pushing handle, such as acquiring necessary configuration information, setting up event listeners and registering event listeners (completion of these preparation works can ensure smooth progress of event pushing). Specifically, the initialization of the event push handle is completed by a mode of designating an event publisher, namely an application EventPublicher. The dynamic route definition mode is used for describing a user-defined dynamic route mode, and specifically includes, but is not limited to, a user-defined mode for adding route information, updating route information and/or deleting route information. Further specifically, in the dynamic route definition manner, the operation of reading the route information may be implemented by a route definition locator routedefinLocator, and the operation of adding, updating, and/or deleting the route information may be implemented by a route definition editor routedefinWriter, where the route definition locator routedefinLocator and the route definition editor routedefinWriter are both existing tools.
S5, responding to a fifth man-machine interaction operation, creating another class to monitor the change of the routing configuration file, and specifically comprising the following steps: designating a current object to depend on the gateway config.java file, initializing configuration content for the Nacos service, designating a route configuration path through the NacosConfig configuration center to acquire the route configuration file, and adding a listener to the NacosConfig configuration center to monitor the change of the route configuration file.
In step S5, the current object refers to an instance of the other class. The change of the routing configuration file is generally generated by manual update, for example, a built Nacos address is firstly logged in, then a configuration file is newly built, then the related information of the routing is defined in the configuration file, finally the configuration file is stored, and a program can automatically monitor the change of the routing configuration file. The purpose of the foregoing dependency is to obtain the ip address, port number, namespace and configuration set unique identifier data-id of the Nacos service, so as to correctly obtain the specific address of the working space to which the configuration file belongs, specifically, specify that the current object depends on the gateway config. The current object is specified by @ DependsOn annotation to be dependent on the GateWayConfig. The purpose of the foregoing initialization of the configuration content is to read the attribute information configured in the gateway config. Specifically, initializing configuration content for the Nacos service includes: the storage address and a namespace of the NacosConfig configuration center in the related data are obtained as configuration content for the Nacos service.
S6, when the monitor receives configuration updating information for indicating the change of the routing configuration file, triggering and calling the dynamic routing definition mode, and updating the changed routing configuration file into the application process of the Spring Cloud Gateway gateway.
In the step S6, for example, if the route configuration file is updated, the monitor is automatically triggered, the result of deleting the route information in the route definition locator is obtained, and then all the route information is added again, so that no service needs to be restarted, and the method is automatic and effective.
The dynamic routing method for the Gateway based on the Nacos service described in the steps S1-S6 provides a new dynamic routing scheme suitable for the Spring Cloud Gateway Gateway, namely, firstly, the creation of a routing configuration file, the creation of a Gateway micro-service, the creation of a Gateway config. Java file, the creation of an interface inheritance class and the creation of a change monitoring class are sequentially completed in response to man-machine interaction operation, then, the change of the routing configuration file is monitored based on an added monitor, finally, when the monitor receives configuration update information for indicating the change of the routing configuration file, a dynamic routing definition mode is triggered and invoked to update the changed routing configuration file into an application process of the Spring Cloud Gateway Gateway, so that the purposes of monitoring the routing and automatic validation without restarting the Gateway service can be achieved based on the configuration of the Nacos service, the operation can be greatly simplified, and the actual application and popularization are facilitated.
As shown in fig. 2, a second aspect of the present embodiment provides a virtual device implementing the gateway dynamic routing method described in the first aspect, which is adapted to be disposed in a server of a router connected to a Spring Cloud Gateway gateway, and includes an operation response module and a trigger call module that are connected to each other in a communication manner;
the operation response module is used for responding to the first man-machine interaction operation, starting the Nacos service, and creating a route configuration file in a NacosConfig configuration center of the Nacos service, wherein the route configuration file contains at least one piece of route information which is initially configured;
the operation response module is also used for responding to the second man-machine interaction operation, creating Gateway micro-service and adding a service configuration file, wherein the service configuration file comprises a designated storage address of the routing configuration file and configured related data for dynamic routing of the Gateway;
the operation response module is further used for responding to a third man-machine interaction operation to create a gateway Config.java file, wherein the gateway Config.java file contains the storage address and the related data read from the service configuration file;
the operation response module is further configured to create a class to inherit an application eventpublicherAware interface in response to the fourth man-machine interaction operation, so as to inject an event publisher application eventpublicher for the Gateway micro-service, so that the Gateway micro-service has the capability of publishing events, and specifically includes: completing initialization of event pushing handles and adding a dynamic route definition mode;
the operation response module is further configured to create another class to monitor a change of the routing configuration file in response to a fifth man-machine interaction operation, and specifically includes: designating a current object to depend on the gateway config.java file, initializing configuration content aiming at the Nacos service, designating a route configuration path through the NacosConfig configuration center to acquire the route configuration file, and adding a monitor to the NacosConfig configuration center to monitor the change of the route configuration file;
and the trigger calling module is used for triggering and calling the dynamic route definition mode when the monitor receives the configuration updating information for indicating the change of the route configuration file, and updating the changed route configuration file into the application process of the Spring Cloud Gateway gateway.
The working process, working details and technical effects of the foregoing device provided in the second aspect of the present embodiment may refer to the gateway dynamic routing method described in the first aspect, which are not described herein again.
As shown in fig. 3, a third aspect of the present embodiment provides a computer device for performing the gateway dynamic routing method according to the first aspect, including a memory, a processor, and a transceiver that are sequentially communicatively connected, where the memory is configured to store a computer program, the transceiver is configured to send and receive a message, and the processor is configured to read the computer program, and perform the gateway dynamic routing method according to the first aspect. By way of specific example, the Memory may include, but is not limited to, random-Access Memory (RAM), read-Only Memory (ROM), flash Memory (Flash Memory), first-in first-out Memory (First Input First Output, FIFO), and/or first-in last-out Memory (First Input Last Output, FILO), etc.; the processor may be, but is not limited to, a microprocessor of the type STM32F105 family. In addition, the computer device may include, but is not limited to, a power module, a display screen, and other necessary components.
The working process, working details and technical effects of the foregoing computer device provided in the third aspect of the present embodiment may refer to the gateway dynamic routing method described in the first aspect, which are not described herein again.
A fourth aspect of the present embodiment provides a computer readable storage medium storing instructions comprising the gateway dynamic routing method according to the first aspect, i.e. having instructions stored thereon which, when run on a computer, perform the gateway dynamic routing method according to the first aspect. The computer readable storage medium refers to a carrier for storing data, and may include, but is not limited to, a floppy disk, an optical disk, a hard disk, a flash Memory, and/or a Memory Stick (Memory Stick), where the computer may be a general purpose computer, a special purpose computer, a computer network, or other programmable devices.
The working process, working details and technical effects of the foregoing computer readable storage medium provided in the fourth aspect of the present embodiment may refer to the gateway dynamic routing method as described in the first aspect, which are not described herein.
A fifth aspect of the present embodiment provides a computer program product comprising instructions which, when run on a computer, cause the computer to perform the gateway dynamic routing method according to the first aspect. The computer may be a general purpose computer, a special purpose computer, a computer network, or other programmable apparatus.
Finally, it should be noted that: the foregoing description is only of the preferred embodiments of the application and is not intended to limit the scope of the application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included in the protection scope of the present application.

Claims (10)

1. A method for dynamic routing of a Nacos service-based gateway, performed by a server communicatively coupled to a Spring CloudGateway gateway-based router, comprising:
responding to a first man-machine interaction operation, starting Nacos service, and creating a route configuration file in a NacosConfig configuration center of the Nacos service, wherein the route configuration file contains at least one piece of route information of initial configuration;
responding to a second man-machine interaction operation, creating Gateway micro-service, and adding a service configuration file, wherein the service configuration file comprises a designated storage address of the routing configuration file and configured related data for dynamic routing of the Gateway;
responding to a third man-machine interaction operation, and creating a gateway Config.java file, wherein the gateway Config.java file comprises the storage address and the related data read from the service configuration file;
responding to the fourth man-machine interaction operation, creating a class to inherit an application EventPublisAware interface so as to inject an event publisher for the Gateway micro-service, so that the Gateway micro-service has the event publishing capability, and specifically comprises the following steps: completing initialization of event pushing handles and adding a dynamic route definition mode;
responding to the fifth man-machine interaction operation, creating another class to monitor the change of the routing configuration file, and specifically comprising: designating a current object to depend on the gateway config.java file, initializing configuration content aiming at the Nacos service, designating a route configuration path through the NacosConfig configuration center to acquire the route configuration file, and adding a monitor to the NacosConfig configuration center to monitor the change of the route configuration file;
when the monitor receives configuration updating information for indicating the change of the route configuration file, triggering and calling the dynamic route definition mode, and updating the changed route configuration file into the application process of the SpringCloudgateway.
2. The gateway dynamic routing method according to claim 1, wherein the related data comprises a namespace of the NacosConfig configuration center, a configuration set unique identifier data-id, and/or a configuration packet unique identifier group-id.
3. The gateway dynamic routing method of claim 1, wherein completing initialization of an event push handle comprises: the initialization of the event pushing handle is completed by a mode of designating an event publisher application eventpublicher.
4. The method according to claim 1, wherein the dynamic route definition means comprises a user definition means for adding route information, updating route information, and/or deleting route information.
5. The method according to claim 4, wherein in the dynamic route definition manner, the operation of reading the route information is implemented by a route definition locator routedentionlocator, and the operation of adding, updating, and/or deleting the route information is implemented by a route definition editor routedentionrouter.
6. The gateway dynamic routing method of claim 1, wherein specifying that a current object depends on the gateway config. The current object is specified by @ DependsOn annotation to be dependent on the GateWayConfig.
7. The gateway dynamic routing method of claim 1, wherein initializing configuration content for the Nacos service comprises: the storage address and a namespace of the NacosConfig configuration center in the related data are obtained as configuration content for the Nacos service.
8. The gateway dynamic routing device based on Nacos service is characterized by being suitable for being arranged in a server of a router which is connected with a SpringCloudgateway based on communication, and comprising an operation response module and a trigger calling module which are connected with each other in a communication way;
the operation response module is used for responding to the first man-machine interaction operation, starting the Nacos service, and creating a route configuration file in a NacosConfig configuration center of the Nacos service, wherein the route configuration file contains at least one piece of route information which is initially configured;
the operation response module is also used for responding to the second man-machine interaction operation, creating Gateway micro-service and adding a service configuration file, wherein the service configuration file comprises a designated storage address of the routing configuration file and configured related data for dynamic routing of the Gateway;
the operation response module is further used for responding to a third man-machine interaction operation to create a gateway Config.java file, wherein the gateway Config.java file contains the storage address and the related data read from the service configuration file;
the operation response module is further configured to create a class to inherit an application eventpublicherAware interface in response to the fourth man-machine interaction operation, so as to inject an event publisher application eventpublicher for the Gateway micro-service, so that the Gateway micro-service has the capability of publishing events, and specifically includes: completing initialization of event pushing handles and adding a dynamic route definition mode;
the operation response module is further configured to create another class to monitor a change of the routing configuration file in response to a fifth man-machine interaction operation, and specifically includes: designating a current object to depend on the gateway config.java file, initializing configuration content aiming at the Nacos service, designating a route configuration path through the NacosConfig configuration center to acquire the route configuration file, and adding a monitor to the NacosConfig configuration center to monitor the change of the route configuration file;
and the trigger calling module is used for triggering and calling the dynamic route definition mode when the monitor receives the configuration updating information for indicating the change of the route configuration file, and updating the changed route configuration file into the application process of the SpringCloudgateway.
9. A computer device comprising a memory, a processor and a transceiver in communication connection in sequence, wherein the memory is configured to store a computer program, the transceiver is configured to send and receive messages, and the processor is configured to read the computer program and perform the gateway dynamic routing method according to any one of claims 1 to 7.
10. A computer readable storage medium having instructions stored thereon which, when executed on a computer, perform the gateway dynamic routing method of any of claims 1 to 7.
CN202310625897.6A 2023-05-30 2023-05-30 Gateway dynamic routing method, device, computer equipment and computer readable storage medium based on Nacos service Pending CN116633727A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310625897.6A CN116633727A (en) 2023-05-30 2023-05-30 Gateway dynamic routing method, device, computer equipment and computer readable storage medium based on Nacos service

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310625897.6A CN116633727A (en) 2023-05-30 2023-05-30 Gateway dynamic routing method, device, computer equipment and computer readable storage medium based on Nacos service

Publications (1)

Publication Number Publication Date
CN116633727A true CN116633727A (en) 2023-08-22

Family

ID=87609609

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310625897.6A Pending CN116633727A (en) 2023-05-30 2023-05-30 Gateway dynamic routing method, device, computer equipment and computer readable storage medium based on Nacos service

Country Status (1)

Country Link
CN (1) CN116633727A (en)

Similar Documents

Publication Publication Date Title
WO2021017301A1 (en) Management method and apparatus based on kubernetes cluster, and computer-readable storage medium
CN108989066B (en) Equipment management method and device
US20210405629A1 (en) System and method for interoperable communication of an automation system component with multiple information sources
WO2021017279A1 (en) Cluster security management method and apparatus based on kubernetes and network domain, and storage medium
WO2017054531A1 (en) Yang model-based compiling method, and corresponding interface, component, and system
CN113301116B (en) Cross-network communication method, device, system and equipment for micro-service application
CN110324169B (en) Interface management method and device
WO2019057055A1 (en) Task processing method and apparatus, electronic device, and storage medium
CN104731943A (en) Server and data processing method
WO2024016547A1 (en) Data query method and device based on multi-party collaboration
CN114254606A (en) Microservice framework model
US20240187501A1 (en) Techniques for distributed interface component generation
CN111736835A (en) Form processing method and device and storage medium
CN109117152B (en) Service generation system and method
CN110781441A (en) New retail business middle desk based on micro-service framework
CN111970192B (en) Information editing method and device based on session group
EP2395468A1 (en) Semantic user interface data assembling
CN117389647A (en) Plug-in generation method, application development method, device, equipment and medium
CN115168365B (en) Data storage method and device, electronic equipment and storage medium
CN112068953A (en) Cloud resource fine management traceability system and method
Xiaohua et al. Design and implementation of OpenDayLight manager application
US20220342742A1 (en) Graphical management of big data pipelines
CN116633727A (en) Gateway dynamic routing method, device, computer equipment and computer readable storage medium based on Nacos service
CN116048517A (en) API (application program interface) generating method, system and device based on B/S (browser/Server) architecture application system
US20150088866A1 (en) Accessing application services from forms

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination