All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.quarkiverse.googlecloudservices.bigquery.runtime.BigQueryProducer Maven / Gradle / Ivy

There is a newer version: 2.13.0
Show newest version
package io.quarkiverse.googlecloudservices.bigquery.runtime;

import java.io.IOException;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.Default;
import jakarta.enterprise.inject.Produces;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;

import com.google.api.gax.core.CredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.cloud.bigquery.BigQuery;
import com.google.cloud.bigquery.BigQueryOptions;
import com.google.cloud.bigquery.storage.v1.BigQueryWriteClient;
import com.google.cloud.bigquery.storage.v1.BigQueryWriteSettings;

import io.quarkiverse.googlecloudservices.common.GcpBootstrapConfiguration;
import io.quarkiverse.googlecloudservices.common.GcpConfigHolder;

@ApplicationScoped
public class BigQueryProducer {

    @Inject
    GoogleCredentials googleCredentials;

    @Inject
    CredentialsProvider credentialsProvider;

    @Inject
    GcpConfigHolder gcpConfigHolder;

    @Produces
    @Singleton
    @Default
    public BigQuery bigQuery() {
        GcpBootstrapConfiguration gcpConfiguration = gcpConfigHolder.getBootstrapConfig();
        return BigQueryOptions.newBuilder().setCredentials(googleCredentials)
                .setProjectId(gcpConfiguration.projectId().orElse(null))
                .build()
                .getService();
    }

    @Produces
    @Singleton
    @Default
    public BigQueryWriteClient bigQueryWriteClient() throws IOException {
        GcpBootstrapConfiguration gcpConfiguration = gcpConfigHolder.getBootstrapConfig();
        BigQueryWriteSettings bigQueryWriteSettings = BigQueryWriteSettings.newBuilder()
                .setCredentialsProvider(credentialsProvider)
                .setQuotaProjectId(gcpConfiguration.projectId().orElse(null))
                .build();
        return BigQueryWriteClient.create(bigQueryWriteSettings);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy