当前位置:网站首页>Fizz gateway secondary development integration tutorial
Fizz gateway secondary development integration tutorial
2022-06-24 11:16:00 【openapplus】
summary
fizz 2.0 Modular design is adopted , Include :
- fizz-spring-boot-starter modular , Facilitate third-party rapid integration fizz gateway .
- fizz-bootstrap modular , Demo module , Show how third parties integrate fizz, It is recommended that the third party use this module as the skeleton application gateway , And carry out secondary development .
The following is an example of the gateway log plug-in to introduce the topic .
Integrate fizz gateway
establish spring boot maven engineering , Suggest 2.2.13.RELEASE edition
adjustment pom
To configure properties
<properties>
<java.version>1.8</java.version>
<fizz.version>2.0.0</fizz.version>
<spring-framework.version>5.2.15.RELEASE</spring-framework.version>
<reactor-bom.version>Dysprosium-SR20</reactor-bom.version>
<lettuce.version>5.3.7.RELEASE</lettuce.version>
<netty.version>4.1.65.Final</netty.version>
<httpcore.version>4.4.14</httpcore.version>
<log4j2.version>2.13.3</log4j2.version>
<commons-lang3.version>3.12.0</commons-lang3.version>
<lombok.version>1.18.20</lombok.version>
<apache.dubbo.version>2.7.5</apache.dubbo.version>
<grpc.version>1.16.1</grpc.version>
<mockito.version>3.4.6</mockito.version>
<curator.version>4.0.1</curator.version>
<zookeeper.version>3.5.9</zookeeper.version>
</properties>
<!-- these properties Specify the version that the gateway depends on -->Join in fizz Gateway depends on
<dependency>
<groupId>com.fizzgate</groupId>
<artifactId>fizz-common</artifactId>
<version>${fizz.version}</version>
</dependency>
<dependency>
<groupId>com.fizzgate</groupId>
<artifactId>fizz-spring-boot-starter</artifactId>
<version>${fizz.version}</version>
</dependency>Adjust configuration
Copy fizz-bootstrap modular resources Under the js Catalog 、application.yml、log4j2-spring.xml, To the corresponding location of the current project , adjustment :
Manage the background for the gateway redis;
If not for performance testing , Adjustable log4j2-spring.xml The log level in is info/debug.
Project start class
Copy fizz-bootstrap Of FizzBootstrapApplication.java To the project source directory , Name adjustable , Run startup class , If there is no error log , Description Introduction fizz success .
Development log plug-in
Plug in development includes adding plug-in definitions 、 Write plug-in filters 、 Manage background application configuration .
Add plug-in definitions in the management background
The plug-in name is also the name of the plug-in id Unique ,order Is the execution order of the plug-in , It is also the display order of plug-ins on the interface .
Form definition :
[
{
"field":"logReqId",
"label":" Print request id journal ",
"component":"radio",
"dataType":"boolean",
"default":false,
"options":[
{
"label":" yes ",
"value":true
},
{
"label":" no ",
"value":false
}
]
},
{
"field":"appendFizzRsv",
"label":" add to fizzRsv Request header ",
"component":"radio",
"dataType":"boolean",
"default":false,
"options":[
{
"label":" yes ",
"value":true
},
{
"label":" no ",
"value":false
}
]
}
]
The front end of the management background generates the configuration form of the plug-in based on this Write plug-in filters
@Component(LogPluginFilter.LOG_PLUGIN_FILTER) // With the plug-in above id Agreement
public class LogPluginFilter extends PluginFilter {
private static final Logger log = LoggerFactory.getLogger(LogPluginFilter.class);
public static final String LOG_PLUGIN_FILTER = "logPlugin";
@Override
public Mono<Void> doFilter(ServerWebExchange exchange, Map<String, Object> config, String fixedConfig) {
String rid = exchange.getRequest().getId();
Boolean logReqId = (Boolean) config.get("logReqId"); // Whether to print the request id journal , That is, the above definition , It can be configured through background management
if (logReqId == null || logReqId) {
log.info(exchange.getRequest().getURI().toString() + " Request id: " + rid);
}
Boolean appendFizzRsv = (Boolean) config.get("appendFizzRsv");
if (appendFizzRsv == null || appendFizzRsv) {
WebUtils.appendHeader(exchange, "FIZZ-RSV", rid);
}
return WebUtils.transmitSuccessFilterResultAndEmptyMono(exchange, LOG_PLUGIN_FILTER, null); // Save the plug-in execution results , And back to
}
}
The plug-in must be a spring Of Component( Or sub annotation ), Project startup class scanBasePackages To override the plug-in pkg;
The plug-in implements two functions , Record request id journal , Add... When forwarding a request FIZZ-RSV Request header , And the function can be turned on or off .# Application plug-in
Yes
Routing application plug-in :
Configured above " Print request id journal "、" add to fizzRsv Request header ", Corresponding
public Mono<Void> doFilter(ServerWebExchange exchange, Map<String, Object> config, String fixedConfig)
in config Of logReqId and appendFizzRsv key, Restart project , Access the previous route , If there is a corresponding log output , Indicates that the plug-in is in effect .
边栏推荐
- 09. Tencent cloud IOT device side learning -- RRPC and behavior
- Understanding of homogeneous coordinates
- Adobe Photoshop using the box selection tool for selection tutorial
- 【毕业季·进击的技术er】绕树三匝,何枝可依?
- Install wpr Exe command
- The record of 1300+ times of listing and the pursuit of ultimate happiness
- Investing in a good navigation framework from the beginning of the jetpack compose tutorial will help you save a lot of migration work later
- 图片的可视化呈现有效增强大屏吸引力
- MYSQL_精讲数据库数据类型
- Today's sleep quality record 76 points
猜你喜欢

Simple pricelist style code

PHP短信通知+语音播报自动双呼

Libuv的安装及运行使用

Act as you like

Rising bubble canvas breaking animation JS special effect

First acquaintance with string+ simple usage (I)

Group counting_ Structure and workflow of CPU

Déplacer Tencent sur le cloud a guéri leur anxiété technologique

服乔布斯不服库克,苹果传奇设计团队解散内幕曝光

图片的可视化呈现有效增强大屏吸引力
随机推荐
Act as you like
程序员大部分时间不是写代码,而是。。。
Functions of document management what functions does the document management software have
Why use a firewall? What is the function of firewall?
Clickhouse deployment and basic usage 1
How to export only the titles in word documents? (i.e. delete all the text contents and keep only the title) stop B
How to improve the quality of Baidu keyword?
MYSQL_精讲数据库数据类型
09. Tencent cloud IOT device side learning -- RRPC and behavior
TP-LINK 1208路由器教程(2)
Why does the virtual machine Ping the host but not the virtual machine
Dedecms template file explanation and homepage label replacement
How to use data analysis tools to deal with emergencies in retail industry
Opencv optical flow prediction and remap remapping function usage
Cloud vendor secondary virtualization restrictions
Nacos source code - configure automatic update
Maui's way of learning -- Opening
Qt: judge whether the string is in numeric format
MYSQL_ Elaborate on database data types
@RequestBody注解