本文仅对公司内部的stream流系统
前一段时间有需求,需要将一些应用迁移到公司的stream流平台上,迁移过程中需要开发部分平台未有的插件,本文主要帮博主记录以下两个点:
- 开发过程中的注意事项
- 平台配置注意事项
开发流程
pom中引用
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>stream</id>
<name>libs-releases</name>
<url>
http://ip/nexus/content/repositories/releases/repository/
</url>
<layout>default</layout>
</repository>
</repositories>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<!--构建java包时候打包所有的依赖库-->
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<artifactId> maven-assembly-plugin </artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.X.java_plugin.JavaPlugin</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.sm_stream</groupId>
<artifactId>sm_stream_processor</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.9.5</version>
</dependency>
</dependencies>
其中注意的点
- 是公司内部系统暂只支持jdk1.6(后续会支持到1.8)
- pom中的com.X.java_plugin.JavaPlugin是固定的不可以修改
- log4j是可以通过在插件内写日志,然后在平台页面可以查询的,以下是log配置
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<!-- Author: Crunchify.com -->
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{YYYY-MM-dd HH:mm:ss} [%t] %-5p %c{1}:%L - %msg%n" />
</Console>
<RollingFile name="RollingFile" filename="log/CrunchifyTest.log"
filepattern="${logPath}/%d{YYYYMMddHHmmss}-fargo.log">
<PatternLayout pattern="%d{YYYY-MM-dd HH:mm:ss} [%t] %-5p %c{1}:%L - %msg%n" />
<Policies>
<SizeBasedTriggeringPolicy size="100 MB" />
</Policies>
<DefaultRolloverStrategy max="20" />
</RollingFile>
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="Console" />
<AppenderRef ref="RollingFile" />
</Root>
</Loggers>
</Configuration>
插件需要实现插件的基类-ProcessorBase 自己实现基类下的init、doProcess、callFlush、doFlush、stop等方法;
- init方法是初始化插件,在任务开始时此方法被调用,可以初始化资源;
- callFlush是流程图的头结点调用的,头结点调用callFlush之后,后续的结点的doFlush方法会被调用;
- 头结点的doProcess会被一直调用,而非头结点的doProcess方法只有在前面队列中有数据时才会被调用;
- stop方法是在任务停止时被调用,一些调用的资源可以在此方法中释放;
- ProcessResult作为doProcess的返回结果,可以在doProcess方法中调用ProcessResult的addResult方法;
平台配置注意事项
- 依赖包通过SO发布的方式,然后将jar包在pangu的地址填写到路径中,填写注意事项后就可以保存,依赖包发布成功;
- 发布插件时注意类名=插件名的选项,如果类不是在跟目录下,此选项不能勾选,并且类名需要些全限制类名,然后将输入参数和输出key填写好即可完成插件的发布;
- 当依赖jar发生变更后需要更新依赖包+插件+流程图中插件的版本
自己记录备用