【问题标题】:How to filter a stream of tuple with Apache Edgent如何使用 Apache Edgent 过滤元组流
【发布时间】:2016-12-20 10:56:58
【问题描述】:

我根据这个manual创建了一个源函数。

public static void main(String[] args) throws Exception {
    DirectProvider dp = new DirectProvider();
    Topology top = dp.newTopology();

    final URL url = new URL("http://finance.yahoo.com/d/quotes.csv?s=BAC+COG+FCX&f=snabl");

    TStream<String> linesOfWebsite = top.source(queryWebsite(url));
}

现在我想过滤这个流。我有这样的想法:

TStream<Iterable<String>> simpleFiltered = source.filter(item-> item.contains("BAX");

这不起作用。有人知道如何过滤流吗?我不想更改请求 url 来预先进行过滤。

【问题讨论】:

    标签: java apache-edgent


    【解决方案1】:

    从提供的信息很难判断。运行拓扑需要dp.submit(top)。筛选器代码未指定使用正在指定的 URL 发生的项目。例如,

    ...
    TStream<String> linesOfWebsite = top.source(queryWebsite(url));
    linesOfWebsite.print(); // show what's received
    
    TStream<String> filtered = linesOfWebsite.filter(t -> t.contains("BAC"));
    filtered.sink(t -> System.out.println("filtered: " + t));
    
    dp.submit(top);  // required
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多