java.lang.IllegalStateException:获取gcp secret manager时,当needsExecutor()为true时调用getTransportChannel()

avkwfej4  于 2023-06-20  发布在  Java
关注(0)|答案(1)|浏览(103)

我尝试使用依赖版本google-cloud-secretmanager 2.13.0。有人能帮上忙吗?下面是util类来获取secret manager值。

public String get(String secretName) {
    try (SecretManagerServiceClient client = SecretManagerServiceClient.create()) {
        SecretVersionName secretVersionName = SecretVersionName.of(projectId, secretName, "latest");

        AccessSecretVersionRequest accessRequest = AccessSecretVersionRequest.newBuilder().setName(secretVersionName.toString()).build();

        ByteString secretValue = client.accessSecretVersion(accessRequest).getPayload().getData();

        String secretString = secretValue.toStringUtf8();

        if (StringUtils.isNotBlank(secretString)) {
            return secretString;
        } else {
            throw new RuntimeException(String.format("Secret of %s is blank", secretName));
        }
    } catch (Exception e) {
        throw new RuntimeException("Caught an error when getting a secret value.", e);
    }
}
Exception in thread "main" java.lang.RuntimeException: Caught an error when getting a secret value.
    at com.rakuten.rcp.cdu.util.SecretManager.get(SecretManager.java:30)
    at com.rakuten.rcp.cdu.FeedToGsp.run(FeedToGsp.java:107)
    at com.rakuten.rcp.cdu.FeedToGsp.main(FeedToGsp.java:101)
Caused by: java.lang.IllegalStateException: getTransportChannel() called when needsExecutor() is true
    at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.getTransportChannel(InstantiatingGrpcChannelProvider.java:180)
    at com.google.api.gax.rpc.ClientContext.create(ClientContext.java:201)
    at com.google.cloud.secretmanager.v1.stub.GrpcSecretManagerServiceStub.create(GrpcSecretManagerServiceStub.java:248)
    at com.google.cloud.secretmanager.v1.stub.SecretManagerServiceStubSettings.createStub(SecretManagerServiceStubSettings.java:349)
    at com.google.cloud.secretmanager.v1.SecretManagerServiceClient.<init>(SecretManagerServiceClient.java:180)
    at com.google.cloud.secretmanager.v1.SecretManagerServiceClient.create(SecretManagerServiceClient.java:162)
    at com.google.cloud.secretmanager.v1.SecretManagerServiceClient.create(SecretManagerServiceClient.java:153)
    at com.rakuten.rcp.cdu.util.SecretManager.get(SecretManager.java:15)
    ... 2 more```
62lalag4

62lalag41#

我怀疑你在这里有一些依赖冲突和不匹配的Beam/GAX版本。
您如何带来依赖项的匹配版本?
我知道最简单的方法是使用Beam提供的BOM:www.example.com https://cloud.google.com/dataflow/docs/guides/common-errors#java-dependency-errors

相关问题