MCPcopy Create free account
hub / github.com/airscholar/FlinkCommerce / main

Method main

src/main/java/FlinkCommerce/DataStreamJob.java:51–282  ·  view source on GitHub ↗
(String[] args)

Source from the content-addressed store, hash-verified

49 private static final String password = "postgres";
50
51 public static void main(String[] args) throws Exception {
52 // Sets up the execution environment, which is the main entry point
53 // to building Flink applications.
54 final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
55
56 String topic = "financial_transactions";
57
58 KafkaSource<Transaction> source = KafkaSource.<Transaction>builder()
59 .setBootstrapServers("localhost:9092")
60 .setTopics(topic)
61 .setGroupId("flink-group")
62 .setStartingOffsets(OffsetsInitializer.earliest())
63 .setValueOnlyDeserializer(new JSONValueDeserializationSchema())
64 .build();
65
66 DataStream<Transaction> transactionStream = env.fromSource(source, WatermarkStrategy.noWatermarks(), "Kafka source");
67
68 transactionStream.print();
69
70 JdbcExecutionOptions execOptions = new JdbcExecutionOptions.Builder()
71 .withBatchSize(1000)
72 .withBatchIntervalMs(200)
73 .withMaxRetries(5)
74 .build();
75
76 JdbcConnectionOptions connOptions = new JdbcConnectionOptions.JdbcConnectionOptionsBuilder()
77 .withUrl(jdbcUrl)
78 .withDriverName("org.postgresql.Driver")
79 .withUsername(username)
80 .withPassword(password)
81 .build();
82
83
84 //create transactions table
85 transactionStream.addSink(JdbcSink.sink(
86 "CREATE TABLE IF NOT EXISTS transactions (" +
87 "transaction_id VARCHAR(255) PRIMARY KEY, " +
88 "product_id VARCHAR(255), " +
89 "product_name VARCHAR(255), " +
90 "product_category VARCHAR(255), " +
91 "product_price DOUBLE PRECISION, " +
92 "product_quantity INTEGER, " +
93 "product_brand VARCHAR(255), " +
94 "total_amount DOUBLE PRECISION, " +
95 "currency VARCHAR(255), " +
96 "customer_id VARCHAR(255), " +
97 "transaction_date TIMESTAMP, " +
98 "payment_method VARCHAR(255) " +
99 ")",
100 (JdbcStatementBuilder<Transaction>) (preparedStatement, transaction) -> {
101
102 },
103 execOptions,
104 connOptions
105 )).name("Create Transactions Table Sink");
106
107 //create sales_per_category table sink
108 transactionStream.addSink(JdbcSink.sink(

Callers

nothing calls this directly

Calls 1

Tested by

no test coverage detected