-
Notifications
You must be signed in to change notification settings - Fork 413
2.9_插件开发指引
开始该章节前,请先了解一下Datalink的插件机制:1.5深入插件,插件开发基本流程如下:
- 如果是reader插件,项目名称以"dl-worker-reader-"开头
-
如果是writer插件,项目名称以"dl-worker-writer-"开头
-
保证新添加的项目在dl-worker的pom文件中已经配上,如下所示:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent>
<groupId>com.ucar.datalink</groupId> <artifactId>datalink</artifactId> <version>0.0.1</version> <relativePath>../pom.xml</relativePath>
</parent>
<artifactId>dl-worker</artifactId> <packaging>pom</packaging> <name>worker module for datalink</name>
<modules>
<!--保证自己的模块在此处有对应配置--> <module>dl-worker-core</module> <module>dl-worker-reader-mysql</module> <module>dl-worker-writer-dummy</module> <module>dl-worker-writer-rdbms</module> <module>dl-worker-reader-dummy</module> <module>dl-worker-api</module>
</modules>
</project>
-
在pom文件中增加对dl-worker-api模块的依赖(注:除了这个模块,不要再添加对其它datalink模块的依赖,否则将对打包产生影响,此模块已经间接把其它datalink模块引进来了)
<dependency>
<groupId>com.ucar.datalink</groupId> <artifactId>dl-worker-api</artifactId> <version>0.0.1</version><!--版本视具体情况而定-->
</dependency>
-
在pom文件中增加build配置,如下所示
<build>
<plugins> <plugin> <artifactId>maven-assembly-plugin</artifactId> <configuration> <descriptors> <descriptor>src/main/assembly/package.xml</descriptor> </descriptors> <finalName>reader-mysql</finalName><!--将finalName替换为自己的插件名称即可--> <appendAssemblyId>false</appendAssemblyId> <outputDirectory>${project.parent.parent.build.directory}/dl-worker/plugin/reader </outputDirectory><!--根据插件类型设置,reader或者writer--> </configuration> <executions> <execution> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin> </plugins>
</build>
-
在src/main/assembly路径下添加package.xml文件,如下所示
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>reader-mysql</id><!--替换为自己的插件名称即可--> <formats> <format>dir</format> </formats> <includeBaseDirectory>false</includeBaseDirectory> <dependencySets> <dependencySet> <useProjectArtifact>true</useProjectArtifact> <outputDirectory>/lib</outputDirectory> <scope>runtime</scope> <useTransitiveFiltering>true</useTransitiveFiltering> <excludes> <exclude>com.ucar.datalink:dl-worker-api</exclude> </excludes> </dependencySet> </dependencySets>
</assembly>
- 在dl-domain模块中进行参数定义
Reader插件,放到com.ucar.datalink.domain.plugin.reader包下面
Writer插件,放到com.ucar.datalink.domain.plugin.writer包下面
-
参数类需要继承自相关父类
Reader参数类需要继承自com.ucar.datalink.domain.plugin.PluginReaderParameter
Writer参数类需要继承自com.ucar.datalink.domain.plugin.PluginWriterParameter
Reader和Writer参数都需要实现方法:initPluginName()、initPluginClass()和initSupportedSourceTypes()
注:对于插件名称,如果是reader,插件名称必须以"reader-"开头,如果是writer,插件名称必须以"writer-"开头
如下所示:public class RdbmsWriterParameter extends PluginWriterParameter {
@Override public String initPluginName() { //返回插件名称,前面pom中的finalName和package中的id必须和此处的pluginName保持一致,如: //return "writer-rdbms"; } @Override public String initPluginClass() { //返回该插件对应的TaskReader或TaskWriter的类名称(全限定名),如: //return "com.ucar.datalink.writer.rdbms.RdbmsTaskWriter"; } @Override public Set<MediaSourceType> initSupportedSourceTypes() { //返回该插件支持的数据源源类型,如: //return Sets.newHashSet(MediaSourceType.MYSQL, MediaSourceType.SQLSERVER); }
}
- 如果是Reader插件,还需要定义自己的Position类,用于保存数据同步位点信息,自定义的Position类需要继承自com.ucar.datalink.domain.Position
- go!go!go!