Dynamic routing arrangement method and system based on Spring Cloud Gateway

文档序号:1965916 发布日期:2021-12-14 浏览:13次 中文

阅读说明:本技术 一种基于Spring Cloud Gateway实现的动态路由编排方法及系统 (Dynamic routing arrangement method and system based on Spring Cloud Gateway ) 是由 李飞 范文斌 李凌悦 王涛 杨洪伟 于 2021-08-11 设计创作,主要内容包括:本发明公开了一种基于Spring Cloud Gateway实现的动态路由编排方法及系统,属于服务网关技术领域,包括以下步骤:S1:注册动态路由规则信息;S2:启动加载监听动态路由配置;S3:请求调用网关;S4:匹配路由过滤控制策略;S5:执行动态路由编排流程;S6:请求返回。本发明通过实现Spring Cloud Gateway动态路由的编排,完成了一个服务网关的从无到有,服务提供者无需关心动态路由编排细节,只须按要求配置对应的策略信息即可生成一个服务网关,服务网关统一调用地址前缀,依靠全局过滤器集中管控所有网关,根据私有过滤器隔离管控单独网关,调用过程中日志分阶段异步保存,请求返回结果准确可靠,网关性能高可用。(The invention discloses a dynamic routing arranging method and a dynamic routing arranging system based on Spring Cloud Gateway, which belong to the technical field of service gateways and comprise the following steps: s1: registering dynamic routing rule information; s2: starting loading and monitoring dynamic route configuration; s3: requesting to call a gateway; s4: matching a route filtering control strategy; s5: executing a dynamic routing arrangement process; s6: and returning the request. The invention completes the existence of a service Gateway by realizing the arrangement of the Spring Cloud Gateway dynamic route, a service provider does not need to care about the arrangement details of the dynamic route, only needs to configure corresponding strategy information according to requirements to generate the service Gateway, the service Gateway uniformly calls the address prefix, intensively controls all gateways by depending on a global filter, isolates and controls the single Gateway according to a private filter, logs are asynchronously stored in stages in the calling process, the request return result is accurate and reliable, and the Gateway performance is high and usable.)

1. A dynamic routing arranging method realized based on Spring Cloud Gateway is characterized by comprising the following steps:

s1: registering dynamic routing rule information

The service provider provides a service system interface required to be registered, perfects basic service information, arranges resources, determines the flow direction and arrangement processing requirements of the dynamic route, and adds necessary filtering to the dynamic route as a limiting strategy of the service gateway;

s2: boot load snoop dynamic routing configuration

Starting a Spring Cloud Gateway system, monitoring the configuration of a dynamic route, loading rule information into the Spring Cloud Gateway route, continuously monitoring, and refreshing the rule information into the route in real time when the route information changes;

s3: request call gateway

A consumer or a system administrator calls a unified open address of the service gateway, a unique service code is spliced, the code is an identifier, and necessary parameters are input to send a request to the service gateway;

s4: matched route filtering control strategy

The service gateway request path carries a route unique identifier, and is identified by the gateway route to match with the filtering rules corresponding to the global and private filters;

s5: executing dynamic routing choreography flow

In the request processing process of the service gateway, arranging a plurality of routing resources, adapting http resources and groovy resources, converting resource information of different routes, and recording response log information of different resources;

s6: request return

And after the routing strategy is successfully executed, the service gateway returns service interface data provided by the service provider, records the return information to the log, and the service gateway finishes calling.

2. The dynamic routing orchestration method based on Spring Cloud Gateway of claim 1, wherein: in step S1, the service provider provides a plurality of original resource information, performs arrangement operations on different resources, determines the flow direction of the resource, specifies the service name, the service code, the system to which the service belongs, the service home center, and the service request mode, and completes the registration of the basic information.

3. The dynamic routing orchestration method based on Spring Cloud Gateway of claim 2, wherein: in step S1, after the registration is completed, the global filter and the private filter are configured according to the routing arrangement requirement, the private filter is unique to each of the different service gateways, and the global filter has a control function on all the service gateways, that is, based on the Spring Cloud Gateway routing rule, the black and white list, the current limit, and the fusing policy are configured, so as to provide policy guarantee for the dynamic routing.

4. The dynamic routing orchestration method based on Spring Cloud Gateway of claim 1, wherein: in step S2, after the Spring Cloud Gateway system is started, the routing information is obtained from the micro service dynamic configuration service nacos, and an external API provided by the nacos is called to complete real-time monitoring of dynamic routing change.

