Top Question Error getting access token for service account while downloading file from GCS bucket after few seconds of successful uploading

H

Heriberto Miguel

Guest
I have two JAVA micro services on the same machine and I upload a file from service A and download it from service B to process in the background.

Service A uploads the file successfully but service B gives me the following error (Service B executes 1 second after service A uploads the file)

Mã:
com.google.cloud.storage.StorageException: Error getting access token for service account: Connection refused: connect
    at com.google.cloud.storage.spi.v1.HttpStorageRpc.translate(HttpStorageRpc.java:286) ~[google-cloud-storage-2.6.1.jar:2.6.1]
HttpStorageRpc.java:286
    at com.google.cloud.storage.spi.v1.HttpStorageRpc.get(HttpStorageRpc.java:511) ~[google-cloud-storage-2.6.1.jar:2.6.1]
HttpStorageRpc.java:511
    at com.google.cloud.storage.StorageImpl.lambda$get$6(StorageImpl.java:281) ~[google-cloud-storage-2.6.1.jar:2.6.1]
StorageImpl.java:281
    at com.google.api.gax.retrying.DirectRetryingExecutor.submit(DirectRetryingExecutor.java:105) ~[gax-1.49.1.jar:1.49.1]
DirectRetryingExecutor.java:105
    at com.google.cloud.RetryHelper.run(RetryHelper.java:76) ~[google-cloud-core-1.91.3.jar:1.91.3]
RetryHelper.java:76
    at com.google.cloud.RetryHelper.runWithRetries(RetryHelper.java:50) ~[google-cloud-core-1.91.3.jar:1.91.3]
RetryHelper.java:50
    at com.google.cloud.storage.Retrying.run(Retrying.java:54) ~[google-cloud-storage-2.6.1.jar:2.6.1]
Retrying.java:54
    at com.google.cloud.storage.StorageImpl.run(StorageImpl.java:1376) ~[google-cloud-storage-2.6.1.jar:2.6.1]
StorageImpl.java:1376
    at com.google.cloud.storage.StorageImpl.get(StorageImpl.java:280) ~[google-cloud-storage-2.6.1.jar:2.6.1]
StorageImpl.java:280
    at com.google.cloud.storage.StorageImpl.get(StorageImpl.java:286) ~[google-cloud-storage-2.6.1.jar:2.6.1]

I have configured the credentials in the client variable GOOGLE_APPLICATION_CREDENTIALS.

Service A file upload code:

Mã:
Storage storage = StorageOptions.getDefaultInstance().getService();
BlobId blobId = BlobId.of(defaultBucket, path);
BlobInfo blobInfo = BlobInfo.newBuilder(blobId).build();
storage.create(blobInfo, content);

Service B file download code:

Mã:
Storage storage = StorageOptions.getDefaultInstance().getService();
Blob blob = storage.get(BlobId.of(this.defaultBucket, url));
ReadChannel reader = blob.reader();
InputStream inputStream = Channels.newInputStream(reader);
return inputStream.readAllBytes();

Answer for: "Error getting access token for service account while downloading file from GCS bucket after few seconds of successful uploading"...
 
Top