Google Cloud Services - Storage

This extension allows to inject a com.google.cloud.storage.Storage object inside your Quarkus application.

Be sure to have read the Google Cloud Services extension pack global documentation before this one, it contains general configuration and information.

Bootstrapping the project

First, we need a new project.Create a new project with the following command (replace the version placeholder with the correct one):

mvn io.quarkus:quarkus-maven-plugin:<quarkusVersion>:create \
    -DprojectGroupId=org.acme \
    -DprojectArtifactId=bigquery-quickstart \
    -Dextensions="resteasy-reactive-jackson,quarkus-google-cloud-storage"
cd storage-quickstart

This command generates a Maven project, importing the Google Cloud Storage extension.

If you already have your Quarkus project configured, you can add the quarkus-google-cloud-storage extension to your project by running the following command in your project base directory:

./mvnw quarkus:add-extension -Dextensions="quarkus-google-cloud-storage"

This will add the following to your pom.xml:

<dependency>
    <groupId>io.quarkiverse.googlecloudservices</groupId>
    <artifactId>quarkus-google-cloud-storage</artifactId>
</dependency>

Preparatory steps

To test Storage you first need to create a bucket named quarkus-hello then upload a file hello.txt in it. This file will be read by the test and returned from the endpoint.

You can use gsutil:

gsutil mb gs://quarkus-hello
echo "Hello World!" > hello.txt
gsutil cp hello.txt gs://my-bucket

Some example

This is an example usage of the extension: we create a REST resource with a single endpoint that gets the hello.txt object from the quarkus-hello bucket and returns its content.

import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import com.google.cloud.storage.Blob;
import com.google.cloud.storage.Bucket;
import com.google.cloud.storage.Storage;

@Path("/storage")
public class StorageResource {

    @Inject
    Storage storage;// Inject Storage

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String storage() {
        Bucket bucket = storage.get("quarkus-hello");// Get the bucket
        Blob blob = bucket.get("hello.txt"); // Get the object
        return new String(blob.getContent()); // Return its content
    }

}

Configuration Reference

Configuration property fixed at build time - All other configuration properties are overridable at runtime

Configuration property

Type

Default

Overrides the default service host. This is most commonly used for development or testing activities with a local Google Cloud Storage emulator instance.

Environment variable: QUARKUS_GOOGLE_CLOUD_STORAGE_HOST_OVERRIDE

string

Use the GRPC transport instead of the default HTTP transport.

Environment variable: QUARKUS_GOOGLE_CLOUD_STORAGE_TRANSPORT_USE_GRPC

boolean

false

Storage HTTP transport connect timeout

Environment variable: QUARKUS_GOOGLE_CLOUD_STORAGE_TRANSPORT_HTTP_CONNECT_TIMEOUT

int

Storage transport read timeout

Environment variable: QUARKUS_GOOGLE_CLOUD_STORAGE_TRANSPORT_HTTP_READ_TIMEOUT

int

Initial retry delay. See com.google.api.gax.retrying.RetrySettings.Builder#setInitialRetryDelay(Duration)

Environment variable: QUARKUS_GOOGLE_CLOUD_STORAGE_RETRY_INITIAL_RETRY_DELAY_MILLIS

int

Max retry delay. See com.google.api.gax.retrying.RetrySettings.Builder#setMaxRetryDelay(Duration)

Environment variable: QUARKUS_GOOGLE_CLOUD_STORAGE_RETRY_MAX_RETRY_DELAY_MILLIS

int

Initial RPC timeout. See com.google.api.gax.retrying.RetrySettings.Builder#setInitialRpcTimeout(Duration)

Environment variable: QUARKUS_GOOGLE_CLOUD_STORAGE_RETRY_INITIAL_RPC_TIMEOUT_MILLIS

int

Max RPC timeout. See com.google.api.gax.retrying.RetrySettings.Builder#setMaxRpcTimeout(Duration)

Environment variable: QUARKUS_GOOGLE_CLOUD_STORAGE_RETRY_MAX_RPC_TIMEOUT_MILLIS

int

Logical timeout. See com.google.api.gax.retrying.RetrySettings.Builder#setLogicalTimeout(Duration)

Environment variable: QUARKUS_GOOGLE_CLOUD_STORAGE_RETRY_LOGICAL_TIMEOUT_MILLIS

int

Total timeout. See com.google.api.gax.retrying.RetrySettings.Builder#setTotalTimeout(Duration)

Environment variable: QUARKUS_GOOGLE_CLOUD_STORAGE_RETRY_TOTAL_TIMEOUT_MILLIS

int

Maximum attempts. See com.google.api.gax.retrying.RetrySettings.Builder#setMaxAttempts(int)

Environment variable: QUARKUS_GOOGLE_CLOUD_STORAGE_RETRY_MAX_ATTEMPTS

int