[ 展开 ]
[ 展开 ]
[ 展开 ]
[ 展开 ]
在nifi-XXX-nar下的pom文件里添加以下依赖
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-framework-nar</artifactId>
<type>nar</type>
</dependency>
在nifi-XXX-processor的pom文件里添加以下依赖
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-framework-core</artifactId>
<version>1.2.0</version>
<scope>provided</scope>
</dependency>
在程序代码里如下获取
import org.apache.nifi.util.LogAppendInfoUtil;
String userId = LogAppendInfoUtil.userId();
String projectId = LogAppendInfoUtil.projectId();
PS:LogAppendInfoUtil类在nifi-framework-core-1.2.0.jar里,使用前需要删除本地仓库中已有的jar,从平台maven仓库中重新导入
2、在能力内部获取注册到平台的能力ID
@Override
protected void init(final ProcessorInitializationContext context) {
String procesorId = "0";
if (context.getExtendProperties() != null
&& !StringUtils.isBlank(context.getExtendProperties().get("hidden_processor_id"))) {
procesorId = context.getExtendProperties().get("hidden_processor_id");
}
}
3、在onStop方法里获取能力是手工停止还是nifi重启导致的停止
public void stop(final ProcessContext context) throws IOException {
if(!context.isAutoStopping()){
//do something
}
}
4、将能力上次运行状态信息保存起来,重新打开画布后能获取到
在能够获取ProcessContext context对象的方法里
使用context.putExtendProperty(processorId + extendPropertySuffix, lastJobInf("新创建", ""));保存信息
使用context.getExtendProperty(processorId + extendPropertySuffix);//获取信息
实际信息保存到画布的xml里,信息不要太大,为了保证key不冲突,建议key里包含processorId
[ 展开 ]
[ 展开 ]
[ 展开 ]
GMT+8, 2024-5-20 10:29 , Processed in 0.030327 second(s), 9 queries .