DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Trending

  • Understanding IEEE 802.11(Wi-Fi) Encryption and Authentication: Write Your Own Custom Packet Sniffer
  • Customer 360: Fraud Detection in Fintech With PySpark and ML
  • Mastering Advanced Aggregations in Spark SQL
  • 5 Subtle Indicators Your Development Environment Is Under Siege

Java Serverless Functions With Quarkus Quick Starts

Getting started with your first Java serverless function using a Quarkus quick start.

By 
Daniel Oh user avatar
Daniel Oh
DZone Core CORE ·
Apr. 06, 22 · Tutorial
Likes (6)
Comment
Save
Tweet
Share
5.2K Views

Join the DZone community and get the full member experience.

Join For Free

Are you looking for the shortest path or cheatsheet to bring your Java application into a serverless platform based on Kubernetes? Perhaps you don't have enough time to stand up relevant infrastructure and configure settings for both the application and the platform. This article is a guide to developing Java serverless functions using a Quarkus quick start in the Developer Sandbox for Red Hat OpenShift. As you'll see, using quick starts in the Developer Sandbox lets you focus on the application development without needing to configure Knative.

The Developer Sandbox provides a shared, multi-tenant Red Hat OpenShift 4 cluster with a cloud IDE tool called Red Hat CodeReady Workspaces. All you need is a free account on Red Hat to get access for a limited time to a sandbox. Following the four steps in this article, you can stand up your own cluster in 10 minutes.

Step 1. Launch Your Sandbox

Go to the Welcome page for Developer Sandbox, then click the red Launch button shown in Figure 1. Log in using your Red Hat account.

Figure 1: You can launch a sandbox from the Welcome page.

Step 2. Choose the Quarkus Serverless Functions Quick Start

Once you are logged in to the sandbox, go to the +Add view in the Developer perspective. Click View all quick starts, then type serverless into the search box. Choose the Get started with Quarkus serverless functions quick start, as shown in Figure 2.

Figure 2: The Developer Sandbox offers many quick starts.

Step 3: Start the Development of Your Serverless Functions Using Quarkus

This 10-minute quick start develops some serverless functions in CodeReady Workspaces and deploys the functions to OpenShift using Quarkus extensions. The quick start takes you through the following tasks:

  1. Launch CodeReady Workspaces
  2. Run the Live Coding to develop new serverless functions
  3. Test your first serverless function
  4. Add a new serverless function using Quarkus CDI
  5. Deploy the Quarkus serverless function to OpenShift
  6. Access the functions on OpenShift

The quick start guides you through the step-by-step instructions to complete the tasks. When you complete each task, click Next to verify your work. If you have accomplished the task without any issues, click Yes and then Next to move forward to the next task, as shown in Figure 3.

Figure 3: Click Yes to check your work.

Most tasks in this quick start are self-explanatory, but a couple of them are worth exploring.

Step 4: Add a New Serverless Function Using Quarkus CDI

Quarkus simplifies bean discovery using the @Inject annotation, which is based on the Contexts and Dependency Injection (CDI) specification. You can also use this bean discovery while you're developing serverless functions, as in the following code:

Java
 
@Inject
MyFunctionsService myFunctionsService;

@Funq
public String greeting(String name) {

    return myFunctionsService.greeting(name);

}


When you check your work using the curl command line tool, you don't even need to save the source file, recompile, and restart the application after changing the code. Quarkus development mode updates the running application through Live Coding, as shown in Figure 4. The conveniences of this learning environment let you focus on serverless functions development.

Figure 4: Use a curl command to check the status of your application.

Step 5: Deploy the Quarkus Serverless Function to OpenShift

This quick start uses the Quarkus Funqy extension to make your serverless function (greeting) portable across multiple serverless platforms, including Red Hat OpenShift Serverless, AWS Lambda, Azure Functions, Google Cloud Platform, and Knative.

All required configurations are set in the application.properties file except the quarkus.container-image.group value. You need to replace USERNAME with your account (e.g., doh). Then deploy the Quarkus application using the Maven command-line tool. In the end, the Topology view displays the pod with a function icon, as shown in Figure 5.

Figure 5: Deploy the Quarkus serverless function to OpenShift.

The function pod might scale down to zero if there's no incoming traffic to the pod for 30 seconds.

When you have completed all six tasks, you will see the green checkmarks shown in Figure 6.

Figure 6: The green checkmarks indicate that all tasks have been completed.

Conclusion

In this article, you've learned how quickly you can get started with the development and deployment of Java serverless functions using a Quarkus quick start in the Developer Sandbox for Red Hat OpenShift. The sandbox also provides an out-of-the-box IDE environment for those developers who want to begin cloud-native microservices development on day 1. Visit the Developing with Quarkus self-service learning portal to learn more about Java application development using Quarkus.

Subscribe to bit.ly/danielohtv for learning cloud-native application development with Kubernetes.

Published at DZone with permission of . See the original article here.

Opinions expressed by DZone contributors are their own.

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!