pubsub输出以触发批处理管道

时间:2018-12-09 12:17:55

标签: google-cloud-dataflow

我已经制作了Java管道,其中一个管道用于从主题订户读取消息,并且如果发现特殊的字符(例如“开始”字符串),则在读取csv文件,在数据存储区中查找,加密数据并在同一程序中执行另一个程序写入csv输出。

在此过程中,无论如何,我都无法将pubsub管道输出传递给批处理管道的起点。

======================= 该程序将终止并且无法运行。没错...

如果我删除了检查pubsub管道输出的if条件,即低于一个,则数据流显示2条管道,一个用于pubsub,另一个用于文件处理。即使没有向pub子主题提供任何消息,文件处理管道也可以运行,并且当另外一个..总之无法仅在完成pubsub管道后才能触发批处理管道时,什么也不会发生。请帮忙。

代码段如下:

PCollection<String> pubsubPipeline = 
p.apply(PubsubIO.readStrings().fromTopic(myTpoic))
            .apply("window",
                    Window.into(SlidingWindows//
                            .of(Duration.standardSeconds(30))//
                            .every(Duration.standardSeconds(30)))) //
            .apply("WordsPerLine", ParDo.of(new DoFn<String, String>() {
                @ProcessElement
                public void processElement(ProcessContext c) throws 
Exception {
                    String s = c.element();
                    final String start = "Start";
                    if (start.equals(s)) {
                        c.output(s.toString());
                    } else {
                        LOG.info("Start not found");
                        return;
 //                     throw new Exception();
                    }
                }
            }));
    String start = "Start";
//      String stsubs = pubsubPipeline.toString();
    if (start.equals(pubSubPipeline))
            {
            LOG.info("Come in if condition");   

    LOG.info("Reading input file");
    PCollection<String> lines = p.apply("Read 
  File",TextIO.read().from(input));
    LOG.info("Lookup in the datastore");
    PCollection<HashMap<String, List<Entity>>> entitySet = 
  lines.apply("Query", ParDo.of(new DoFn<String, HashMap<String, 
  List<Entity>>>() {
        @ProcessElement
  ::
  :
  :
    PCollection<String> output = userSet.apply("Print Entity", 
  ParDo.of(new DoFn<User, String>() {
        @ProcessElement
        public void processElement(ProcessContext c) throws Exception {
            User user = c.element();
            if (user != null && user.getEmail() != null && 
  user.getEmail().equals(user.getEncryptedEmail())) {
                user.setEncryptedEmail(null);
            }
            c.output(user.toString());
        }
    }));


    output.apply(TextIO.write().withHeader("User Id,Email,Encrypted Email").to(outputPrefix).withSuffix(".csv").withoutSharding());
    p.run().waitUntilFinish();

            }   

    else
        LOG.info("comes in else condition");
    return;
  }

0 个答案:

没有答案