Skip to main content
Redhat Developers  Logo
  • Products

    Featured

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat OpenShift AI
      Red Hat OpenShift AI
    • Red Hat Enterprise Linux AI
      Linux icon inside of a brain
    • Image mode for Red Hat Enterprise Linux
      RHEL image mode
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • Red Hat Developer Hub
      Developer Hub
    • View All Red Hat Products
    • Linux

      • Red Hat Enterprise Linux
      • Image mode for Red Hat Enterprise Linux
      • Red Hat Universal Base Images (UBI)
    • Java runtimes & frameworks

      • JBoss Enterprise Application Platform
      • Red Hat build of OpenJDK
    • Kubernetes

      • Red Hat OpenShift
      • Microsoft Azure Red Hat OpenShift
      • Red Hat OpenShift Virtualization
      • Red Hat OpenShift Lightspeed
    • Integration & App Connectivity

      • Red Hat Build of Apache Camel
      • Red Hat Service Interconnect
      • Red Hat Connectivity Link
    • AI/ML

      • Red Hat OpenShift AI
      • Red Hat Enterprise Linux AI
    • Automation

      • Red Hat Ansible Automation Platform
      • Red Hat Ansible Lightspeed
    • Developer tools

      • Red Hat Trusted Software Supply Chain
      • Podman Desktop
      • Red Hat OpenShift Dev Spaces
    • Developer Sandbox

      Developer Sandbox
      Try Red Hat products and technologies without setup or configuration fees for 30 days with this shared Openshift and Kubernetes cluster.
    • Try at no cost
  • Technologies

    Featured

    • AI/ML
      AI/ML Icon
    • Linux
      Linux Icon
    • Kubernetes
      Cloud icon
    • Automation
      Automation Icon showing arrows moving in a circle around a gear
    • View All Technologies
    • Programming Languages & Frameworks

      • Java
      • Python
      • JavaScript
    • System Design & Architecture

      • Red Hat architecture and design patterns
      • Microservices
      • Event-Driven Architecture
      • Databases
    • Developer Productivity

      • Developer productivity
      • Developer Tools
      • GitOps
    • Secure Development & Architectures

      • Security
      • Secure coding
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
      • View All Technologies
    • Start exploring in the Developer Sandbox for free

      sandbox graphic
      Try Red Hat's products and technologies without setup or configuration.
    • Try at no cost
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • Java
      Java icon
    • AI/ML
      AI/ML Icon
    • View All Learning Resources

    E-Books

    • GitOps Cookbook
    • Podman in Action
    • Kubernetes Operators
    • The Path to GitOps
    • View All E-books

    Cheat Sheets

    • Linux Commands
    • Bash Commands
    • Git
    • systemd Commands
    • View All Cheat Sheets

    Documentation

    • API Catalog
    • Product Documentation
    • Legacy Documentation
    • Red Hat Learning

      Learning image
      Boost your technical skills to expert-level with the help of interactive lessons offered by various Red Hat Learning programs.
    • Explore Red Hat Learning
  • Developer Sandbox

    Developer Sandbox

    • Access Red Hat’s products and technologies without setup or configuration, and start developing quicker than ever before with our new, no-cost sandbox environments.
    • Explore Developer Sandbox

    Featured Developer Sandbox activities

    • Get started with your Developer Sandbox
    • OpenShift virtualization and application modernization using the Developer Sandbox
    • Explore all Developer Sandbox activities

    Ready to start developing apps?

    • Try at no cost
  • Blog
  • Events
  • Videos

Build your first Java serverless function using a Quarkus quick start

March 28, 2022
Daniel Oh
Related topics:
JavaQuarkusServerless
Related products:
Developer SandboxRed Hat OpenShift ServerlessRed Hat OpenShift

Share:

    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.

    You can launch a sandbox from the Welcome page.
    Figure 1. You can launch a sandbox from the Welcome page.
    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.

    The Developer Sandbox offers many quick starts.
    Figure 2. The Developer Sandbox offers many quick starts.
    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.

    Click Yes to check your work.
    Figure 3. Click Yes to check your work.
    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.

    Task 3: 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:

    @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.

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

    Task 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.

    Deploy the Quarkus serverless function to OpenShift
    Figure 5: Deploy the Quarkus serverless function to OpenShift
    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.

    The green checkmarks indicate that all tasks have been completed.
    Figure 6: The green checkmarks indicate that all tasks have been completed.
    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.

    Last updated: October 31, 2023

    Recent Posts

    • How to encrypt RHEL images for Azure confidential VMs

    • How to manage RHEL virtual machines with Podman Desktop

    • Speech-to-text with Whisper and Red Hat AI Inference Server

    • How to use Splunk as an event source for Event-Driven Ansible

    • Integrate vLLM inference on macOS/iOS with Llama Stack APIs

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Products

    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform

    Build

    • Developer Sandbox
    • Developer Tools
    • Interactive Tutorials
    • API Catalog

    Quicklinks

    • Learning Resources
    • E-books
    • Cheat Sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site Status Dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Report a website issue