数据流以编程方式耗尽管道

时间:2018-08-25 20:10:34

标签: google-cloud-dataflow dataflow

我试图以编程方式耗尽管道。代码的第一部分运行管道,该管道使用单独的线程进行调用。然后,该程序休眠一段时间,然后尝试耗尽管道。 我试图在Dataflow中运行,但没有成功。管道开始了,但是随后的排空代码的其余部分看起来好像从未执行过。 请让我知道是否可能。

我试图查看日志记录以查看执行了多少程序,但是看起来Dataflow仅记录了工作日志,因此直到执行完为止都看不到。我相信管道运行后的代码不会执行。

DataflowRunner runner = DataflowRunner.fromOptions(options);
           DataflowPipelineJob pp = null; 
        // to run the pipeline which calls pipeline.run  
    new Thread(() -> runMethod(pp, runner, options)).start();   

        //Draining below
        try {
            Thread.sleep(360000);           
            GoogleCredential credential;
            credential = GoogleCredential.getApplicationDefault();
               if (credential.createScopedRequired()) {
                   credential = credential.createScoped(Collections.singletonList("https://www.googleapis.com/auth/cloud-platform"));
               }
               HttpTransport httpTransport;        
               httpTransport = GoogleNetHttpTransport.newTrustedTransport();
               JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
                  Dataflow client = new Dataflow.Builder(httpTransport, jsonFactory, credential)
                          .setApplicationName("Google Cloud Platform Sample 1")
                          .build(); 
               Job content = new Job();
               content.setProjectId("sample-id");
               content.setId(pp.getJobId());
               content.setRequestedState("JOB_STATE_DRAINING");
               client.projects().jobs()
                       .update("sample-id", pp.getJobId(), content)
                       .execute();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }  catch (GeneralSecurityException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
           }

1 个答案:

答案 0 :(得分:0)

只要有in flight data,管道就会排空。它将停止提取数据,并且在处理完所有数据后,作业将停止。

1-您从哪里获得数据 2-所有数据都可以在睡眠时间进行处理