CN113992559A - Message processing method, device, equipment and computer readable storage medium - Google Patents

Message processing method, device, equipment and computer readable storage medium Download PDF

Info

Publication number
CN113992559A
CN113992559A CN202111282152.1A CN202111282152A CN113992559A CN 113992559 A CN113992559 A CN 113992559A CN 202111282152 A CN202111282152 A CN 202111282152A CN 113992559 A CN113992559 A CN 113992559A
Authority
CN
China
Prior art keywords
service
message
target
routing
metadata
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.)
Granted
Application number
CN202111282152.1A
Other languages
Chinese (zh)
Other versions
CN113992559B (en
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.)
Tencent Technology Shenzhen Co Ltd
Original Assignee
Tencent Technology Shenzhen 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 Tencent Technology Shenzhen Co Ltd filed Critical Tencent Technology Shenzhen Co Ltd
Priority to CN202111282152.1A priority Critical patent/CN113992559B/en
Publication of CN113992559A publication Critical patent/CN113992559A/en
Application granted granted Critical
Publication of CN113992559B publication Critical patent/CN113992559B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L45/00Routing or path finding of packets in data switching networks
    • H04L45/14Routing performance; Theoretical aspects
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L47/00Traffic control in data switching networks
    • H04L47/10Flow control; Congestion control
    • H04L47/12Avoiding congestion; Recovering from congestion
    • H04L47/125Avoiding congestion; Recovering from congestion by balancing the load, e.g. traffic engineering
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/14Session management
    • H04L67/143Termination or inactivation of sessions, e.g. event-controlled end of session

Abstract

The application provides a message processing method, a device, equipment and a computer readable storage medium; the method comprises the following steps: the gateway equipment receives a service message sent by a client, wherein the service message carries routing metadata used for indicating routing information; analyzing the service message to obtain routing metadata; determining a target service corresponding to the service message and a target server corresponding to the target service according to the routing metadata; and forwarding the service message to the target server so that the target server returns a response result corresponding to the service message. By the method and the device, the quick routing of the service message can be realized.

Description

