【问题标题】:value is already defined in scope in kafka streams值已在 kafka 流的范围内定义
【发布时间】: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


【解决方案1】:

value 已经在上面的 apply() 方法中用作参数, 所以改变行中的值 textlines.flatMapValues(value -&gt; Arrays.asList(value.split("\\},\\{")));

到任何其他名称,如 v

textlines.flatMapValues(v -&gt; Arrays.asList(v.split("\\},\\{")));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-10-28
    • 1970-01-01
    • 1970-01-01
    • 2017-02-15
    • 1970-01-01
    • 1970-01-01
    • 2015-01-01
    • 1970-01-01
    相关资源
    最近更新 更多