当前位置:网站首页>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 .
边栏推荐
- Understanding of homogeneous coordinates
- What characteristics should a good design website have?
- Several stacks of technology sharing: product managers' Online Official answers to several stacks of knowledge
- Any 与 TypeVar,让 IDE 的自动补全更好用
- 【本周六活动】.NET Day in China
- Why does the virtual machine Ping the host but not the virtual machine
- Beauty of script │ VBS introduction interactive practice
- What code did the full stack programmer write this month?
- [graduation season · attacking technology Er] three turns around the tree, what branch can we rely on?
- Lightweight deployment of firefoxsend temporary file sharing service using Tencent cloud
猜你喜欢

Qt: judge whether the string is in numeric format

2D 照片变身 3D 模型,来看英伟达的 AI 新“魔法”!

喜歡就去行動

齐次坐标的理解

喜欢就去行动

TP-LINK 1208路由器教程(2)

math_ Summation and derivation of proportional series & derivation of sum and difference of equal powers / difference between two nth power numbers/

Any and typevar make the automatic completion of IDE better

程序员大部分时间不是写代码,而是。。。

Moving Tencent to the cloud cured their technical anxiety
随机推荐
程序员大部分时间不是写代码,而是。。。
Canvas pipe animation JS special effect
PPT绘图相关,快捷键,美观度
Fais ce que tu veux.
Simple pricelist style code
Cause analysis of frequent crash and restart of easynvr-arm cloud terminal
math_ Summation and derivation of proportional series & derivation of sum and difference of equal powers / difference between two nth power numbers/
TP-LINK 1208路由器教程(2)
Audio knowledge (III) -- MFCCs code implementation
Use the process monitor tool to monitor process operations on registries and files
How to open a video number?
Internship experience sharing in ByteDance 𞓜 ten thousand word job guide
Ppt drawing related, shortcut keys, aesthetics
Qt: judge whether the string is in numeric format
System design: key features of distributed systems
Suddenly I thought of the wooden house in my hometown
Anonymous Messenger: hidden communication of Trojan horse
Redis
What is the function of the graphics card driver? Do you want to update the graphics card driver
图片的可视化呈现有效增强大屏吸引力