5. The dynamic routing orchestration method based on Spring Cloud Gateway of claim 4, wherein: in step S2, a cache area is established in the nacos, and is used for storing the dynamic route identifier information, and monitoring the cache area to complete monitoring of the new route, that is, to complete real-time monitoring of the dynamic route configuration; and the dynamic routing information monitoring executes dynamic routing service (dynamic routing service) at the same time, and dynamically adds or modifies new routing information according to the requirement of the routing information by the Spring Cloud Gateway routing rule.

6. The dynamic routing orchestration method based on Spring Cloud Gateway of claim 1, wherein: in step S3, the dynamic routing provides a uniform external address, the consumer or the system administrator splices the unique identifier endpoint request call, inputs the request message information, and the routing can analyze the routing information in the request call process.

7. The dynamic routing orchestration method based on Spring Cloud Gateway of claim 1, wherein: in step S4, when the request enters the dynamic routing, the execution order of each filter is specified according to the Spring Cloud Gateway routing rule.

8. The dynamic routing orchestration method based on Spring Cloud Gateway of claim 1, wherein: in step S5, in the service gateway processing process, after a resource is executed, processing the resource response information, recording the response information in a log, acquiring a data stream after response to another resource in the routing arrangement, and when the resource is an HTTP resource, using the previous resource response data as a reference of the next resource to complete calling inside the route; and when the other resource is a groovy resource, outputting different results according to different logics of the groovy resource script.

9. The dynamic routing orchestration method based on Spring Cloud Gateway of claim 1, wherein: in step S6, after the request gateway performs filtering and dynamic arrangement, the previously registered service interface return data changes correspondingly according to the arrangement processing and the requirement of the consumer, and the log information is stored while the data is returned after the request is finished.

10. A dynamic routing arrangement system realized based on Spring Cloud Gateway is characterized in that: the dynamic routing orchestration method according to any one of claims 1 to 9, comprising a service provider, a service consumer, a micro-service management and control center, a dynamic routing monitoring module, a routing filtering rule matching module, a dynamic routing orchestration module, and a logging center;

the service provider is used for registering basic information of the dynamic route and determining the flow direction and the processing requirement of the dynamic route;

the service consumer is used for calling a service gateway for dynamic routing arrangement, transmitting necessary routing information and adapting the routing;

the micro-service management and control center is used for caching basic information of dynamic route registration and opening an external API for calling and obtaining when a gateway monitors;

the dynamic route monitoring module is used for monitoring the change of the dynamic route and updating the newly added or modified route information into the routing rule of the Spring Cloud Gateway system in real time;

the route filtering rule matching module is used for ensuring the safety and the availability of the service gateway, providing global, private and multidimensional strategy control, maintaining and managing the safety strategy of the life cycle of the whole route and providing a global management and control platform for managers;

the dynamic routing arrangement module is used for processing the response information of the internal resources of the routing, compiling script information, appointing the flow direction of the resources and outputting the response information according to the format required by the service provider;

the log recording center is used for operation and maintenance of dynamic routing arrangement, and monitoring the calling execution condition of the whole Spring Cloud Gateway system by receiving the summary information of the Gateway request, the response information in the arrangement process and the request return information for result analysis.

Technical Field

The invention relates to the technical field of service gateways, in particular to a dynamic routing arrangement method and a dynamic routing arrangement system based on Spring Cloud Gateway.

Background

In the IT field, recently, micro service architecture is prevalent, one system is often composed of a plurality of systems, standing in the view of functions, abstracting business logic into reusable and assemblable services, and realizing rapid regeneration of the business through arrangement of the services, thereby converting original inherent business functions into general business services, realizing rapid reuse of the business logic, and in order to uniformly manage each service, a gateway should be operated, which aims to provide a simple and effective uniform API route management mode.

In the application process of the Gateway, compared with other gateways, the Spring Cloud Gateway not only provides a uniform access address, but also can apply a filter strategy, and the response type development mode based on Netty is realized more efficiently. However, the conventional Spring Cloud Gateway call generally aims at a single resource, and the returned data cannot be processed again, so that a dynamic routing arranging method and a dynamic routing arranging system realized based on the Spring Cloud Gateway are provided.

Disclosure of Invention

The technical problem to be solved by the invention is as follows: how to realize a matched route filtering strategy based on the Spring Cloud Gateway, executing a dynamic route arranging function, enriching the dimension of the Gateway in management and control, solving the problems that the calling of the Spring Cloud Gateway generally aims at a single resource and the returned data can not be processed again, and providing the dynamic route arranging method based on the Spring Cloud Gateway.

The invention solves the technical problems through the following technical scheme, and the invention comprises the following steps:

