基于stream开发java插件

本文仅对公司内部的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发生变更后需要更新依赖包+插件+流程图中插件的版本

自己记录备用

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值