use of com.google.cloud.teleport.v2.options.JdbcToPubsubOptions in project DataflowTemplates by GoogleCloudPlatform.
the class JdbcToPubsub method main.
/**
* Main entry point for pipeline execution.
*
* @param args Command line arguments to the pipeline.
*/
public static void main(String[] args) {
JdbcToPubsubOptions options = PipelineOptionsFactory.fromArgs(args).withValidation().as(JdbcToPubsubOptions.class);
run(options);
}
use of com.google.cloud.teleport.v2.options.JdbcToPubsubOptions in project DataflowTemplates by GoogleCloudPlatform.
the class JdbcToPubsub method run.
/**
* Runs a pipeline which reads message from JdbcIO and writes to Pub/Sub.
*
* @param options The execution options.
* @return The pipeline result.
*/
public static PipelineResult run(JdbcToPubsubOptions options) {
// Create the pipeline
Pipeline pipeline = Pipeline.create(options);
LOG.info("Starting Jdbc-To-PubSub Pipeline.");
/*
* Steps:
* 1) Read data from a Jdbc Table
* 2) Write to Pub/Sub topic
*/
DynamicJdbcIO.DynamicDataSourceConfiguration dataSourceConfiguration = DynamicJdbcIO.DynamicDataSourceConfiguration.create(options.getDriverClassName(), maybeDecrypt(options.getConnectionUrl(), options.getKMSEncryptionKey())).withDriverJars(options.getDriverJars());
if (options.getUsername() != null) {
dataSourceConfiguration = dataSourceConfiguration.withUsername(maybeDecrypt(options.getUsername(), options.getKMSEncryptionKey()));
}
if (options.getPassword() != null) {
dataSourceConfiguration = dataSourceConfiguration.withPassword(maybeDecrypt(options.getPassword(), options.getKMSEncryptionKey()));
}
if (options.getConnectionProperties() != null) {
dataSourceConfiguration = dataSourceConfiguration.withConnectionProperties(options.getConnectionProperties());
}
PCollection<String> jdbcData = pipeline.apply("readFromJdbc", DynamicJdbcIO.<String>read().withDataSourceConfiguration(dataSourceConfiguration).withQuery(options.getQuery()).withCoder(StringUtf8Coder.of()).withRowMapper(new ResultSetToJSONString()));
jdbcData.apply("writeSuccessMessages", PubsubIO.writeStrings().to(options.getOutputTopic()));
return pipeline.run();
}
Aggregations