# Overview
Dynamic plug-in calling is a unique capability provided by FizzGate, which mainly solves the following two problems:
- Dynamic hot-swappable plug-ins: Allow developers to develop and select plug-ins provided by the market to achieve dynamic hot-swappable plug-ins without affecting node functions.
- ClassLoaders are isolated from each other: ClassLoaders are used to isolate plug-ins and nodes and between plug-ins to ensure compatibility even if different versions of the API are used.
The FizzGate team has conducted in-depth cooperation with the Alibaba Sofa team and made full use of Sofa's isolation technology. This cooperation not only meets Sofa's needs in terms of application scenarios and community feedback capabilities, but also gives full play to Sofa's Serverless capabilities, thereby significantly improving FizzGate's overall capabilities.
There are two main sources of dynamic plug-ins:
- Use templates for secondary development by yourself.
- Download the plug-in from the official market.
# Component development
Download sample code, https://gitee.com/fizzgate/fizz-dynamic-plugin
Here is the main code for a plugin example:
package com.fizzgate.plugin.extension;
import com.alipay.sofa.runtime.api.annotation.SofaService;
import com.alipay.sofa.runtime.api.annotation.SofaServiceBinding;
import com.fizzgate.plugin.FizzPluginFilter;
import com.fizzgate.plugin.FizzPluginFilterChain;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;
import java.util.Map;
@SofaService(uniqueId = LogPlugin.PLUGIN_ID, bindings = {@SofaServiceBinding(serialize = false)})
@Component
public class LogPlugin implements FizzPluginFilter {
public static final String PLUGIN_ID = "logPlugin"; // Plug-in id
public void init(String pluginConfig) {
FizzPluginFilter.super.init(pluginConfig);
}
public Mono<Void> filter(ServerWebExchange exchange, Map<String, Object> config) {
System.err.println("this is my plugin"); // This plugin only outputs this
return FizzPluginFilterChain.next(exchange); //Execute subsequent logic
}
}
In the above code, the @SofaService annotation declares that the component is a dynamic component and needs to expose service capabilities for node calls.
It should be noted that the uniqueId must be consistent with the plug-in background configuration. For other development details, please refer to the static plug-in development method.
# Backend configuration
In the background configuration, the following steps need to be performed:
Click the Extension Center and then click Add;
Edit plug-in related information and ensure that the plug-in name is consistent with uniqueId;
Upload dynamic plug-in files;
Click Save.
These steps ensure that the plug-in is successfully configured and available for use on the system.