Message processing method, device, equipment and computer readable storage medium
Technical Field
The present application relates to computer network technologies, and in particular, to a method, an apparatus, a device, and a computer-readable storage medium for processing a message.
Background
With the popularity of the microservice concept, development and integration based on microservice architecture is becoming an industry trend. Under a micro-service architecture, a large-function Application is split into a plurality of small services, and in order to provide guarantee for internal services, developers of the Application services can be helped to conveniently provide services to the outside by providing a high-performance Application Programming Interface (API) hosting service without considering problems of safety control, flow control, audit logs and the like.
In the related art, a device implementing the API hosting service may be referred to as an API gateway, and the API gateway may provide a uniform access portal to simplify operations of a client accessing the microservice. However, the routing method for the service message in the related art is complex in configuration and slow in routing speed.
Disclosure of Invention
Embodiments of the present application provide a message processing method, an apparatus, an electronic device, a computer-readable storage medium, and a computer program product, which can implement fast routing of a service message.
The technical scheme of the embodiment of the application is realized as follows:
an embodiment of the present application provides a message processing method, including:
the method comprises the steps that gateway equipment receives a service message sent by a client, wherein the service message carries routing metadata used for indicating routing information;
analyzing the service message to obtain the routing metadata;
determining a target service corresponding to the service message and a target server corresponding to the target service according to the routing metadata;
and forwarding the service message to the target server so that the target server returns a response result corresponding to the service message.
An embodiment of the present application provides a message processing apparatus, including:
the system comprises a receiving module, a sending module and a receiving module, wherein the receiving module is used for receiving a service message sent by a client, and the service message carries routing metadata used for indicating routing information;
the analysis module is used for analyzing the service message to obtain the routing metadata;
a determining module, configured to determine, according to the routing metadata, a target service corresponding to the service message and a target server corresponding to the target service;
and the sending module is used for forwarding the service message to the target server so as to enable the target server to return a response result corresponding to the service message.
In the foregoing solution, the parsing module is further configured to parse the service message to obtain a routing metadata area, where the routing metadata area includes serialized routing metadata;
and performing deserialization on the serialized routing metadata to obtain the routing metadata.
In the foregoing solution, the determining module is further configured to match the routing information indicated by the routing metadata with routing information in a routing table, so as to determine target routing information in the routing table;
determining a target service corresponding to the service message and a service instance corresponding to the target service based on the target routing information;
and determining a target server corresponding to the service message according to the service instance corresponding to the target service.
In the above solution, the routing information indicated by the routing metadata includes a message identifier, and the determining module is further configured to obtain a reference message identifier group included in each routing information in a routing table and a service corresponding to each reference message identifier group;
determining a reference message identifier group to which the message identifier belongs as a target message identifier group, and determining routing information comprising the target message identifier group as the target routing information;
determining a target service corresponding to the service message based on the target routing information, including:
and determining that the service corresponding to the target message identification group is the target service corresponding to the service message based on the target routing information.
In the above scheme, the message identifier is stored in a key-value pair manner, and the determining module is further configured to obtain an identifier value corresponding to the message identifier;
determining an identification value range corresponding to each reference message identification group;
and determining the identification value range to which the identification value belongs, and determining the corresponding reference message identification group as the target message identification group.
In the above scheme, the determining module is further configured to determine, when the number of the service instances is one, a server where the service instance is located as a target server corresponding to the service message;
when the number of the service instances is at least two, determining a target service instance from the at least two service instances according to load balance, and taking a server where the target service instance is located as the target server.
In the above scheme, the sending module is further configured to obtain the number of service messages of the current routing of the target service by the gateway device and a current limiting threshold of the gateway device;
wherein the current limit threshold is used to characterize a maximum number of service messages that can be routed to the target service by the gateway device per unit time;
forwarding the service message to the target server when the number does not reach the current limit threshold.
In the above scheme, the sending module is further configured to obtain a fusing manner corresponding to the target service when the number reaches the current limiting threshold;
the fusing mode is used for indicating the operation executed by forbidding the client to access the target service;
and executing the operation according to the fusing mode to stop forwarding the service message to the target server.
In the foregoing solution, the sending module is further configured to discard the service message sent by the client when the fusing manner indicates to execute a message discarding operation;
and when the fusing mode indicates that the connection interruption operation is carried out, interrupting the communication connection between the client and the target server.
An embodiment of the present application provides an electronic device, including:
a memory for storing executable instructions;
and the processor is used for realizing the message processing method provided by the embodiment of the application when the processor executes the executable instructions stored in the memory.
The embodiment of the present application provides a computer-readable storage medium, which stores executable instructions for causing a processor to implement the message processing method provided by the embodiment of the present application when the processor executes the executable instructions.
The embodiment of the present application provides a computer program product, which includes a computer program, and the computer program, when executed by a processor, implements the message processing method provided by the embodiment of the present application.
The embodiment of the application has the following beneficial effects:
in the embodiment of the application, the service message carries the routing metadata used for indicating the routing information, so that the gateway device can directly realize the fast routing of the service message based on the routing information indicated by the routing metadata, the routing mode is simple and flexible, and the coupling degree between the client and the server is reduced.
Drawings
Fig. 1 is a schematic architecture diagram of a message processing method provided in an embodiment of the present application;
fig. 2 is a schematic structural diagram of an electronic device provided in an embodiment of the present application;
fig. 3 is a schematic flowchart of a message processing method provided in an embodiment of the present application;
FIG. 4 is a schematic diagram of a metadata region format according to an embodiment of the present application;
FIG. 5 is a flowchart of a method for determining a target server according to an embodiment of the present disclosure;
fig. 6 is an exemplary diagram of routing information provided by an embodiment of the present application;
fig. 7 is a schematic diagram of a matching manner of routing information provided in an embodiment of the present application;
fig. 8 is a schematic diagram of a configuration of routing information provided in an embodiment of the present application;
FIG. 9 is a schematic diagram of a configuration of current limiting fuse information according to an embodiment of the present disclosure;
fig. 10 is a flowchart illustrating a method for determining target routing information according to an embodiment of the present application;
FIG. 11 is a message processing flow diagram provided by an embodiment of the present application;
FIG. 12 is a flowchart illustrating a method for determining a target service provided by an embodiment of the present application;
FIG. 13 is a flowchart of a method for determining a target server according to an embodiment of the present disclosure;
FIG. 14 is a flow chart of a current limiting fusing process provided by an embodiment of the present application;
FIGS. 15A-15B are schematic diagrams of related routing configurations provided by embodiments of the present application;
FIG. 16 is a schematic diagram of a service message processing system architecture provided by an embodiment of the present application;
fig. 17 is a message processing flowchart provided in an embodiment of the present application.
Detailed Description
In order to make the objectives, technical solutions and advantages of the present application clearer, the present application will be described in further detail with reference to the attached drawings, the described embodiments should not be considered as limiting the present application, and all other embodiments obtained by a person of ordinary skill in the art without creative efforts shall fall within the protection scope of the present application.
In the following description, reference is made to "some embodiments" which describe a subset of all possible embodiments, but it is understood that "some embodiments" may be the same subset or different subsets of all possible embodiments, and may be combined with each other without conflict.
Where similar language of "first/second" appears in the specification, the following description is added, and where reference is made to the term "first \ second \ third" merely for distinguishing between similar items and not for indicating a particular ordering of items, it is to be understood that "first \ second \ third" may be interchanged both in particular order or sequence as appropriate, so that embodiments of the application described herein may be practiced in other than the order illustrated or described herein.
Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used herein is for the purpose of describing embodiments of the present application only and is not intended to be limiting of the application.
Before further detailed description of the embodiments of the present application, terms and expressions referred to in the embodiments of the present application will be described, and the terms and expressions referred to in the embodiments of the present application will be used for the following explanation.
1) Application program interface gateway: an Application Programming Interface (API) gateway, abbreviated as API gateway, is a central Interface of multiple microservice clients, and is used for uniformly accessing calls of all APIs to an API gateway layer, which is responsible for accessing and outputting.
For services with large number, complexity and size, the advantages of introducing the API gateway are as follows: the aggregation interface enables the service to be transparent to a caller (client), and the coupling degree of the client and the back end is reduced; background services are aggregated, so that the flow is saved, the performance is improved, and the user experience is improved; and API management functions such as safety, flow control, filtering, caching, charging, monitoring and the like are provided.
2) Metadata (Meta Data): data information used to describe the data. Common attribute information, such as data, may format the description information for machine processing.
3) Routing table (routing table): in a computer network, is a spreadsheet (file) or class database stored in a router or networked computer. The routing table stores the path (and in some cases, the route metric value of the path) that points to a particular network address. The routing table contains topology information of the network periphery. The main goal of routing table establishment is to implement routing protocols and static routing. It can be understood that the table of related information recording the path from the source end to the destination end is provided for the routing module to find the route.
4) And (3) service fusing: for the limitation of the calling times of the service interface, when a certain service reaches the upper limit, the interface gateway can automatically stop sending a request to an upstream service, and return an error prompt message or a uniform response to the client to perform service degradation, and for the service which needs to temporarily break down, the interface gateway opens a breaker corresponding to the service to perform service fusing, so that the whole system is prevented from avalanche.
5) Layer 4/layer 7 routing: corresponding to layer 4 (transport layer, TCP/UDP layer) and layer 7 (application layer, HTTP) respectively in the network seven-layer protocol. The route realized in the transmission layer is called 4-layer route, and the route realized in the application layer is called 7-layer route.
In the related art, most of the routing methods for service messages are based on the HTTP protocol, and a target route is often acquired through regular matching of a Uniform Resource Locator (URL). For the service message of the custom protocol, most of the service message is based on the TCP/UDP protocol, and the carried service message is not necessarily the HTTP protocol, and has no URL field. Such service information is not always in the URL, and even if the service information is put on the URL, the configuration with the regular expression is very complicated and is not easy to understand.
Based on this, embodiments of the present application provide a message processing method, an apparatus, a device, and a computer-readable storage medium, which can implement fast routing of service messages, and the routing manner is simple and flexible, and reduces the coupling degree between a client and a server.
An exemplary application of the message processing device provided in the embodiments of the present application is described below, and the message processing device provided in the embodiments of the present application may be implemented as various types of user terminals such as a notebook computer, a tablet computer, a desktop computer, a set-top box, a mobile device (e.g., a mobile phone, a portable music player, a personal digital assistant, a dedicated message device, and a portable game device), and may also be implemented as a server. In the following, an exemplary application will be explained when the gateway device is implemented as a server.
Referring to fig. 1, fig. 1 is a schematic block diagram of a message processing method provided in this embodiment, in order to implement supporting a message processing application, in a message processing system 100, a terminal 400 (exemplarily showing a terminal 400-1 and a terminal 400-2) is connected to a gateway device through a network 300, the gateway device is connected to a server 200 (exemplarily showing a server 200-1 and a server 200-2) through the network 300, and the network 300 may be a wide area network or a local area network, or a combination of both.
In practical applications, the terminal 400 may be various types of user terminals such as a smart phone, a tablet computer, a notebook computer, and the like, and may also be a desktop computer, a media player, a game console, a television, or a combination of any two or more of these data processing devices; the server 200 may be an independent physical server, a server cluster or a distributed system formed by a plurality of physical servers, or a cloud server providing basic cloud computing services such as a cloud service, a cloud database, cloud computing, a cloud function, cloud storage, a network service, cloud communication, a middleware service, a domain name service, a security service, a Content Delivery Network (CDN), a big data and artificial intelligence platform, and the like. The gateway apparatus 500 may be any one or more of the terminals 400, and may be any one or more of the servers 200.
The terminal 400 is configured to send a service message carrying routing metadata indicating routing information to the gateway device, and receive a response failure notification sent by the gateway device that disappears or a response result for the service message returned by the server.
The gateway device 500 is configured to receive a service message sent by a client, where the service message carries routing metadata used for indicating routing information; analyzing the service message to obtain routing metadata; determining a target service corresponding to the service message and a target server corresponding to the target service according to the routing metadata; and forwarding the service message to the target server so that the target server returns a response result corresponding to the service message.
The server 200 is configured to receive the service message forwarded by the gateway device, and forward a response result to the service message to the terminal.
In some embodiments, as shown in fig. 1, an application client 410-1 (e.g., a game application client, an instant messaging client, etc.) deployed by a terminal 400-1 sends a service broker carrying routing metadata indicating routing information to a gateway device 500 via a network 300. The gateway device 500 receives the service message sent by the client 410-1, and analyzes the service message to obtain the routing metadata; then, according to the routing metadata, determining a target service corresponding to the service message and a target server corresponding to the target service; forwarding the service message to the target server; the target server returns a response result corresponding to the service message to the gateway device, and the gateway device forwards the response result aiming at the service message to the client.
Referring to fig. 2, fig. 2 is a schematic structural diagram of an electronic device provided in an embodiment of the present application, and the electronic device 600 shown in fig. 2 includes: at least one processor 610, memory 650, at least one network interface 620, and a user interface 630. The various components in electronic device 600 are coupled together by a bus system 640. It is understood that bus system 640 is used to enable communications among the components. Bus system 640 includes a power bus, a control bus, and a status signal bus in addition to a data bus. For clarity of illustration, however, the various buses are labeled as bus system 640 in fig. 2.
The Processor 610 may be an integrated circuit chip having Signal processing capabilities, such as a general purpose Processor, a Digital Signal Processor (DSP), or other programmable logic device, discrete gate or transistor logic device, discrete hardware components, or the like, wherein the general purpose Processor may be a microprocessor or any conventional Processor, or the like.
The user interface 630 includes one or more output devices 631 including one or more speakers and/or one or more visual displays that enable the presentation of media content. The user interface 630 also includes one or more input devices 632, including user interface components to facilitate user input, such as a keyboard, mouse, microphone, touch screen display, camera, other input buttons and controls.
The memory 650 may be removable, non-removable, or a combination thereof. Exemplary hardware devices include solid state memory, hard disk drives, optical disk drives, and the like. Memory 650 optionally includes one or more storage devices physically located remote from processor 610.
The memory 650 includes volatile memory or nonvolatile memory, and may include both volatile and nonvolatile memory. The nonvolatile Memory may be a Read Only Memory (ROM), and the volatile Memory may be a Random Access Memory (RAM). The memory 650 described in embodiments herein is intended to comprise any suitable type of memory.
In some embodiments, memory 650 can store data to support various operations, examples of which include programs, modules, and data structures, or subsets or supersets thereof, as exemplified below.
An operating system 651 including system programs for handling various basic system services and performing hardware-related tasks, such as a framework layer, a core library layer, a driver layer, etc., for implementing various basic services and for handling hardware-based tasks;
a network communication module 652 for reaching other computing devices via one or more (wired or wireless) network interfaces 620, exemplary network interfaces 620 including: bluetooth, wireless compatibility authentication (WiFi), and Universal Serial Bus (USB), etc.;
a presentation module 653 for enabling presentation of information (e.g., a user interface for operating peripherals and displaying content and information) via one or more output devices 431 (e.g., a display screen, speakers, etc.) associated with the user interface 430;
an input processing module 654 for detecting one or more user inputs or interactions from one of the one or more input devices 432 and translating the detected inputs or interactions.
In some embodiments, the apparatus provided by the embodiments of the present application may be implemented in software, and fig. 2 shows the message processing apparatus 655 stored in the memory 650, which may be software in the form of programs and plug-ins, and the like, and includes the following software modules: the receiving module 6551, the parsing module 6552, the determining module 6553 and the sending module 6554, which are logical and thus may be arbitrarily combined or further split depending on the functions implemented. The functions of the respective modules will be explained below.
In other embodiments, the message processing apparatus provided in this embodiment may be implemented in hardware, and for example, the message processing apparatus provided in this embodiment may be a processor in the form of a hardware decoding processor, which is programmed to execute the message processing method provided in this embodiment, for example, the processor in the form of the hardware decoding processor may employ one or more Application Specific Integrated Circuits (ASICs), DSPs, Programmable Logic Devices (PLDs), Complex Programmable Logic Devices (CPLDs), Field Programmable Gate Arrays (FPGAs), or other electronic components.
Next, a message processing method provided in an embodiment of the present application is described. In some embodiments, the gateway device may be a standalone device, or may be any one of the server 200 or the terminal 400 shown in fig. 1, and the message processing method provided in the embodiments of the present application will be described in conjunction with exemplary applications and implementations of the gateway device provided in the embodiments of the present application. Referring to fig. 3, fig. 3 is a schematic flowchart of a message processing method provided in an embodiment of the present application, and will be described with reference to the steps shown in fig. 3.
In step 101, a gateway device receives a service message sent by a client, where the service message carries routing metadata indicating routing information.
In some embodiments, the client accesses the microservices provided by the servers in the microservice system to which the application belongs through the gateway device, and in the microservice system, the gateway device may also be referred to as an API gateway (the gateway device is an API gateway, which is not specifically described in the following statement). In practical application, the service message may carry routing metadata indicating routing information, and through the routing metadata, the API gateway may obtain a target service to be accessed by the service message and a service instance corresponding to the target service, thereby determining a server capable of processing the service message. It should be noted that the service message carrying the routing metadata may be transmitted in layer 4 (transport layer, TCP/UDP layer) in the network seven-layer protocol, that is, the service message carrying the routing metadata is transmitted based on TCP/UDP, and thus, the service message carrying the routing metadata can be applied to message routing without URL content or without port content.
Routing metadata is illustrated, and in some embodiments, is primarily used to match with routing tables at the API gateway device, i.e., routing metadata is used to indicate information related to routing information (metadata appearing in the following description may be understood as routing metadata). The routing metadata may be transmitted in a key value pair (key, value) format, wherein the key and the value may be of a string type, and may store any type of data.
In practical implementations, a plurality of mutually independent routing metadata may be included for the service message, each metadata may define a constraint on the route. For example, the metadata identifies for the message: key ═ msgid ', value ═ 100'; the metadata is game user identification: key ═ uin ', value ═ game account 1'.
The data transmission can be realized in an application layer of a TCP/IP seven layer based on an HTTP protocol, and can also be realized in a transmission layer of a TCP/IP four layer based on a custom protocol. The custom protocol may be understood as defining a format specification in a data transmission process, that is, a format of transmission data determined after the client, the gateway device, and the server have agreed.
In step 102, the service message is parsed for routing metadata.
In some embodiments, the service message may be transmitted in a byte stream manner, the service message may carry a routing metadata region, and the routing metadata region may include a plurality of routing metadata in a byte stream format obtained through serialization processing. After receiving a service request sent by a client, the gateway device may obtain initial routing metadata in the following manner: the gateway equipment analyzes the service message to obtain a routing metadata area, and the routing metadata area comprises serialized routing metadata; and deserializing the serialized routing metadata to obtain the routing metadata.
In practical implementation, the routing metadata area may have a header and a body position of the service message, and the start position and the end position corresponding to the routing metadata area may be set. The gateway equipment analyzes the service message (analyzes the byte stream corresponding to the service message), carries out deserialization operation on the byte stream from the initial position of the routing metadata area to the end position of the routing metadata area, and finally obtains the deserialized routing metadata.
In some embodiments, when the routing metadata is transmitted in the form of key-value pairs, a plurality of pieces of metadata may form the metadata area by composing a byte stream by some serialization method. Referring to fig. 4, fig. 4 is a schematic diagram of a format of a metadata area provided in this embodiment, where the metadata area is a byte array having a certain length and may be represented as (buffer, length), multiple metadata in the metadata area are distinguished by a preset divider (shown as number 1 in the figure), a key and a value of each metadata, and after a serialization operation, the format of the metadata (shown as number 2 in the figure) may be a key portion shown as number 2-a in the figure, (the key portion is composed of a length of the key and a content of the key), a divider shown as number 2-b in the figure, and a value portion shown as number 2-c in the figure (the value portion is composed of a length of the value and a content of the value), in an actual application, the divider shown as number 2-b in the figure and the divider shown as number 1 in the figure may be the same, or may be different.
In step 103, a target service corresponding to the service message and a target server corresponding to the target service are determined according to the routing metadata.
In some embodiments, the gateway device matches the routing information indicated by the routing metadata with the routing information in the preloaded routing table, and determines a target server corresponding to the service message. Referring to fig. 5, fig. 5 is a flowchart of a method for determining a target server according to an embodiment of the present application, and is described with reference to the steps shown in fig. 5.
In step 1031, the gateway device matches the routing information indicated by the routing metadata with the routing information in the routing table to determine the target routing information in the routing table.
Describing a routing table, in some embodiments, the routing table is composed of a piece of routing information (also referred to as a routing rule), and the matching rule of the routing information in the routing table is: matching from front to back; if any rule is successfully matched, the matching process is exited; no route is matched, and a default route is taken for a non-specified route; otherwise an error is returned. The routing information mainly comprises 4 parts: name, matching rules, routing policy, load balancing policy (loadbalancer). Name (name): routing rules are identified and no duplication is allowed. Matching rules (match rules): metadata for matching, and a matching approach are described.
Exemplarily, referring to fig. 6, fig. 6 is an exemplary diagram of routing information provided in this embodiment, where 2 pieces of routing information are exemplarily listed, the routing information 1 (shown by number 1 in the diagram), the message Identity (msgid), and the user Identity (uin) describe information that can be matched, the service name (service name) represents a target service server1 that the routing information 1 can route, the service instance (server id) represents a service instance corresponding to the target service of the routing information 1, the service instance 101 and the service instance 102, and the load balancing manner (loadbalancer) corresponding to the routing information is a round robin manner (round _ binding).
Explaining the matching manner, in some embodiments, refer to fig. 7, where fig. 7 is a schematic diagram of a matching manner of routing information provided in the embodiments of the present application, and the diagram shows that the matching manner includes 3 matching manners, a first one: exist, the matching field key exists; and the second method comprises the following steps: performing, wherein the key of the matching field exists, and the value is the same as the field value in the routing rule; and the third is that: range, key of matching field exists, and value is between min and max.
Exemplarily, referring to fig. 6, routing information shown by number 1 in fig. 6, where a matching manner of msgid is range, and a corresponding value range is 1-10, that is, a value of msgid carried in a service message falls within a range of 1-10, and then the routing information may be used as candidate routing information for further matching; the corresponding value of the matching mode exact of the uin is 100, that is, if the value of the uin carried in the service message is 100, the routing can be matched, and the routing information 1 is the routing information which can be matched by the service message whose value of the uin is 100 and whose value falls within the range of 1-10. Routing information 2 shown by number 2 in the figure is routing information that a service message of value 11 of msgid can match.
Explaining a routing policy, which describes a successfully matched routing policy and a load balancing (also referred to as load balancing) method. In some embodiments, referring to fig. 8, fig. 8 is a schematic diagram of a routing information configuration provided in the embodiments of the present application, where the schematic diagram shows a load balancing manner (loadBalancer portion shown in fig. 2) and a server portion (shown in fig. 1) of routing information (route). The server part mainly defines the name of the service (service _ name) provided by the target server and the instance of the service (service _ id listed in the host shown as number 2-1 in the figure). If no specific instance is specified (host does not list service _ id), or more than 1 service instance is specified (the number of service _ id is more than 1), a load balancing approach (loadBalancer) may be configured.
Describing the load balancing strategy, in some embodiments, loadBalancer mainly defines 3 load balancing strategies: HASH (HASH), consistent HASH (conssistanthash), ROUND ROBIN (ROUND _ ROBIN), and RANDOM (RANDOM). Wherein, the first one: hashing is typically accomplished by hashing the hash key with an algorithm to an integer value and then modulo the instance number, and accessing the first instance if the value is 0 and the second instance if the value is 1. And the second method comprises the following steps: rotation is a method of balancing access in turn, with the first access selecting instance 0 and the second access selecting instance 1. And the third is that: randomness is the calculation of a value by a random algorithm and then modulo the number of service instances, with the value 0 accessing the first instance and 1 accessing the second instance.
Exemplarily, referring to fig. 6, the load balancing method (loadbalancer) corresponding to the routing information shown in number 1 in fig. 6 is a round robin method, and for the target service server1, two service instances (service _ id), that is, a service instance 101 and a service instance 102, are provided.
Explaining current limiting and fusing of the API gateway, in some embodiments, referring to fig. 9, fig. 9 is a schematic view of configuration of current limiting and fusing information provided in the embodiments of the present application, where a current limiting configuration (flowcontrol) of the API gateway may be characterized by qps (query Per second) shown in number 1 in the figure, qps defines a maximum traffic threshold of this piece of routing information, after the API gateway realizes current limiting through a preset current limiting algorithm, a subsequent OPERATION on a service message may be realized through a fusing mode, a fusing configuration (shown in fig. 2) of the API gateway may be characterized by an OPERATION, the OPERATION mainly defines a fusing mode exceeding the current limiting threshold, and the fusing mode that may be used includes discarding or closing connection, and the like.
In some embodiments, the routing information indicated by the routing metadata may include a message identification, and the gateway device may determine the target routing information from the routing table based on the message identification. Referring to fig. 10, fig. 10 is a schematic flowchart of a method for determining target routing information provided in the embodiment of the present application, and based on fig. 5, step 1031 may also be implemented in the following manner:
step 201, the gateway device obtains the reference message identifier groups included in each routing information in the routing table and the services corresponding to each reference message identifier group.
Exemplarily, referring to fig. 11, fig. 11 is a message processing flowchart provided by an embodiment of the present application, in which an API gateway receives two service messages from a client, where a service message 1 carries route metadata msgid ═ 8 corresponding to a message identifier and route metadata uin ═ 100 corresponding to a user identifier, that is, an identifier value corresponding to the message identifier msgid is 8, and an identifier value corresponding to the user identifier is 100; the service message 2 carries a message indication corresponding to the routing metadata msgid ═ 11, and a user identification routing metadata uin ═ 100. Based on the routing table shown in fig. 6, groups may be identified for reference messages by msgid in the table of fig. 6.
Step 202, the gateway device determines that the reference message identification group to which the message identification belongs is the target message identification group, and determines that the routing information including the target message identification group is the target routing information.
In some embodiments, referring to fig. 12, fig. 12 is a flowchart illustrating a method for determining a target service provided in an embodiment of the present application, and based on fig. 10, when a message identifier may be stored in a key-value pair manner, step 202 may also be implemented by:
step 2021, the gateway device obtains an identifier value corresponding to the message identifier.
In actual implementation, the message identifier may be stored in a key-value pair form, that is, in a key-value form, the message identifier serves as a key, and an identifier value corresponding to the message identifier serves as a value.
Exemplarily, referring to fig. 11, the API gateway receives two service messages from a client, where service message 1 carries route metadata msgid ═ 8 corresponding to a message identifier and route metadata uin ═ 100 corresponding to a subscriber identifier, that is, an identifier value corresponding to the message identifier msgid is 8, and an identifier value corresponding to the subscriber identifier is 100; the service message 2 carries a message indication corresponding to the routing metadata msgid ═ 11, and a user identification routing metadata uin ═ 100.
Step 2022, determine the corresponding identification value range of each reference message identification group.
In practical implementation, each reference message identifier in each reference message identifier group is also stored in a key-value pair form, the reference message identifier is used as a key, and an identifier value range corresponding to the reference message identifier is used as a value.
Bearing the above example, after receiving the service message 1, the API gateway obtains and matches each routing information in the routing table according to the sequence from front to back, the routing table can refer to fig. 6, the API gateway determines the identifier value range [1, 10] corresponding to the reference message identifier msgid of the routing information 1 shown by the number 1 in fig. 6, which indicates that if the identifier value corresponding to the message identifier in the service message falls into the range [1, 10], the routing information 1 can be used as the target routing information; the identification value corresponding to the reference message identification msgid of the routing information 2 shown by the number 2 is a value 11, which indicates that if the identification value corresponding to the message identification in the service message is 11, the routing information 2 can be used as the target routing information.
Step 2023, determining the identification value range to which the identification value belongs, and determining the corresponding reference message identification group as the target message identification group.
Bearing the above example, the identification value of the message identifier in the service message 1 shown in fig. 11 falls into the identification value range of the reference message identifier in the routing information 1 shown in the number 1 in fig. 6, the reference message identifier group in the routing information 1 may be the target message identifier group of the service message 1, and the target routing information corresponding to the service message 1 may be the routing information 1 shown in the number 1 in fig. 6; the identification value of the message identifier in the service message 2 shown in fig. 11 falls into the identification value range of the reference message identifier in the routing information 2 shown by the number 2 in fig. 6, the reference message identifier group in the routing information 2 may be the target message identifier group of the service message 2, and the target routing information corresponding to the service message 2 may be the routing information 2 shown by the number 2 in fig. 6.
Step 1032, the gateway device determines a target service corresponding to the service message and a service instance corresponding to the target service based on the target routing information.
In some embodiments, based on the target routing information determined in steps 201-202 shown in fig. 10, the gateway device may also determine the target service by: and based on the target routing information, the gateway equipment determines that the service corresponding to the target message identification group is the target service corresponding to the service message.
Bearing the above example, the target reference message identification group corresponding to the service message 1 shown in fig. 11 belongs to the routing information 1 shown in the number 1 in fig. 6, the service server1 corresponding to the routing information 1 can be used as the target service of the service message 1, and the service instance 101 and the service instance 102 corresponding to the routing message 1 can be used as the service instance corresponding to the target service server 1; the target reference message identifier group corresponding to the service message 2 shown in fig. 11 belongs to the routing information 2 shown in the number 2 in fig. 6, and the service server2 corresponding to the routing information 2 may serve as a target service of the service message 2, and since the service instance of the service server2 is not set in the routing message 2, one service instance may be selected for forwarding in a load balancing manner.
Step 1033, the gateway device determines the target server corresponding to the service message according to the service instance corresponding to the target service.
In some embodiments, referring to fig. 13, fig. 13 is a flowchart of a method for determining a target server provided in an embodiment of the present application, and based on fig. 5 or fig. 10, step 1033 may be implemented by:
step 301, the gateway device obtains the number of service instances corresponding to the target service.
In actual implementation, the target server responding to the service message is determined according to the number of the service instances corresponding to the determined target service.
Step 302a, when the number of the service instances is one, determining the server where the service instances are located as a target server corresponding to the service message.
In actual implementation, when the number of the service instances corresponding to the target service in the target routing information is one, the server where the service instance is located is directly used as the target server for the corresponding service message.
Step 302b, when the number of the service instances is at least two, according to the load balance, determining a target service instance from the at least two service instances, and taking a server where the target service instance is located as a target server.
In actual implementation, when the number of service instances corresponding to the target service in the target routing information is at least two, or a service instance corresponding to the target service is not specified in the target routing information, the target server corresponding to the service message may be determined in a load balancing manner. And determining a load balancing mode which can be implemented by the network equipment by acquiring the configuration load balancing strategy.
Illustratively, in the routing table shown in fig. 6, the corresponding target routing information is routing information 1 shown in number 1, in the routing information 1, the number of service instances corresponding to the service server1 is two, that is, the service instance 101 and the service instance 102, in the routing information 1, the corresponding load balancing manner is rotated, the service instance 101 is selected as the service instance of the target service in the rotating manner, that is, the service message is responded by the service instance 101, and the response result is obtained, and at the same time, according to the service instance 101, the server shown in number a is determined as the target server for processing the service message 1, from the two servers shown in number 3-1 in fig. 11, the server shown in number a is determined. The server shown by number 3-2 is determined as the target server for processing the service message 2.
In step 104, the service message is forwarded to the target server, so that the target server returns a response result corresponding to the service message.
In some embodiments, when the gateway device forwards the service message to the target server, different operations for the service message may be customized according to the current limiting threshold set by the gateway device. The size of the current service message of the routing target service can be determined according to the size relation between the current service message of the gateway device and the current limiting threshold value. Referring to fig. 14, fig. 14 is a flowchart of a current limiting fusing process provided in an embodiment of the present application, and based on fig. 3, step 104 may also be implemented by:
step 1041, the gateway device obtains the number of service messages of the current route target service of the gateway device and the current limiting threshold of the gateway device.
In some embodiments, the current limit threshold is used to characterize a maximum number of service messages per unit time that a target service can be routed through the gateway device.
In practical implementation, the flow limitation can be realized by gateway flow limitation methods such as a leaky bucket algorithm and a token bucket algorithm.
For example, referring to routing information 1 shown as number 1 in fig. 6, the current limit threshold qps of the corresponding server1 is 100, which indicates that the maximum number of service messages processed per minute to access the server1 is 100. If qps does not reach 100 when the service message 1 shown in fig. 11 accesses the server1, the gateway device may continue to perform subsequent processing on the service message 1, that is, execute step 1042 a; if qps reaches 100 when the service message 1 shown in fig. 11 accesses the server1, the gateway device may continue to obtain the configured fusing manner in the routing information 1, and perform the operation indicated by the corresponding fusing manner on the service message, that is, perform step 1042 b.
In step 1042a, when the number does not reach the current limit threshold, the service message is forwarded to the target server.
For example, referring to routing information 1 shown as number 1 in fig. 6, if service message 1 shown in fig. 11 accesses server1, qps does not reach 100, the gateway device may forward the service message to the server corresponding to the target service.
In step 1042b, when the number reaches the current limiting threshold, a fusing mode corresponding to the target service is obtained.
For example, referring to routing information 1 shown by number 1 in fig. 6, if service message 1 shown in fig. 11 accesses server1, qps has reached 100, and the gateway device needs to obtain the value corresponding to the fusing manner, i.e., operation, configured in routing information 1 and corresponding to service server 1. When the operation value is 0, it may indicate that the service message after accessing operation 100 times for the service server1 is discarded; when the operation value is 1, it may indicate that the communication connection between the client and the target service is directly interrupted.
Step 1043, according to the fusing manner, performs an operation to stop forwarding the service message to the target server.
In some embodiments, when the number of service messages of the current routing target service of the gateway device meets the current limiting condition of the gateway device, the fusing mode set by the gateway device may be acquired, and a corresponding operation is performed on the service messages to stop forwarding the service messages to the target server. Stopping forwarding of the service message to the target server may be accomplished by fusing: when the fusing mode indicates to execute the message discarding operation, discarding the service message sent by the client; and when the fusing mode indicates that the connection interruption operation is carried out, interrupting the communication connection between the client and the target server.
According to the embodiment of the application, the service message is injected with the metadata area which can define a plurality of metadata constraints, so that the routing information can be flexibly set. In this way, the client and server can be decoupled: the server only needs to provide specific service functions and does not need to pay attention to the access condition of the client to the service; when the client accesses the service interface, only the function of the service interface is concerned, and the realization and the deployment of a server for providing the service are not concerned. By injecting the routing metadata into the service message sent by the client and configuring corresponding routing information based on the routing metadata, the API gateway can efficiently complete the routing function of the target service. The client only needs to pay attention to the service interface name and the interface protocol, does not need to pay attention to the implementation and the deployment of a server providing the service, does not need to pay attention to a load balancing strategy and a current limiting and fusing strategy, only needs to extract metadata corresponding to the service message to generate a metadata area, and injects the metadata area to the message header of the service message. In addition, the server only needs to concentrate on providing interface service, and does not need to pay attention to the access condition of the service interface. The gateway equipment can also ensure the normal and reliable operation of the back-end service by changing the current limiting strategy or the load balancing strategy of the routing rule; the background service hot updating gray level online can be realized by adjusting routing logic, adding version numbers in the metadata area and the like; therefore, the front-end-back-end coupling is reduced, the development efficiency of the application program service is greatly improved, and the robustness, stability and flexibility of the system are improved.
Next, an exemplary application of the embodiment of the present application in a practical application scenario will be described. Taking a micro-service cluster corresponding to a large-scale game application as an example, in a game service, a client can communicate with a plurality of servers at the back end, for example, the client communicates with a family server to pull family information, the client communicates with a replica server to pull replica information and temporary team formation information, the client communicates with a combat-going server to pull combat information, and the like.
In the related art, referring to fig. 15A to 15B, fig. 15A to 15B are schematic diagrams of related routing configurations provided in this embodiment, fig. 15A is routing configuration information when a 7-layer routing is adopted, a logic (which is a high-performance HTTP and reverse proxy WEB server) mainly faces a WEB server, the 7-layer routing mainly matches a URL with a preconfigured location through a regular expression based on an HTTP protocol, then finds a preconfigured upstream (a module of the logic) through the location, combines a group of target machines into an upstream, and the group of machines can carry a load balancing policy of the logic), and then finds a target end through a load balancing method configured by the upstream. Fig. 15B shows routing configuration information when 4-layer routing is adopted, where the 4-layer routing of Nginx is mainly based on ports, and routes traffic to different predefined upsstreams through different ports, and then finds a destination through a load balancing method defined by the upsstreams.
From the above analysis, it can be seen that the 7-layer routing of Nginx is based on the http protocol, which is routed by regular matching of URLs. The custom protocol mainly works on TCP/UDP, and the carried protocol is not necessarily HTTP protocol, and has no URL field, and thus 7-layer routing can not be used. In addition, for some more complex routing strategies, for example: MSGID is between 2001 and 2010, user UIN is 1000, and the first route is followed, and the other route is followed by 2. Such information is not necessarily in the URL (which may not be based on the http protocol), and even if placed on the URL, the configuration with the regular expression is very complicated and difficult to understand. And the 4-layer routing of the Nginx is based on ports, and a complex custom routing strategy cannot be completed.
Based on this, the message processing method provided by the embodiment of the application is a method for self-defining routing and fusing based on four layers of metadata. By adding a metadata area in the protocol, a plurality of metadata constraints can be defined in the data area, and a very flexible routing strategy can be simply realized. This allows the client and server to be decoupled: the server only needs to provide specific functions and the client only concerns the interface functions and not which server provides. The routing function may be performed by the gateway device by injecting metadata into the client message and configuring the routing rules.
In some embodiments, referring to fig. 16, fig. 16 is a schematic diagram of an architecture of a service message processing system provided in an embodiment of the present application, where the service message processing system provided in the embodiment of the present application includes three parts, namely, a client (shown by reference number 1 in the figure), a gateway device (shown by reference number 2 in the figure, and may be subsequently referred to as an API gateway), and a server (shown by reference number 3 in the figure, and may also be referred to as a server). The client can re-package the service message, and the process for realizing the service message packaging is as follows: C1. setting metadata; C2. a serialized metadata region; C3. adding the metadata area into a custom message header; C4. the message is sent to the API gateway. The API gateway device may implement forwarding of the service message in combination with a preset routing table (shown by reference number 4 in the figure), and implement a forwarding process of the service message as follows: G1. receiving a client message, and taking out a metadata area to perform deserialization to form a plurality of metadata; G2. traversing the road table in sequence, and matching according to the matching fields in the matching logic and the matching method; G3. matching successfully, determining a target routing rule, and continuously checking whether the current limiting and fusing strategies meet the conditions; G4. and if the current limiting strategy is satisfied, selecting a target server to forward the service message according to the routing strategy. The server can implement the response to the service message.
In some embodiments, referring to fig. 17, fig. 17 is a message processing flowchart provided in an embodiment of the present application, and describes a detailed process of matching metadata with each routing information in a routing table by an API gateway, with reference to the steps shown in fig. 17.
Step 401, the client describes the service message with a plurality of metadata, serializes the metadata into a metadata area, adds the metadata area to a message header of the service message, and sends the service message to the gateway device.
In some embodiments, the metadata is mainly used for matching with the routing table on the API gateway device, that is, the metadata is used for indicating information related to the routing information, and may be referred to as routing metadata (the metadata appearing later may be understood as routing metadata), and is data for describing the service message, and may be stored in a key-value pair (key, value) format, where the key and the value may be of a character string type, and may store any type of data. In practical implementation, a plurality of mutually independent metadata can be set for the service message, and each metadata can define a constraint on the route. For example, the metadata identifies for the message: key ═ msgid ', value ═ 100'; the metadata is game user identification: key ═ uin ', value ═ game account 1'.
Since service messages are transmitted in a network connection, they are usually transmitted in the form of a byte stream. In some embodiments, multiple pieces of metadata may be organized into a byte stream by some method of serialization. Referring to fig. 4, a plurality of metadata are distinguished by a preset divider (numbered 1 in the figure), and after a serialization operation, the meta format of the metadata (numbered 2 in the figure) may be a key part (the key part is composed of two parts of the length of the key and the content of the key), a divider (numbered 2-b in the figure), and a value part (the value part is composed of two parts of the length of the value and the content of the value) shown in the figure by number 2-c, which may be the same or different in practical applications.
Step 402, the gateway device deserializes the metadata region into a plurality of metadata, which are matched with the preloaded routing tables.
In actual implementation, after receiving the service message, the API gateway parses the service message, obtains the metadata region from the message header of the service message, and deserializes the metadata region to obtain the routing metadata corresponding to the current service message. Then, the obtained routing metadata is matched with each routing information in a routing table pre-loaded into the memory, and a matching result is obtained, wherein the matching result can be used for indicating whether the routing information corresponding to the routing metadata, namely the target routing information corresponding to the service message, is obtained by matching in the routing table.
Describing a routing table, wherein the routing table is composed of a routing rule (routing information), and a specific execution policy (routing matching rule): matching from front to back; if any rule is successfully matched, the matching process is exited; no route is matched, and a default route is taken for a non-specified route; otherwise an error is returned. The routing rule mainly comprises 4 parts: name, matching rules, routing policies, load balancing policies. Name (name): routing rules are identified and no duplication is allowed. Matching rules (match rules): metadata for matching, and a matching manner (method of matching) are described.
In some embodiments, referring to fig. 7, there are shown 3 matching approaches, the first: exist, the matching field key exists; and the second method comprises the following steps: performing, wherein the key of the matching field exists, and the value is the same as the field value in the routing rule; and the third is that: range, key of matching field exists, and value is between min and max.
In actual implementation, when the gateway device is started, the routing table is loaded, the routing table is analyzed into a routing rule, and the matching logic, the routing strategy, the current limiting strategy and the like are loaded in the memory; if the routing table is updated during the operation of the gateway device, for example, the current limiting policy is adjusted, a new service is added, a server of the new service is added, etc., a signal (update message) may be sent to the API gateway, so that the API gateway device reloads (loads) the routing table. The gateway equipment receives a service message sent by a client, takes out the metadata area through a custom protocol, and analyzes the metadata area into an independent piece of metadata through an agreed deserialization method. Traversing the routing table from front to back, taking out a first routing rule, and through matching fields, matching values and matching methods in the matching logic, judging whether metadata exists, if a plurality of matching fields of the matching logic are matched with the metadata, the routing rule is matched with the message. The matching process is exited. If any matching field does not match, the routing rule is not matched; then the next routing rule is taken out to continue matching.
Step 403, after the route metadata is successfully matched, the gateway device determines the target server through a load balancing policy, and forwards the service message to the target server.
Explaining a routing strategy, wherein the routing strategy describes a successfully matched routing strategy and a load balancing (loadBalancer) method. In some embodiments, referring to fig. 8, a load balancing policy (loadBalancer part shown as number 2 in the figure) and a server part (number 1 in the figure) for routing information (route) are shown. The server part mainly defines the service name (service _ name) and the service instance (service _ id listed by host shown as number 2-1 in the figure) provided by the destination end machine (target server). If no specific instance is specified (host does not list service _ id), or more than 1 service instance is specified (number of service _ id is greater than 1), a load balancing policy (loadBalancer) may be configured.
Describing the load balancing strategy, in some embodiments, loadBalancer mainly defines 3 load balancing strategies: HASH (HASH), consistent HASH (conssistanthash), ROUND ROBIN (ROUND _ ROBIN), and RANDOM (RANDOM). Wherein, the first one: hashing is typically accomplished by hashing the hash key with an algorithm to an integer value and then modulo the instance number, and accessing the first instance if the value is 0 and the second instance if the value is 1. And the second method comprises the following steps: rotation is a method of balancing access in turn, with the first access selecting instance 0 and the second access selecting instance 1. And the third is that: randomness is the calculation of a value by a random algorithm and then modulo the number of service instances, with the value 0 accessing the first instance and 1 accessing the second instance.
In some embodiments, referring to fig. 9, a current limiting configuration (flowcontrol) of the API gateway may be characterized by a QPS (number 1 in the figure), where the QPS defines a maximum traffic threshold of the current routing information, after the API gateway implements current limiting by a preset current limiting algorithm, a subsequent OPERATION on a service message may be implemented by a fusing mode, a fusing configuration (number 2 in the figure) of the API gateway may be characterized by an OPERATION, the OPERATION mainly defines a processing policy that exceeds the threshold, and the applicable policy includes a fusing policy such as discarding or closing a connection.
In actual implementation, if the routing rule is successfully matched in the routing table, it may be further checked whether the current limiting and fusing logic for the routing rule is satisfied, via step 402. If the flow exceeds a set threshold (current limiting threshold), packet loss or disconnection operation is carried out according to a current limiting fusing logic (set fusing mode). If the current-limiting strategy is passed, a specific destination service name can be found according to the routing strategy in the routing rule, and if only one instance is configured for the destination service, the message is directly forwarded to the instance; if a plurality of instances are configured or no instances are configured, one instance needs to be selected for forwarding through a policy defined in the load balancing.
In summary, in the above steps 401 to 403, the client carries metadata information for routing in a customized four-layer protocol, and the information may be described in a plurality of key-value pair formats; the method comprises the following steps that a pre-configured routing table is loaded by an API gateway, the routing table is composed of a plurality of routing rules based on sequence, and each routing rule defines information such as a metadata matching rule, a load balancing algorithm, destination terminal information and a current limiting scheme; the API gateway obtains the metadata information, finds out the matched routing rule through the routing matching rule, and further checks whether the current limiting condition is met, when the current limiting condition is met, the target end (target server) can be found out through a load balancing algorithm, and then the service message is forwarded to the target end. If no matched routing rule is found in the routing table, the default routing rule is used for forwarding the service message to the destination terminal, or the API gateway sends a notification message of routing failure to the client terminal.
According to the embodiment of the application, a metadata area capable of defining a plurality of metadata constraints is added into a custom protocol, so that a very flexible routing strategy can be realized. In this way, the client and server can be decoupled: the server only needs to provide specific functions, and the client only needs to pay attention to the functions of the service interfaces when accessing the service interfaces, and does not need to pay attention to the implementation and deployment of the server providing the services. The API gateway can perform routing functions by injecting metadata into client messages and configuring routing rules. The client only needs to pay attention to the service interface name and the interface protocol, does not need to pay attention to the realization and the deployment of a server providing the service, does not need to pay attention to a load balancing strategy and a current limiting and fusing strategy, only needs to extract metadata corresponding to the service message to generate a metadata area, and adds the metadata area to the message header of the service message. In addition, the server only needs to concentrate on providing interface service, and does not need to pay attention to the access condition of the service interface. The gateway equipment can also ensure the normal and reliable operation of the back-end service by changing the current limiting strategy or the load balancing strategy of the routing rule; the background service hot updating gray level online can be realized by adjusting routing logic, adding version numbers in the metadata area and the like; therefore, the front-end-back-end coupling is reduced, the development efficiency of the application program service is greatly improved, and the robustness, stability and flexibility of the system are improved.
Continuing with the exemplary structure of the message processing apparatus 655 implemented as software modules provided by the embodiments of the present application, in some embodiments, as shown in fig. 2, the software modules stored in the message processing apparatus 655 of the memory 640 may include:
a receiving module 6551, configured to receive a service message sent by a client, where the service message carries routing metadata used for indicating routing information;
an analyzing module 6552, configured to analyze the service message to obtain the routing metadata;
a determining module 6553, configured to determine, according to the routing metadata, a target service corresponding to the service message and a target server corresponding to the target service;
a sending module 6554, configured to forward the service message to the target server, so that the target server returns a response result corresponding to the target message.
In some embodiments, the parsing module is further configured to parse the service message to obtain a routing metadata area, where the routing metadata area includes serialized routing metadata; and performing deserialization on the serialized routing metadata to obtain the routing metadata.
In some embodiments, the determining module is further configured to match the routing information indicated by the routing metadata with routing information in a routing table to determine target routing information in the routing table; determining a target service corresponding to the service message and a service instance corresponding to the target service based on the target routing information; and determining a target server corresponding to the service message according to the service instance corresponding to the target service.
In some embodiments, the routing information indicated by the routing metadata includes a message identifier, and the determining module is further configured to obtain a reference message identifier group included in each piece of routing information in a routing table and a service corresponding to each reference message identifier group; determining a reference message identifier group to which the message identifier belongs as a target message identifier group, and determining routing information comprising the target message identifier group as the target routing information; determining a target service corresponding to the service message based on the target routing information, including: and determining that the service corresponding to the target message identification group is the target service corresponding to the service message based on the target routing information.
In some embodiments, the message identifier is stored in a key-value pair manner, and the determining module is further configured to obtain an identifier value corresponding to the message identifier; determining an identification value range corresponding to each reference message identification group; and determining the identification value range to which the identification value belongs, and determining the corresponding reference message identification group as the target message identification group.
In some embodiments, the determining module is further configured to determine, when the number of the service instances is one, a server where the service instance is located as a target server corresponding to the service message; when the number of the service instances is at least two, determining a target service instance from the at least two service instances according to load balance, and taking a server where the target service instance is located as the target server.
In some embodiments, the sending module is further configured to obtain the number of service messages currently routed by the gateway device to the target service, and a current limiting threshold of the gateway device; wherein the current limit threshold is used to characterize a maximum number of service messages that can be routed to the target service by the gateway device per unit time; forwarding the service message to the target server when the number does not reach the current limit threshold.
In some embodiments, the sending module is further configured to obtain a fusing manner corresponding to the target service when the number reaches the current limiting threshold; the fusing mode is used for indicating the operation executed by forbidding the client to access the target service; and executing the operation according to the fusing mode to stop forwarding the service message to the target server.
In some embodiments, the sending module is further configured to discard the service message sent by the client when the fusing manner indicates to perform a message discarding operation; and when the fusing mode indicates that the connection interruption operation is carried out, interrupting the communication connection between the client and the target server.
Embodiments of the present application provide a computer program product or computer program comprising computer instructions stored in a computer readable storage medium. The processor of the computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes the message processing method described in the embodiment of the present application.
Embodiments of the present application provide a computer-readable storage medium storing executable instructions, which when executed by a processor, will cause the processor to perform a message processing method provided by embodiments of the present application, for example, a message processing method as shown in fig. 3.
In some embodiments, the computer-readable storage medium may be memory such as FRAM, ROM, PROM, EPROM, EEPROM, flash, magnetic surface memory, optical disk, or CD-ROM; or may be various devices including one or any combination of the above memories.
In some embodiments, executable instructions may be written in any form of programming language (including compiled or interpreted languages), in the form of programs, software modules, scripts or code, and may be deployed in any form, including as a stand-alone program or as a module, component, subroutine, or other unit suitable for use in a computing environment.
By way of example, executable instructions may correspond, but do not necessarily have to correspond, to files in a file system, and may be stored in a portion of a file that holds other programs or data, such as in one or more scripts in a hypertext Markup Language (HTML) document, in a single file dedicated to the program in question, or in multiple coordinated files (e.g., files that store one or more modules, sub-programs, or portions of code).
By way of example, executable instructions may be deployed to be executed on one computing device or on multiple computing devices at one site or distributed across multiple sites and interconnected by a communication network.
In summary, in the embodiment of the present application, a metadata area capable of defining a plurality of metadata constraints is added to a custom protocol, so that a very flexible routing policy can be implemented. In this way, the client and server can be decoupled: the server only needs to provide specific functions, and the client only needs to pay attention to the functions of the service interfaces when accessing the service interfaces, and does not need to pay attention to the implementation and deployment of the server providing the services. The API gateway can perform routing functions by injecting metadata into client messages and configuring routing rules. The client only needs to pay attention to the service interface name and the interface protocol, does not need to pay attention to the realization and the deployment of a server providing the service, does not need to pay attention to a load balancing strategy and a current limiting and fusing strategy, only needs to extract metadata corresponding to the service message to generate a metadata area, and adds the metadata area to the message header of the service message. In addition, the server only needs to concentrate on providing interface service, and does not need to pay attention to the access condition of the service interface. The gateway equipment can also ensure the normal and reliable operation of the back-end service by changing the current limiting strategy or the load balancing strategy of the routing rule; the background service hot updating gray level online can be realized by adjusting routing logic, adding version numbers in the metadata area and the like; therefore, the front-end-back-end coupling is reduced, the development efficiency of the application program service is greatly improved, and the robustness, stability and flexibility of the system are improved.
The above description is only an example of the present application, and is not intended to limit the scope of the present application. Any modification, equivalent replacement, and improvement made within the spirit and scope of the present application are included in the protection scope of the present application.

