Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cloud tasks support #300

Open
zecit opened this issue Jul 4, 2022 · 8 comments
Open

Add cloud tasks support #300

zecit opened this issue Jul 4, 2022 · 8 comments

Comments

@zecit
Copy link

zecit commented Jul 4, 2022

Add a module to support cloud tasks creation.

@bernardocoferre
Copy link
Contributor

+1

@kamal-j
Copy link

kamal-j commented Feb 10, 2023

Any update on this?

@loicmathieu
Copy link
Collaborator

No update, we didn't plan to support any Google Cloud services as it may be a huge task.
Anyone how is interested should +1 on the issue description so I know that is a wanted feature.

Most Google Cloud Services works in the same way so I plan to create a section on the documentation explaining how someone can integrate them without needing and extension (it's mainly authentication and gRCP integration with Quarkus gRCP).

@kamal-j
Copy link

kamal-j commented Feb 13, 2023

Most Google Cloud Services works in the same way so I plan to create a section on the documentation explaining how someone can integrate them without needing and extension (it's mainly authentication and gRCP integration with Quarkus gRCP).

That would be very helpful. Thanks!

@shaonianA
Copy link

+1

@ayhanap
Copy link

ayhanap commented Nov 3, 2023

I've been using Cloud Tasks in my quarkus application for a while. I hope I didn't miss anything because it's been a while and hard to extract needed parts.

To make it work as native image I added following to pom.xml

        <dependency>
            <groupId>io.quarkiverse.googlecloudservices</groupId>
            <artifactId>quarkus-google-cloud-common</artifactId>
        </dependency>
        <dependency>
            <groupId>io.quarkiverse.googlecloudservices</groupId>
            <artifactId>quarkus-google-cloud-common-grpc</artifactId>
        </dependency>
        <dependency>
            <groupId>com.google.cloud</groupId>
            <artifactId>google-cloud-tasks</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>javax.annotation</groupId>
                    <artifactId>javax.annotation-api</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.checkerframework</groupId>
                    <artifactId>checker-qual</artifactId>
                </exclusion>
                <!-- We exclude the grpc-netty-shaded library as grpc-netty is included via
                quarkus-google-cloud-common-grpc and Quarkus includes the netty library -->
                <exclusion>
                    <groupId>io.grpc</groupId>
                    <artifactId>grpc-netty-shaded</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.google.api</groupId>
                    <artifactId>gax-grpc</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>animal-sniffer-annotations</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-grpc-common</artifactId>
        </dependency>

And to initialize and authenticate I do following.


@Inject
GoogleCredentials googleCredentials;
    
    
CloudTasksSettings settings = CloudTasksSettings.newBuilder()                            
 .setCredentialsProvider(FixedCredentialsProvider.create(googleCredentials))
                                .build();
try (CloudTasksClient client = CloudTasksClient.create(settings)) {
   
  // Construct the fully qualified queue name.
  String queuePath = QueueName.of(gCloudProjectId, gCloudLocationId, 
  ct.getQueueName()).toString();
  OidcToken.Builder oidcTokenBuilder =
  OidcToken.newBuilder()
     .setServiceAccountEmail(gCloudServiceAccount)
     .setAudience(ct.getAudiance());
                                        
  Task.newBuilder()
     .setHttpRequest(HttpRequest.newBuilder()
                     .setBody(ByteString.copyFrom(ct.getBody(), Charset.defaultCharset()))
                      .putHeaders("Content-Type", "application/json")
                      .setUrl(ct.getUrl())
                       .setHttpMethod(ct.getMethod())
                       .setOidcToken(oidcTokenBuilder)
                       .build())
                       
  Task taskToCreate = taskBuilder.build();

  // Send create task request.
  Task task = client.createTask(queuePath, taskToCreate);
  System.out.println("Task created: " + task.getName());

}
                                

@loicmathieu
Copy link
Collaborator

Thanks @ayhanap these steps are the basic steps for supporting any Google Cloud services: declaring the dependency with exclusion, if gRCP is used: excluding the dependency and importing the Quarkuse one, injecting authentication and initiating a client. To make it looks more like an extension you can create a CDI producer for the client.

I still have plan to add a documentation page for it, I may borrow the code for your example ;)

I think you don't need to exclude

                <exclusion>
                    <groupId>com.google.api</groupId>
                    <artifactId>gax-grpc</artifactId>
                </exclusion>

And for checker-qual and animal-sniffer, excluding them should be only needed when the lib is integrated into a Quarkus extension.

@ayhanap
Copy link

ayhanap commented Nov 6, 2023

I got inspired by existing code from other gcloud services, I just copied the storage one I guess :) Might be right about unnecessary exclusions, been a while don't remember if they caused any issues.

Feel free to use it as you like, it's just the sample code from https://cloud.google.com/tasks/docs/creating-http-target-tasks#java and some modifications for authentication.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants