123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- <!DOCTYPE html>
- <html xmlns="http://www.w3.org/1999/xhtml"
- xmlns:th="http://www.thymeleaf.org" lang="zh-CN">
- <div class="container-fluid">
- <div class="row">
- <div class="col-md-12">
- <!-- 插件文档 -->
- <div class="col-md-5">
- <blockquote>
- <p>插件有什么用?</p>
- <small class="text-muted">插件是一种可扩展全量同步和增量同步实现数据转换的技术方式。通过插件可以接收同步数据,自定义同步到目标源的行数据,也能消费数据并实现更多业务场景。</small>
- </blockquote>
- <p>如何开发插件?</p>
- <ol>
- <li>新建java或maven工程,比如app</li>
- <li>导入开发包:
- <ul>
- <li>方式1:导入jar <a onClick="downLoad()" href="javascript:;" title="下载开发包">dbsyncer-common-[[${version}]].jar</a></li>
- <li>方式2:引入pom(需要安装到本地)
- <pre><dependency><br/> <groupId>org.ghi</groupId><br/> <artifactId>dbsyncer-common</artifactId><br/> <version>[[${version}]]</version><br/></dependency></pre>
- </li>
- </ul>
- </li>
- <li>
- <simple>新建一个类,比如MyPlugin,实现接口ConvertService方法</simple>
- <pre>package org.test;
- import org.dbsyncer.common.spi.ConvertService;
- import java.util.List;
- import java.util.Map;
- public class MyPlugin implements ConvertService{
- /**
- * 全量同步
- *
- * @param source 数据源
- * @param target 目标源
- */
- @Override
- public void convert(List<Map> source, List<Map> target) {
- // TODO 消费或处理数据
- }
- /**
- * 增量同步
- *
- * @param event 事件(INSERT/UPDATE/DELETE)
- * @param source 数据源
- * @param target 目标源
- */
- @Override
- public void convert(String event, Map source, Map target) {
- // TODO 消费或处理数据
- }
- /**
- * 重写方法:设置版本号
- *
- * @return
- */
- @Override
- public String getVersion() {
- return "1.0.0";
- }
- /**
- * 重写方法:设置插件名称
- *
- * @return
- */
- @Override
- public String getName() {
- return "MyPlugin";
- }
- }</pre>
- </li>
- <li>
- <simple>/META-INF/新建services文件夹,并在services下新建一个文件,命名为org.dbsyncer.common.spi.ConvertService,文件写入实现类路径org.test.MyPlugin,如果有多个实现就换行再写入</simple>
- <p><img draggable="false" th:src="@{'/img/plugin/spi.png'}"></p>
- </li>
- <li>
- <simple>打包jar</simple>
- <p><img draggable="false" th:src="@{'/img/plugin/jar.png'}"></p>
- </li>
- </ol>
- </div>
- <!-- 插件列表 -->
- <div class="col-md-7">
- <form id="uploadForm" class="form-horizontal" role="form">
- <div class="page-header">
- <h3>上传插件 <small>只支持 "jar" 的文件扩展名.</small></h3>
- </div>
- <div class="form-group">
- <div class="file-loading">
- <input id="filePlugin" type="file" name="files" multiple="multiple" />
- </div>
- </div>
- <div class="form-group">
- <table class="table table-hover">
- <caption>插件列表([[${plugins?.size()} ?: 0]])</caption>
- <thead>
- <tr>
- <th>名称</th>
- <th>运行驱动</th>
- <th>类名</th>
- <th>版本</th>
- <th>文件</th>
- </tr>
- </thead>
- <tbody id="pluginList">
- <tr th:id="${p?.name}" th:each="p,state : ${plugins}">
- <td th:title="内置插件" th:if="${p?.unmodifiable}"><i class="fa fa-plug fa_gray" aria-hidden="true"></i> [[${p?.name}]]</td>
- <td th:title="普通插件" th:if="${not p?.unmodifiable}"><i class="fa fa-star fa_blueviolet" aria-hidden="true"></i> [[${p?.name}]]</td>
- <td th:text="${p?.mappingName}"/>
- <td th:text="${p?.className}"/>
- <td th:text="${p?.version}"/>
- <td th:text="${p?.fileName}"/>
- </tr>
- </tbody>
- </table>
- </div>
- </form>
- </div>
- </div>
- </div>
- </div>
- <script type="text/javascript">
- $("#filePlugin").fileinput({
- theme: 'fas',
- language: 'zh',
- uploadUrl: $basePath + '/plugin/plugin',
- enctype: 'multipart/form-data',
- removeFromPreviewOnError: true, //当选择的文件不符合规则时,例如不是指定后缀文件、大小超出配置等,选择的文件不会出现在预览框中,只会显示错误信息
- allowedFileExtensions: ['jar'],
- minFileCount: 0, //每次多次上载允许的最小文件数。如果设置为0,则表示文件数是可选的
- maxFileCount: 5, //表示允许同时上传的最大文件个数 如果设置为0,则表示允许的文件数不受限制
- showPreview: true,
- showUpload: true,//不展示上传按钮
- validateInitialCount: true,//是否在验证minFileCount和包含初始预览文件计数(服务器上载文件)maxFileCount
- }).on("fileuploaded", function(event, data, previewId, index) {
- if (!data.response.success) {
- bootGrowl(data.response.resultValue, "danger");
- }
- doLoader("/plugin");
- });
- function downLoad(){
- window.open($basePath + "/plugin/download");
- }
- </script>
- </html>
|