Guest User

Untitled

a guest
Sep 16th, 2019
106
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class StreamingJob {
  2.  
  3. public static void main(String[] args) throws Exception {
  4. // Set up the streaming execution environment
  5. final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
  6. env.enableCheckpointing(4000);
  7.  
  8. // Set up a Cloud Pub/Sub topic as input
  9.  
  10. // deserializer controls how Apache Flink deserializes the message
  11. // returns from Cloud Pub/Sub (a byte string) to a PubSubEvent
  12. // (custom Java class). See Deserialization.java and
  13. // PubSubEvent.java for definition.
  14. PlayCountEventDeserializationSchema deserializer = new PlayCountEventDeserializationSchema();
  15.  
  16. Map<String, String> envVars = System.getenv();
  17. String projectId = envVars.get("GCP_PROJECT");
  18. String subscription = envVars.get("PUBSUB_SUBSCRIPTION");
  19.  
  20. SourceFunction<PubSubEvent> pubSubSource = PubSubSource.newBuilder()
  21. .withDeserializationSchema(deserializer)
  22. .withProjectName(projectId)
  23. .withSubscriptionName(subscription)
  24. .build();
  25.  
  26. DataStream<PubSubEvent> dataStream = env.addSource(pubSubSource);
  27.  
  28. ...
  29. }
  30. }
RAW Paste Data