s1: registering dynamic routing rule information

The service provider provides a service system interface required to be registered, perfects basic service information, arranges resources, determines the flow direction and arrangement processing requirements of the dynamic route, and adds necessary filtering to the dynamic route as a limiting strategy of the service gateway;

s2: boot load snoop dynamic routing configuration

Starting a Spring Cloud Gateway system, monitoring the configuration of a dynamic route, loading rule information into the Spring Cloud Gateway route, continuously monitoring, and refreshing the rule information into the route in real time when the route information changes;

s3: request call gateway

A consumer or a system administrator calls a unified open address of the service gateway, a unique service code is spliced, the code is an identifier, and necessary parameters are input to send a request to the service gateway;

s4: matched route filtering control strategy

The service gateway request path carries a route unique identifier, and is identified by gateway routes and matched with private filtering rules, the private filtering rules are unique to different gateways, and a global filter has a control function on all service gateways;

s5: executing dynamic routing choreography flow

In the request processing process of the service gateway, arranging a plurality of routing resources, adapting http resources and groovy resources, converting resource information of different routes, and recording response log information of different resources;

s6: request return

And after the routing strategy is successfully executed, the service gateway returns service interface data provided by the service provider, records the return information to the log, and the service gateway finishes calling.

Further, in step S1, the service provider provides a plurality of original resource information, performs arrangement operations on different resources, determines the flow direction of the resource, specifies the service name, the service code, the system to which the service belongs, the service home center, and the service request mode, and completes the basic information registration, that is, the dynamic routing of the unique identifier and the special classification of the external router.

Further, in step S1, after the registration is completed, the configuration of the global filter and the private filter is performed according to the routing arrangement requirement, where black and white lists, current limits, and fusing policies are configured based on the Spring Cloud Gateway routing rule, so as to provide policy guarantee for dynamic routing.

Further, in step S2, after the Spring Cloud Gateway system is started, the routing information is obtained from the micro service dynamic configuration service nacos, and an external API provided by the nacos is called to complete real-time monitoring of dynamic routing change.

Further, in step S2, a cache region is established in the nacos, and is dedicated to store the dynamic route identifier information, and the cache region is monitored to complete monitoring of the new route, that is, to complete real-time monitoring of the dynamic route configuration; and the dynamic routing information monitoring executes dynamic routing service (dynamic routing service) at the same time, and dynamically adds or modifies new routing information according to the requirement of the routing information by the Spring Cloud Gateway routing rule.

Further, in step S3, the dynamic routing provides a unified external address, the consumer or the system administrator splices the unique routing identifier endpoint request call, inputs the request message information, and the routing can analyze the routing information in the request call process.

Further, in the step S4, when the request enters the dynamic routing, the execution sequence of each filter is specified according to the Spring Cloud Gateway routing rule.

Further, in step S5, in the service gateway processing process, after a resource is executed, processing the resource response information, recording the response information in the log, obtaining that the data stream after response flows to another resource in the routing arrangement, and when the resource is an HTTP resource, taking the previous resource response data as a reference of the next resource, and completing invoking inside the route; and when the other resource is a groovy resource, outputting different results according to different logics of the groovy resource script.

Further, in step S6, after the request gateway performs filtering and dynamic arrangement, the service interface return data registered before has changed correspondingly according to the arrangement processing and the requirement of the consumer, and the log information is saved while the data is returned after the request is finished.

The invention also provides a dynamic routing arrangement system realized based on Spring Cloud Gateway, which is used for the dynamic routing arrangement method and comprises a service provider, a service consumer, a micro-service management and control center, a dynamic routing monitoring module, a routing filtering rule matching module, a dynamic routing arrangement module and a log recording center;

the service provider is used for registering basic information of the dynamic route and determining the flow direction and the processing requirement of the dynamic route;

the service consumer is used for calling a service gateway for dynamic routing arrangement, transmitting necessary routing information and adapting the routing;

the micro-service management and control center is used for caching basic information of dynamic route registration and opening an external API for calling and obtaining when a gateway monitors;

the dynamic route monitoring module is used for monitoring the change of the dynamic route and updating the newly added or modified route information into the routing rule of the Spring Cloud Gateway system in real time;

the route filtering rule matching module is used for ensuring the safety and the availability of the service gateway, providing global, private and multidimensional strategy control, maintaining and managing the safety strategy of the life cycle of the whole route and providing a global management and control platform for managers;

the dynamic routing arrangement module is used for processing the response information of the internal resources of the routing, compiling script information, appointing the flow direction of the resources and outputting the response information according to the format required by the service provider;

