DZone
Java Zone
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
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Java Zone > Java Serverless Functions With Quarkus Quick Starts

Java Serverless Functions With Quarkus Quick Starts

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

Daniel Oh user avatar by
Daniel Oh
CORE ·
Apr. 06, 22 · Java Zone · Tutorial
Like (5)
Save
Tweet
3.69K 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 Daniel Oh. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Learn APIs With Coding Over Cocktails
  • Build a Business-Led API Strategy and Get the Most Out of Your APIs
  • Instancio: Test Data Generator for Java (Part 2)
  • API Security Weekly: Issue 164

Comments

Java Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo