在云数据流中运行时,我无法从自定义DoFn中连接到云SQL。日志中显示的错误如下:
当从appenginer句柄连接到云sql时,相同的代码和配置工作得很好。
我已经显式地给出了计算引擎服务帐户-compute@developer.gserviceaccount.com - Cloud客户端、Cloud查看器和编辑器角色。
任何帮助来排除这一点是非常感谢的!
发布于 2019-05-15 15:01:49
要从外部应用程序连接到Cloud,可以在文档中遵循一些方法--如何从外部applications1连接到Cloud -您可以找到实现目标的替代方案和步骤。
发布于 2019-05-22 20:00:30
在尝试使用带有云数据流的连接池来使用自定义DoFn的cloud时,我也遇到了许多问题。现在,我不记得我的错误是否与您的错误相同,但我的解决方案是在DoFn类中创建一个@Setup方法,如下所示:
static class ProcessDatabaseEvent extends DoFn<String, String> {
@Setup
public void createConnectionPool() throws IOException {
final Properties properties = new Properties();
properties.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("config.properties"));
final String JDBC_URL = properties.getProperty("jdbc.url");
final String JDBC_USER = properties.getProperty("jdbc.username");
final String JDBC_PASS = properties.getProperty("jdbc.password");
final HikariConfig config = new HikariConfig();
config.setMinimumIdle(5);
config.setMaximumPoolSize(50);
config.setConnectionTimeout(10000);
config.setIdleTimeout(600000);
config.setMaxLifetime(1800000);
config.setJdbcUrl(JDBC_URL);
config.setUsername(JDBC_USER);
config.setPassword(JDBC_PASS);
pool = new HikariDataSource(config);
}
@ProcessElement
public void processElement(final ProcessContext context) throws IOException, SQLException {
//Your DoFn code here...
}https://stackoverflow.com/questions/56135135
复制相似问题