企业级微服务API网关Fizz-如何自定义插件

Java100

概念

fizz 插件可理解为响应式的 http servlet filter,即能拦截请求作处理,也能对响应作调整。

插件可以对路由进行操作,即所有与路由匹配的请求;或网关分组,即一组路由。

[En]

The plug-in can act on the route, that is, all requests matching the route; Or gateway grouping, that is, a group of routes.

插件开发分为两部分:网关和管理后台。网关部分定义插件和执行逻辑,管理后台定义插件的配置。

[En]

Plug in development is divided into two parts: gateway and management background. The gateway part defines plug-ins and execution logic, and the management background defines the configuration of plug-ins.

下面以简单的登录校验为例,即客户端通过请求头 token 传递登录态,插件校验登录态,介绍插件的开发。

网关开发

实现 FizzPluginFilter.java 即定义了一个插件,本例插件实现:

```
@Component(LoginValidationPlugin.ID) // 必配,用于与管理后台的配置关联等
public class LoginValidationPlugin implements FizzPluginFilter {

public static final String ID = "LoginValidationPlugin";
输入验证码查看隐藏内容

扫描二维码关注本站微信公众号 Johngo学长
或者在微信里搜索 Johngo学长
回复 svip 获取验证码
wechat Johngo学长