无法使用 Java SocketFactory 库连接到云 SQL
Cannot connect to Cloud SQL with Java SocketFactory Library
这是我在云端提出的重复问题 SQL google 小组讨论论坛:https://groups.google.com/forum/#!topic/google-cloud-sql-discuss/qYmjvfH0MdI
我正在使用 Cloud Dataflow 运行 一些使用 Cloud SQL 作为我个人帐户中的接收器的管道。管道执行后,我想连接到 Cloud SQL 到 运行 一条删除语句。我不能 运行 使用 JdbcIO 删除(只能选择和插入)。尽管我可以使用 JdbcIO 连接到云 SQL,但我无法使用普通 Jdbc 连接到它。
下面是我用来连接到我的实例的代码
static void cleanUpPipeline() {
String jdbcUrl = String.format(
"jdbc:postgresql://google/%s?cloudSqlInstance=%s"
+ "&socketFactory=com.google.cloud.sql.postgres.SocketFactory",
"xxxxxx",
"xxxxxx");
try {
Class.forName("org.postgresql.Driver");
Connection connection = DriverManager.getConnection(jdbcUrl, "xxxxxx", "xxxxxx");
} catch (SQLException | ClassNotFoundException e) {
e.printStackTrace();
}
}
我的 pom.xml 具有以下依赖项:
<dependency>
<groupId>com.google.cloud.sql</groupId>
<artifactId>postgres-socket-factory</artifactId>
<version>1.0.11</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.5</version>
</dependency>
我收到的错误是:
INFO: Connecting to Cloud SQL instance [xxxxxxxxx] via ssl socket. nov
13, 2018 2:53:49 PM com.google.cloud.sql.core.SslSocketFactory
getInstance
INFO: First Cloud SQL connection, generating RSA key pair. nov 13,
2018 2:53:51 PM com.google.cloud.sql.core.SslSocketFactory
fetchInstanceSslInfo
INFO: Obtaining ephemeral certificate for Cloud SQL instance [xxxxxx].
nov 13, 2018 2:53:54 PM com.google.cloud.sql.core.SslSocketFactory
createAndConfigureSocket
INFO: Connecting to Cloud SQL instance [xxxxxxxx] on IP [xxxxxxx]
org.postgresql.util.PSQLException: Connection to google:5432 refused.
Check that the hostname and port are correct and that the postmaster
is accepting TCP/IP connections.
我相信我所做的一切都在这里。谁能帮我?
最后是防火墙的问题。我无法从防火墙内部访问端口 3307,这是云 SQL 代理使用的端口。我相信 Java SocketFactory 库也需要使用该端口。
这是我在云端提出的重复问题 SQL google 小组讨论论坛:https://groups.google.com/forum/#!topic/google-cloud-sql-discuss/qYmjvfH0MdI
我正在使用 Cloud Dataflow 运行 一些使用 Cloud SQL 作为我个人帐户中的接收器的管道。管道执行后,我想连接到 Cloud SQL 到 运行 一条删除语句。我不能 运行 使用 JdbcIO 删除(只能选择和插入)。尽管我可以使用 JdbcIO 连接到云 SQL,但我无法使用普通 Jdbc 连接到它。
下面是我用来连接到我的实例的代码
static void cleanUpPipeline() {
String jdbcUrl = String.format(
"jdbc:postgresql://google/%s?cloudSqlInstance=%s"
+ "&socketFactory=com.google.cloud.sql.postgres.SocketFactory",
"xxxxxx",
"xxxxxx");
try {
Class.forName("org.postgresql.Driver");
Connection connection = DriverManager.getConnection(jdbcUrl, "xxxxxx", "xxxxxx");
} catch (SQLException | ClassNotFoundException e) {
e.printStackTrace();
}
}
我的 pom.xml 具有以下依赖项:
<dependency>
<groupId>com.google.cloud.sql</groupId>
<artifactId>postgres-socket-factory</artifactId>
<version>1.0.11</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.5</version>
</dependency>
我收到的错误是:
INFO: Connecting to Cloud SQL instance [xxxxxxxxx] via ssl socket. nov 13, 2018 2:53:49 PM com.google.cloud.sql.core.SslSocketFactory getInstance
INFO: First Cloud SQL connection, generating RSA key pair. nov 13, 2018 2:53:51 PM com.google.cloud.sql.core.SslSocketFactory fetchInstanceSslInfo
INFO: Obtaining ephemeral certificate for Cloud SQL instance [xxxxxx]. nov 13, 2018 2:53:54 PM com.google.cloud.sql.core.SslSocketFactory createAndConfigureSocket
INFO: Connecting to Cloud SQL instance [xxxxxxxx] on IP [xxxxxxx] org.postgresql.util.PSQLException: Connection to google:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
我相信我所做的一切都在这里。谁能帮我?
最后是防火墙的问题。我无法从防火墙内部访问端口 3307,这是云 SQL 代理使用的端口。我相信 Java SocketFactory 库也需要使用该端口。