首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Apache NiFi文本替换

问Apache NiFi文本替换
EN

Stack Overflow用户
提问于 2018-02-09 05:21:01
回答 2查看 319关注 0票数 1

用属性值替换including the brackets中的字符串的最佳方法是什么?

{ "VoiceMessageTemplateEnglish“:”你好,我是LocationName打电话来确认AppointmentDate上有名字的约会。请按1确认,按2取消“,}

我尝试在JS中使用ExecuteScript处理器,但是没有任何运气。

谢谢!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-02-10 20:36:12

最后我使用JS解决了这个问题:

谢谢达吉特为我指明了正确的方向

var flowFile = session.get();if (flowFile != null) {

代码语言:javascript
复制
var lclAppointmentDate = flowFile.getAttribute("AppointmentDate");
var lclAppointmentStartTime = flowFile.getAttribute("AppointmentStartTime");
var lclName = flowFile.getAttribute("Name");
var lclVoiceMailTemplate = flowFile.getAttribute("VoiceMailTemplate");



if (lclVoiceMailTemplate != null){
    lclVoiceMailTemplate  = lclVoiceMailTemplate
                       .replace('[Name]', lclName)
                       .replace('[AppointmentDate]', lclAppointmentDate)
                       .replace('[AppointmentTime]', lclAppointmentStartTime);
    flowFile = session.putAttribute(flowFile, "FinalVoiceMailTemplate", lclVoiceMailTemplate);
}
session.transfer(flowFile, REL_SUCCESS);
session.commit();

}

票数 0
EN

Stack Overflow用户

发布于 2018-02-09 09:12:15

nifi 1.5.0中的处理器ExecuteGroovyScript

代码语言:javascript
复制
def ff = session.get()
if(!ff)return

def attr = ff.getAttributes()
def text = ff.read().getText("UTF-8")
text = text.replaceAll( /\[(\w+)\]/ ) {  attr[it[1]] ?: "noValue" }

ff.write("UTF-8", text)

REL_SUCCESS << ff
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48699181

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档