Claims (10)

1. A method of message processing, the method comprising:
the method comprises the steps that gateway equipment receives a service message sent by a client, wherein the service message carries routing metadata used for indicating routing information;
analyzing the service message to obtain the routing metadata;
determining a target service corresponding to the service message and a target server corresponding to the target service according to the routing metadata;
and forwarding the service message to the target server so that the target server returns a response result corresponding to the service message.
2. The method of claim 1, wherein parsing the service message to obtain the routing metadata comprises:
analyzing the service message to obtain a routing metadata area, wherein the routing metadata area comprises serialized routing metadata;
and performing deserialization on the serialized routing metadata to obtain the routing metadata.
3. The method of claim 1, wherein the determining the target service corresponding to the service message and the target server corresponding to the target service according to the routing metadata comprises:
matching the routing information indicated by the routing metadata with routing information in a routing table to determine target routing information in the routing table;
determining a target service corresponding to the service message and a service instance corresponding to the target service based on the target routing information;
and determining a target server corresponding to the service message according to the service instance corresponding to the target service.
4. The method of claim 3, wherein the routing information indicated by the routing metadata includes a message identification;
the matching the routing information indicated by the routing metadata with routing information in a routing table to determine target routing information in the routing table includes:
acquiring a reference message identifier group included in each routing information in a routing table and a service corresponding to each reference message identifier group;
determining a reference message identifier group to which the message identifier belongs as a target message identifier group, and determining routing information comprising the target message identifier group as the target routing information;
determining a target service corresponding to the service message based on the target routing information, including:
and determining that the service corresponding to the target message identification group is the target service corresponding to the service message based on the target routing information.
5. The method of claim 4, wherein the message identifier is stored in a key-value pair manner, and the determining that the reference message identifier group to which the message identifier belongs is a target message identifier group comprises:
acquiring an identification value corresponding to the message identification;
determining an identification value range corresponding to each reference message identification group;
and determining the identification value range to which the identification value belongs, and determining the corresponding reference message identification group as the target message identification group.
6. The method of claim 3, wherein the determining the target server corresponding to the service message according to the service instance corresponding to the target service comprises:
when the number of the service instances is one, determining a server where the service instances are located as a target server corresponding to the service message;
when the number of the service instances is at least two, determining a target service instance from the at least two service instances according to load balance, and taking a server where the target service instance is located as the target server.
7. The method of claim 1, wherein forwarding the service message to the target server comprises:
acquiring the number of service messages of the current routing of the target service of the gateway equipment and a current limiting threshold value of the gateway equipment;
wherein the current limit threshold is used to characterize a maximum number of service messages that can be routed to the target service by the gateway device per unit time;
forwarding the service message to the target server when the number does not reach the current limit threshold.
8. The method of claim 7, further comprising:
when the number reaches the current limiting threshold value, acquiring a fusing mode corresponding to the target service;
the fusing mode is used for indicating the operation executed by forbidding the client to access the target service;
and executing the operation according to the fusing mode to stop forwarding the service message to the target server.
9. The method of claim 7, wherein the performing the operation to stop forwarding the service message to the target server according to the blown manner comprises:
when the fusing mode indicates to execute a message discarding operation, discarding the service message sent by the client;
and when the fusing mode indicates that the connection interruption operation is carried out, interrupting the communication connection between the client and the target server.
10. A message processing apparatus, characterized in that the apparatus comprises:
the system comprises a receiving module, a sending module and a receiving module, wherein the receiving module is used for receiving a service message sent by a client, and the service message carries routing metadata used for indicating routing information;
the analysis module is used for analyzing the service message to obtain the routing metadata;
a determining module, configured to determine, according to the routing metadata, a target service corresponding to the service message and a target server corresponding to the target service;
and the sending module is used for forwarding the service message to the target server so as to enable the target server to return a response result corresponding to the target message.
CN202111282152.1A 2021-11-01 2021-11-01 Message processing method, device, equipment and computer readable storage medium Active CN113992559B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111282152.1A CN113992559B (en) 2021-11-01 2021-11-01 Message processing method, device, equipment and computer readable storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111282152.1A CN113992559B (en) 2021-11-01 2021-11-01 Message processing method, device, equipment and computer readable storage medium

