Reading Time: 2 minutes
In this blog, we will cover how Micronaut is integrated with the Google Cloud Platform (GCP)
What is Micronaut
Micronaut is an open-source JVM-based software framework for building lightweight, modular applications and microservices.
It is a provider of computing resources for developing, deploying, and operating applications on the Web.
- We will need a “micronaut-gcp-common” maven dependency in order to run our application on the Google Platform.
<dependency> <groupId>io.micronaut.gcp</groupId> <artifactId>micronaut-gcp-common</artifactId> <version>2.0.2</version> </dependency>
- We should have a Google Cloud account or a free trial account in order to set up a Google Cloud project on the console.
- We can create a Google Cloud project from the Google Cloud UI itself or install the “gcloud CLI”.
- It’s strongly recommended that you use a Service Account for your application.
We are going to deploy a Micronaut application as an HTTP Function to Google Cloud
- The Controller Class
- Next, Google Cloud requirements: We need a Google Cloud account and also a Google Cloud project.
- Create an executable jar including all dependencies:
- You need a single JAR. Delete every ‘jar’ except
<you_project_name>-0.1.jarin your target directory (where the jar is present).
- Next run:
gcloud functions deploy <project_name> --entry-point io.micronaut.gcp.function.http.HttpFunction --runtime java11 --trigger-http
- To get the trigger URL, do the following:
YOUR_HTTP_TRIGGER_URL=$(gcloud functions describe <project_name> --format='value(httpsTrigger.url)')
- Now using the above variable we can test the function invocation:
curl -w "\n" $YOUR_HTTP_TRIGGER_URL/<your_endpoint>
- Finally, we will see the below response on this trigger URL:
Hence, we have seen above how to integrate Micornaut with the Google platform with an example of how to deploy a Micronaut application as an HTTP Function to Google Cloud and get the response using the trigger URL.