I am trying to use Apache Beam to create a Dataflow pipeline and I am not able to follow the documentation and cannot find any examples.
The pipeline is simple.
- Create a pipeline
- Read from a pub/sub topic
- Write to spanner.
Currently, I am stuck at step 2. I cannot find any example of how to read from pub/sub and and consume it.
This is the code I have so far and would like to
class ExtractFlowInfoFn extends DoFn<PubsubMessage, KV<String, String>> {
public void processElement(ProcessContext c) {
KV.of("key", "value");
}
}
public static void main(String[] args) {
Pipeline p = Pipeline.create(
PipelineOptionsFactory.fromArgs(args).withValidation().create());
p.apply("ReadFromPubSub", PubsubIO.readMessages().fromSubscription("test"))
.apply("ConvertToKeyValuePair", ParDo.of(new ExtractFlowInfoFn()))
.apply("WriteToLog", ));
};
I was able to come up with the code by following multiple examples. To be honest, I have no idea what I am doing here.
Please, either help me understand this or link me to the correct documentation.