Google cloud dataflow 使用SSL-Dataflow的Google Cloud Postgresql的Java连接字符串

Google cloud dataflow 使用SSL-Dataflow的Google Cloud Postgresql的Java连接字符串,google-cloud-dataflow,google-cloud-sql,apache-beam,Google Cloud Dataflow,Google Cloud Sql,Apache Beam,需要使用Dataflow作业(Java代码)将数据写入Google Cloud PostgreSQL。此PostgreSQL实例已启用SSL。因此,我想知道这个启用SSL的PostgreSQL数据库的连接字符串(客户端认证、密钥和服务器认证)。在没有SSL的情况下,下面的连接字符串在数据流作业中可以正常工作。但是想知道SSL的连接字符串 JdbcIO.<KV<Integer,Integer>>write() .withDataSourceConfiguration( Da

需要使用Dataflow作业(Java代码)将数据写入Google Cloud PostgreSQL。此PostgreSQL实例已启用SSL。因此,我想知道这个启用SSL的PostgreSQL数据库的连接字符串(客户端认证、密钥和服务器认证)。在没有SSL的情况下,下面的连接字符串在数据流作业中可以正常工作。但是想知道SSL的连接字符串

JdbcIO.<KV<Integer,Integer>>write()
.withDataSourceConfiguration( DataSourceConfiguration.create("org.postgresql.Driver","jdbc:postgresql://<PrivateIP>:5432/db")
               .withUsername("***")
               .withPassword("password"))
JdbcIO.write()
.withDataSourceConfiguration(DataSourceConfiguration.create(“org.postgresql.Driver”,“jdbc:postgresql://:5432/db”)
.withUsername(“***”)
.withPassword(“密码”))

您可以使用以下命令配置到PostgreSQL的连接:
sslcert
sslkey
sslrootcert
,以指向不同的证书


您还可以使用创建临时证书并自动使用它们。

您可以使用以下命令配置到PostgreSQL的连接:
sslcert
sslkey
sslrootcert
,以指向不同的证书


您还可以使用,它创建临时证书并自动使用它们。

下面的代码适用于我

String conUrl="jdbc:postgresql://google/<dbName>?cloudSqlInstance=<InstanceName>&socketFactory=com.google.cloud.sql.postgres.SocketFactory&user=<UserName>&password=<PWD>";

p.apply(JdbcIO.<KV<Integer,Integer>>write()
    .withDataSourceConfiguration( DataSourceConfiguration.create("org.postgresql.Driver",conUrl)
            .withUsername(<UserName>)
            .withPassword(<PWD>)
            )
    .withStatement("insert into public.testTable(id,order_number) values(?, ?)")
    .withPreparedStatementSetter(new JdbcIO.PreparedStatementSetter<KV<Integer,Integer>>() {
        public void setParameters(KV<Integer,Integer> element, PreparedStatement query)
                throws SQLException {
            query.setInt(1, element.getKey());
            query.setInt(2, element.getValue());
        }
    })
);
String conUrl=“jdbc:postgresql://google/?cloudSqlInstance=&socketFactory=com.google.cloud.sql.postgres.SocketFactory&user=&password=";
p、 apply(JdbcIO.write()
.withDataSourceConfiguration(DataSourceConfiguration.create(“org.postgresql.Driver”,conUrl)
.withUsername()
.withPassword()
)
.with语句(“插入到public.testTable(id,订单号)值(?,)中”)
.withPreparedStatementSetter(新JdbcIO.PreparedStatementSetter(){
公共void setParameters(KV元素,PreparedStatement查询)
抛出SQLException{
setInt(1,element.getKey());
setInt(2,element.getValue());
}
})
);

下面的代码适合我

String conUrl="jdbc:postgresql://google/<dbName>?cloudSqlInstance=<InstanceName>&socketFactory=com.google.cloud.sql.postgres.SocketFactory&user=<UserName>&password=<PWD>";

p.apply(JdbcIO.<KV<Integer,Integer>>write()
    .withDataSourceConfiguration( DataSourceConfiguration.create("org.postgresql.Driver",conUrl)
            .withUsername(<UserName>)
            .withPassword(<PWD>)
            )
    .withStatement("insert into public.testTable(id,order_number) values(?, ?)")
    .withPreparedStatementSetter(new JdbcIO.PreparedStatementSetter<KV<Integer,Integer>>() {
        public void setParameters(KV<Integer,Integer> element, PreparedStatement query)
                throws SQLException {
            query.setInt(1, element.getKey());
            query.setInt(2, element.getValue());
        }
    })
);
String conUrl=“jdbc:postgresql://google/?cloudSqlInstance=&socketFactory=com.google.cloud.sql.postgres.SocketFactory&user=&password=";
p、 apply(JdbcIO.write()
.withDataSourceConfiguration(DataSourceConfiguration.create(“org.postgresql.Driver”,conUrl)
.withUsername()
.withPassword()
)
.with语句(“插入到public.testTable(id,订单号)值(?,)中”)
.withPreparedStatementSetter(新JdbcIO.PreparedStatementSetter(){
公共void setParameters(KV元素,PreparedStatement查询)
抛出SQLException{
setInt(1,element.getKey());
setInt(2,element.getValue());
}
})
);

这适用于我与jdbcIO建立连接

String conUrl="jdbc:postgresql://google/dbName?cloudSqlInstance=projectId:us-central1:databaseId&socketFactory=com.google.cloud.sql.postgres.SocketFactory&user=postgres&password=*****";

这对于我建立与jdbcIO的连接很有用

String conUrl="jdbc:postgresql://google/dbName?cloudSqlInstance=projectId:us-central1:databaseId&socketFactory=com.google.cloud.sql.postgres.SocketFactory&user=postgres&password=*****";