the log recording center is used for operation and maintenance of dynamic routing arrangement, and monitoring the calling execution condition of the whole Spring Cloud Gateway system by receiving the summary information of the Gateway request, the response information in the arrangement process and the request return information for result analysis.

Compared with the prior art, the invention has the following advantages: according to the dynamic routing arrangement method based on the Spring Cloud Gateway, the arrangement of the Spring Cloud Gateway dynamic routing is realized, the existence of a service Gateway is completed, a service provider does not need to care about the details of the dynamic routing arrangement, the service Gateway can be generated only by configuring corresponding strategy information according to requirements, the service Gateway uniformly calls an address prefix, all gateways are intensively controlled and controlled by a global filter, an individual Gateway is isolated and controlled according to a private filter, logs are asynchronously stored in a calling process in stages, the request return result is accurate and reliable, the Gateway performance is high and available, and the method is worthy of popularization and use.

Drawings

Fig. 1 is a schematic flow chart of a dynamic routing method implemented based on a Spring Cloud Gateway in the embodiment of the present invention.

Detailed Description

The following examples are given for the detailed implementation and specific operation of the present invention, but the scope of the present invention is not limited to the following examples.

The embodiment provides a technical scheme: a dynamic routing arrangement method based on Spring Cloud Gateway comprises the following steps:

step S1: registering dynamic routing rule information

The service provider provides a service system interface required to be registered, perfects basic service information, arranges resources, and determines the flow direction and arrangement processing requirements of the dynamic route; adding necessary filtering into a dynamic route, wherein the filtering comprises a black and white list, current limiting, fusing and the like, and the filtering is used as a limiting strategy of a service gateway;

step S2: boot load snoop dynamic routing configuration

Starting a Spring Cloud Gateway system, automatically monitoring the configuration of a dynamic route, loading rule information into the Spring Cloud Gateway route, continuously monitoring, and refreshing the route in real time once the route information changes;

step S3: request call gateway

A consumer or a system administrator calls a unified open address of the service gateway, splices the unique code of the service, inputs necessary parameters and sends a request to the service gateway;

step S4: matched route filtering control strategy

The service gateway request path carries a route unique identifier, and is automatically matched with private filtering rules through gateway route identification, the private filtering rules are unique to different gateways, and a global filter has a control function on all service gateways;

step S5: executing dynamic routing choreography flow

In the request processing process of the service gateway, arranging a plurality of routing resources, adapting http resources and groovy resources, converting resource information of different routes, and recording response log information of different resources;

step S6: request return

And after the routing strategy is successfully executed, the service gateway returns service interface data provided by the service provider, records the return information to the log, and the service gateway finishes calling.

In this embodiment, in step S1, the service provider provides a plurality of original resource information, performs arrangement operations on different resources, determines the flow direction of the resource, specifies the service name, the service code, the system to which the service belongs, the service home center, and the service request mode, and completes a basic information registration, that is, the external unique identifier and the special classification of the dynamic route. After the registration is completed, the configuration of the global filter and the private filter is carried out according to the routing arrangement requirement, and the policies such as a black and white list, current limiting, fusing and the like are configured based on the Spring Cloud Gateway routing rule, so that the policy guarantee is provided for the dynamic routing.

In this embodiment, in step S2, once the Gateway system (Spring Cloud Gateway system) is started, dynamic routing information is automatically monitored, where the routing information is obtained from the micro service dynamic configuration service nacos, an external API provided by the nacos is called to complete real-time monitoring of dynamic routing changes, the API provided by the nacos cannot monitor a new problem of the dynamic routing, and a cache region is established in the nacos for this purpose in step S2, and is specially stored with the dynamic routing identification information, and monitors the cache region to complete monitoring of the new routing, that is, to complete real-time monitoring of the dynamic routing configuration. And the dynamic routing information monitoring executes dynamic routing service (dynamic routing service) at the same time, and dynamically adds or modifies new routing information according to the requirement of the routing information by the Spring Cloud Gateway routing rule.

In this embodiment, in step S3, the dynamic routing provides a unified external address, the consumer or the system administrator splices information such as an unique identifier endpoint (i.e., a service code) of the routing request, and inputs a request message, and the routing can analyze routing information including the service code during the request invocation process, and the service code is used as a unique identifier, and enters the dynamic routing arrangement gateway similar to a pass.

In this embodiment, in step S4, when the request enters the dynamic routing, the execution order of each type of filter is specified according to the Spring Cloud Gateway routing rule, and the filter getOrder rewriting method is as follows:

