# Overview
fizz 2.0 adopts a modular design, including:
fizz-spring-boot-starter module to facilitate third parties to quickly integrate fizz gateway.
fizz-bootstrap module, a demonstration module that shows how third parties integrate fizz. It is recommended that third parties use this module as a skeleton application gateway and conduct secondary development.
The following uses the example of the gateway log plug-in to introduce the topic.
# Integrate fizz gateway
# Create spring boot maven project, recommended version 2.2.13.RELEASE
# Adjust pom
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 of the gateway dependency -->
Add fizz gateway dependency
<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>
Note:
https://mvnrepository.com/artifact/com.github.wehotel/fizz-bootstrap
https://mvnrepository.com/artifact/com.github.wehotel/fizz-gateway-node
This is a legacy test package, please do not use it.
# Adjust configuration
Copy the js directory, application.yml, and log4j2-spring.xml under the resources of the fizz-bootstrap module to the corresponding location of the current project, and adjust:
Manage the backend redis for the gateway;
If it is not for performance testing, you can adjust the log level in log4j2-spring.xml to info/debug.
# Project startup class
Copy FizzBootstrapApplication.java of fizz-bootstrap to the project source code directory. The name can be adjusted. Run the startup class. If there is no error log, it means that fizz is introduced successfully.
# Development log plug-in
The development of plug-ins includes adding plug-in definitions, writing plug-in filters, and managing background application configurations.
# Add new plug-in definition in the management background
The plug-in name is also the plug-in id and must be unique, and order is the execution order of the plug-in, which is also the order in which the plug-in is displayed on the interface.
Form definition:
[
{
"field":"logReqId",
"label":"Print request id log",
"component":"radio",
"dataType":"boolean",
"default":false,
"options":[
{
"label":"Yes",
"value":true
},
{
"label":"No",
"value":false
}
]
},
{
"field":"appendFizzGateRsv",
"label":"Add 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 plug-in configuration form accordingly.
###Writing plug-in filters
@Component(LogPluginFilter.LOG_PLUGIN_FILTER) // Consistent with the plug-in id above
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 log, that is, the above definition, can be configured through the management background
if (logReqId == null || logReqId) {
log.info(exchange.getRequest().getURI().toString() + " request id: " + rid);
}
Boolean appendFizzGateRsv = (Boolean) config.get("appendFizzGateRsv");
if (appendFizzGateRsv == null || appendFizzGateRsv) {
WebUtils.appendHeader(exchange, "FIZZ-RSV", rid);
}
return WebUtils.transmitSuccessFilterResultAndEmptyMono(exchange, LOG_PLUGIN_FILTER, null); // Save the plug-in execution result and return
}
}
The plug-in must be a spring Component (or sub-annotation), and the scanBasePackages of the project startup class must override the plug-in's pkg;
The plug-in implements two functions, recording the request id log, and adding the FIZZ-RSV request header when forwarding the request, and the function can be turned on or off.
# Apply plugin
right
Routing application plug-in:
The "print request id log" and "add fizzRsv request header" configured above correspond to
public Mono<Void> doFilter(ServerWebExchange exchange, Map<String, Object> config, String fixedConfig)
In the config's logReqId and appendFizzGateRsv key, restart the project and access the previous route. If there is corresponding log output, it means that the plug-in is effective.