Publications (2)

Publication Number Publication Date
CN113992559A true CN113992559A (en) 2022-01-28
CN113992559B CN113992559B (en) 2023-02-24

Family

ID=79745293

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111282152.1A Active CN113992559B (en) 2021-11-01 2021-11-01 Message processing method, device, equipment and computer readable storage medium

Country Status (1)

Country Link
CN (1) CN113992559B (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115514650A (en) * 2022-09-21 2022-12-23 杭州网易再顾科技有限公司 Bandwidth management method, device, medium and electronic equipment in current limiting scene
WO2023220988A1 (en) * 2022-05-18 2023-11-23 Oppo广东移动通信有限公司 Communication method, network device, and terminal device

Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107645508A (en) * 2017-10-16 2018-01-30 深圳市买买提乐购金融服务有限公司 A kind of data handling system, method, client and server
CN110225104A (en) * 2019-05-24 2019-09-10 深圳市明源云科技有限公司 Data capture method, device and terminal device
CN110837424A (en) * 2019-10-15 2020-02-25 东软集团股份有限公司 Service instance determining method and device, storage medium and electronic equipment
WO2020098025A1 (en) * 2018-11-16 2020-05-22 网宿科技股份有限公司 Static route deployment method, device and system
CN111290865A (en) * 2020-02-10 2020-06-16 腾讯科技(深圳)有限公司 Service calling method and device, electronic equipment and storage medium
CN111600930A (en) * 2020-04-09 2020-08-28 网宿科技股份有限公司 Micro-service request traffic management method, device, server and storage medium
CN112000348A (en) * 2020-07-28 2020-11-27 金蝶医疗软件科技有限公司 Control method and device for service gray release and computer equipment
CN113010313A (en) * 2021-03-16 2021-06-22 深圳市腾讯网络信息技术有限公司 Load balancing method and device, electronic equipment and computer storage medium

Patent Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107645508A (en) * 2017-10-16 2018-01-30 深圳市买买提乐购金融服务有限公司 A kind of data handling system, method, client and server
WO2020098025A1 (en) * 2018-11-16 2020-05-22 网宿科技股份有限公司 Static route deployment method, device and system
CN110225104A (en) * 2019-05-24 2019-09-10 深圳市明源云科技有限公司 Data capture method, device and terminal device
CN110837424A (en) * 2019-10-15 2020-02-25 东软集团股份有限公司 Service instance determining method and device, storage medium and electronic equipment
CN111290865A (en) * 2020-02-10 2020-06-16 腾讯科技(深圳)有限公司 Service calling method and device, electronic equipment and storage medium
CN111600930A (en) * 2020-04-09 2020-08-28 网宿科技股份有限公司 Micro-service request traffic management method, device, server and storage medium
CN112000348A (en) * 2020-07-28 2020-11-27 金蝶医疗软件科技有限公司 Control method and device for service gray release and computer equipment
CN113010313A (en) * 2021-03-16 2021-06-22 深圳市腾讯网络信息技术有限公司 Load balancing method and device, electronic equipment and computer storage medium

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2023220988A1 (en) * 2022-05-18 2023-11-23 Oppo广东移动通信有限公司 Communication method, network device, and terminal device
CN115514650A (en) * 2022-09-21 2022-12-23 杭州网易再顾科技有限公司 Bandwidth management method, device, medium and electronic equipment in current limiting scene

Also Published As

Publication number Publication date
CN113992559B (en) 2023-02-24

Similar Documents

Publication Publication Date Title
CN113992559B (en) Message processing method, device, equipment and computer readable storage medium
US7698269B2 (en) URL shortening and authentication with reverse hash lookup
US9838333B2 (en) Software-defined information centric network (ICN)
CN111901244B (en) Network message forwarding system
US10749805B2 (en) Statistical collection in a network switch natively configured as a load balancer
CN106209830B (en) message construction method based on XML network protocol expression
US20030217096A1 (en) Agent based application using data synchronization
US7328210B2 (en) Attribute rule enforcer for a directory
US9110884B2 (en) Message publishing and subscribing method and apparatus
CN103560905B (en) For configure, apply and manage network equipment object-oriented policy expression system and method
US20170331739A1 (en) Data plane integration
US9935834B1 (en) Automated configuration of virtual port channels
US11184277B1 (en) Reducing routing rules used to route traffic
US10033631B1 (en) Route distribution for service appliances
US20230045247A1 (en) Transmitting network traffic to a pool of redundant network appliances
CN113489652A (en) Data stream amplification method and device, convergence splitter and storage medium
CN113783781A (en) Method and device for interworking between virtual private clouds
CN110913011B (en) Session holding method, session holding device, readable storage medium and electronic device
CN110290060B (en) Cross-network communication method, device and storage medium
US10103995B1 (en) System and method for automated policy-based routing
Michel Lombera et al. Mobile decentralized search and retrieval using SMS and HTTP
Shao et al. Accelerating bgp configuration verification through reducing cycles in smt constraints
CN115801298A (en) Method, system, device and storage medium for file transmission
US10116698B1 (en) Managing network firewall configuration utilizing source lists
CN117041272B (en) Data processing method, device, equipment and storage medium

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
GR01 Patent grant
GR01 Patent grant