the smaller the return result is, the earlier the return result is, the dynamic routing orchestration gateway respectively executes global IP black and white list filtering, global current limiting processing, analysis routing parameter filtering, global IP dimension current limiting, global application black and white list filtering, authentication filtering, global user dimension black and white list filtering, private service dimension IP black and white list filtering, private service dimension service current limiting filtering, private service + IP combined current limiting filtering, private service dimension service fusing filtering and the like. The black and white list of the IP limits that only some IPs can be called or some IPs cannot be called; in the route parameter analysis, log information is recorded simultaneously by analyzing token, frompip, body and the like, so that the dynamic route calling of later-stage statistics can be conveniently used; the security of application calling is ensured by checking appKey in authentication; in the current-limiting filtering, the phenomenon that the gateway service bearing is exceeded to cause breakdown because multiple requests occur in a short time in the gateway route is prevented; in the fusing filtering, if a certain service is abnormal too much or the request time is too long, a degradation mechanism is executed, and the normal calling of other gateways is ensured.

In this embodiment, in step S5, in the service gateway processing process, after a resource is executed, it needs to process the resource response information, and record the response information in the log, so as to ensure the backup of data before processing, obtain the data stream after response to another resource in the route arrangement, and when the resource is an HTTP resource, use the response data of the previous resource as the entry parameter of the next resource, and complete the invocation inside the route; when another resource is a groovy resource, different results are output according to different logics of the groovy resource script, such as filtering response data or adding identification information to the response data.

In this embodiment, in step S6, after the request Gateway performs filtering and dynamic arrangement, the previously registered service interface return data has changed correspondingly according to the arrangement processing and the requirement of the consumer, and is more safely usable under the protection of the Spring Cloud Gateway system, and the log information is saved while the data is returned after the request is finished.

The invention discloses a system for realizing a dynamic routing arrangement method based on Spring Cloud Gateway, which comprises a service provider, a service consumer, a micro-service management and control center (namely the service management and control center in figure 1), a dynamic routing monitoring module, a routing filtering rule matching module, a dynamic routing arrangement module and a log recording center, wherein the service provider is connected with the service consumer through a network;

the service provider is used for registering basic information of the dynamic route, including unique identification endpoint and the like, arranging resources and determining the flow direction and processing requirement of the dynamic route;

the service consumer is used for calling a service gateway for dynamic routing arrangement, transmitting necessary routing information and adapting the routing;

the micro-service management and control center is used for caching basic information of dynamic route registration and providing external API (application programming interface) for calling and obtaining when the gateway monitors conveniently;

the dynamic route monitoring module is used for monitoring the change of the dynamic route and updating the newly added or modified route information into the routing rule of the Spring Cloud Gateway system in real time;

the routing filtering rule matching module is used for ensuring the safe availability of the service gateway, providing global, private and multidimensional policy control, maintaining and managing the security policy of the life cycle of the whole routing, ensuring the high availability of dynamic routing call and providing a global management and control platform for managers;

the dynamic routing arrangement module is used for processing the response information of the internal resources of the routing, compiling script information, appointing the flow direction of the resources and outputting the response information according to the format required by the service provider;

the log recording center is used for operation and maintenance of dynamic routing arrangement, and monitoring the calling execution condition of the whole Spring Cloud Gateway system by receiving the summary information of the Gateway request, the response information in the arrangement process and the request return information for result analysis.

It should be noted that, in the above embodiments, the included units are only divided according to functional logic, but are not limited to the above division as long as the corresponding functions can be realized; in addition, specific names of the functional units are only for convenience of distinguishing from each other, and are not used for limiting the protection scope of the present invention.

In addition, it is understood by those skilled in the art that all or part of the steps in the method for implementing the embodiments described above may be implemented by a program instructing associated hardware, and the corresponding program may be stored in a computer-readable storage medium.

To sum up, the dynamic routing arrangement method implemented based on the Spring Cloud Gateway according to the above embodiment completes the existence of a service Gateway, a service provider does not need to care about the dynamic routing arrangement details, and can generate a service Gateway by configuring corresponding policy information as required, the service Gateway uniformly calls an address prefix, centrally controls all gateways by means of a global filter, and controls individual gateways by means of private filter isolation, logs are asynchronously stored in stages in the calling process, the request return result is accurate and reliable, the Gateway performance is high, and the method is worthy of being popularized and used.

Although embodiments of the present invention have been shown and described above, it is understood that the above embodiments are exemplary and should not be construed as limiting the present invention, and that variations, modifications, substitutions and alterations can be made to the above embodiments by those of ordinary skill in the art within the scope of the present invention.

10页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:SID列表的处理方法及装置

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!