数据流作业中的默认数据存储实例

Default datastore instance inside dataflow job

我正在尝试在数据流作业中调用 Google 数据存储 我得到的是空实例

datastore = DatastoreOptions.getDefaultInstance().getService();

这可能是一个凭据问题。你能试试这个吗,

Credentials credentials = context.getPipelineOptions().as(GcpOptions.class).getGcpCredential();

Datastore datastore = DatastoreOptions.newBuilder().setCredentials(credentials).build().getService();

尝试将此代码放在主函数中而不是数据流管道中。