PutSQL失败时发送电子邮件

时间:2019-05-30 12:49:30

标签: apache-nifi

我想在PutSQL失败时发送电子邮件,PutSQL的{​​{1}},因为在Rollback on Failure=true失败时源代码不支持发送电子邮件,因此我添加了{ {1}}关系。我添加了三行代码,以在PutSQL失败时发送电子邮件,但是它们都不起作用。

enter image description here enter image description here enter image description here

1 个答案:

答案 0 :(得分:0)

您可以将流文件路由到多个关系(有关详细信息,请参见Apache NiFi Developer Guide -- Route Based on Content (One to Many))。我不确定您是说要 true 失败还是想要回滚,还是不确定是否可以将其更改为 false

如果您需要失败时回滚为真 AND 来接收电子邮件警报,则有两种选择:

  • 修改PutSQL源代码以克隆流文件,并将其发送到如上所述的alert关系。您将需要使用类似于RouteOnContent的代码(请参见下文)。
  • $NIFI_HOME/conf/logback.xml中注册一个email log appender,该{{3}}从WARN获得ERRORorg.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});