【发布时间】:2018-05-29 12:49:28
【问题描述】:
我正在尝试使用 kafka 流中的编码部分,如下所示
KStreamBuilder builder = new KStreamBuilder();
KStream<String, String> textlines = builder.stream("iostatin2");
KStream<String, String> mstream = textlines
.mapValues(value -> value.replace("[","" ) )
.mapValues(value -> value.replace("]","" ) )
.mapValues(value -> value.replaceAll("\":\"", "\":"))
.mapValues(value -> value.replaceAll("\":", "\":\""))
.mapValues(value -> value.replaceAll("\",\"", ",\""))
.mapValues(value -> value.replaceAll(",\"", "\",\""))
.mapValues(value -> value.replaceAll(":\"\\{", ":\\{"))
.mapValues(value -> value.replaceAll("\\}\",", "\\},"))
.mapValues(value -> value.replaceAll("\\},\\{" ,"\\}\\},\\{\\{"));
textlines.foreach(new ForeachAction<String, String>() {
@Override
public void apply(String key, String value) {
try {
textlines.flatMapValues(value -> Arrays.asList(value.split("\\},\\{")));
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
});
所以在foreachaction()函数中
textlines.flatMapValues(value -> Arrays.asList(value.split("\\},\\{")));
在此行中的值导致错误,例如变量“值”已在范围中定义。那么我应该用什么替换那行...请帮助我..
【问题讨论】:
-
只是重命名变量?
标签: apache-kafka apache-kafka-streams