Quarkus - Using WebSockets

    To complete this guide, you need:

    • less than 15 minutes

    • an IDE

    • Apache Maven 3.5.3+

    Architecture

    In this guide, we create a straightforward chat application using web sockets to receive and send messages to the other connected users.

    Clone the Git repository: git clone , or download an archive.

    The solution is located in the websockets-quickstart .

    Creating the Maven project

    First, we need a new project. Create a new project with the following command:

    This command generates the Maven project (without any classes) and import the extension.

    Our application contains a single class that handles the web sockets.Create the org.acme.websocket.ChatSocket class in the src/main/java directory.Copy the following content into the created file:

    • Configures the web socket URL

    • Stores the currently opened web sockets

    A slick web frontend

    Now, let’s see our application in action. Run it with:

    Then open your 2 browser windows to http://localhost:8080/:

    • Enter a name in the top text area (use 2 different names).

    • Send and receive messages

    Application

    As usual, the application can be packaged using ./mvnw clean package and executed using the file.You can also build the native executable using ./mvnw package -Pnative.