Java Code Examples for org.apache.beam.runners.dataflow.options.DataflowPipelineOptions#setNumWorkers()

The following examples show how to use org.apache.beam.runners.dataflow.options.DataflowPipelineOptions#setNumWorkers() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StreamingDataflowWorkerTest.java    From beam with Apache License 2.0 5 votes vote down vote up
private List<ParallelInstruction> makeUnboundedSourcePipeline(
    int numMessagesPerShard, // Total number of messages in each split of the unbounded source.
    DoFn<ValueWithRecordId<KV<Integer, Integer>>, String> doFn)
    throws Exception {
  DataflowPipelineOptions options =
      PipelineOptionsFactory.create().as(DataflowPipelineOptions.class);
  options.setNumWorkers(1);
  CloudObject codec =
      CloudObjects.asCloudObject(
          WindowedValue.getFullCoder(
              ValueWithRecordId.ValueWithRecordIdCoder.of(
                  KvCoder.of(VarIntCoder.of(), VarIntCoder.of())),
              GlobalWindow.Coder.INSTANCE),
          /*sdkComponents=*/ null);

  return Arrays.asList(
      new ParallelInstruction()
          .setSystemName("Read")
          .setOriginalName("OriginalReadName")
          .setRead(
              new ReadInstruction()
                  .setSource(
                      CustomSources.serializeToCloudSource(
                              new TestCountingSource(numMessagesPerShard), options)
                          .setCodec(codec)))
          .setOutputs(
              Arrays.asList(
                  new InstructionOutput()
                      .setName("read_output")
                      .setOriginalName(DEFAULT_OUTPUT_ORIGINAL_NAME)
                      .setSystemName(DEFAULT_OUTPUT_SYSTEM_NAME)
                      .setCodec(codec))),
      makeDoFnInstruction(doFn, 0, StringUtf8Coder.of(), WindowingStrategy.globalDefault()),
      makeSinkInstruction(StringUtf8Coder.of(), 1, GlobalWindow.Coder.INSTANCE));
}
 
Example 2
Source File: PubsubWordCount.java    From cloud-bigtable-examples with Apache License 2.0 5 votes vote down vote up
private static void injectMessages(BigtablePubsubOptions options) {
  String inputFile = options.getInputFile();
  String topic = options.getPubsubTopic();
  DataflowPipelineOptions copiedOptions = options.as(DataflowPipelineOptions.class);
  copiedOptions.setStreaming(false);
  copiedOptions.setNumWorkers(INJECTORNUMWORKERS);
  copiedOptions.setJobName(copiedOptions.getJobName() + "-injector");
  Pipeline injectorPipeline = Pipeline.create(copiedOptions);
  injectorPipeline.apply(TextIO.read().from(inputFile))
      .apply(ParDo.of(new FilterEmptyStringsFn()))
      .apply(PubsubIO.writeStrings().to(topic));
  injectorPipeline.run().waitUntilFinish();
}