apache-nifi - PutSQL 失败时发送电子邮件
问题描述
我想在PutSQL
失败时发送电子邮件,PutSQL
's Rollback on Failure=true
,因为源代码不支持PutSQL
失败时发送电子邮件,所以我添加了REL_ALERT
关系。我添加了三行代码以在PutSQL
失败时发送电子邮件,但它们都不起作用。
解决方案
您可以将流文件路由到多个关系(有关详细信息,请参阅Apache NiFi 开发人员指南——基于内容的路由(一对多))。我不确定您是说要在失败时回滚为true,还是您没有意识到可以将其更改为false。
如果您需要回滚失败并接收电子邮件警报,您有几个选择:
- 修改
PutSQL
源代码以克隆流文件并将其发送到上述alert
关系。您需要使用类似于RouteOnContent
(见下文)的代码。 - 注册一个电子邮件日志追加器,在
$NIFI_HOME/conf/logback.xml
其中获取WARN
或ERROR
级别日志事件org.apache.nifi.processors.standard.PutSQL
将流文件路由到多个关系的示例代码
final Relationship firstRelationship = destinations.iterator().next();
destinations.remove(firstRelationship);
for (final Relationship relationship : destinations) {
FlowFile clone = session.clone(flowFile);
clone = session.putAttribute(clone, ROUTE_ATTRIBUTE_KEY, relationship.getName());
session.getProvenanceReporter().route(clone, relationship);
session.transfer(clone, relationship);
logger.info("Cloning {} to {} and routing clone to {}", new Object[]{flowFile, clone, relationship});
}
flowFile = session.putAttribute(flowFile, ROUTE_ATTRIBUTE_KEY, firstRelationship.getName());
session.getProvenanceReporter().route(flowFile, firstRelationship);
session.transfer(flowFile, firstRelationship);
logger.info("Routing {} to {}", new Object[]{flowFile, firstRelationship});
推荐阅读
- kotlin - 如何缓存 gradle 插件依赖项?
- javascript - 如何正则表达式匹配并返回具有已知起始格式并以双换行符结尾的字符串?
- javascript - 如何将此滚动动画隔离为容器代替?
- c - 在 C 中重新安装设置信号
- r - 如何编写一个R循环来添加多个excel文件,更改它们的列名,然后基于一行组合它们?
- javascript - 如何在不清除字段值的情况下更改表单字段的属性?
- python - ConnectionResetError: [WinError 10054] 现有连接被远程主机错误强行关闭
- c# - IF 奇数/偶数条件检查的行为相反
- python - NameError:名称'self'未定义:Python
- python - 远程计算机上的 Visual Studio 调试