Getting Started with IoT Edge development using Quarkus on CentOS Stream

This project implements on how developers get started with IoT edge development on CentOS Stream but we’ll also showcase how Quarkus, a cloud-native Java framework enables developers to integrate a lightweight message broker for processing data streams from the IoT devices in a reactive way, as shown in Figure 1.

arch.png

Figure 1. Hige Level Architecture for IoT Edge Development

Quarkus SmallRye Messaging and RESTEasy extensions

SmallRye Reactive messaging is a framework for building event-driven, data streaming, and event-sourcing applications using CDI. It lets your application interaction using various messaging technologies such as Apache Kafka, AMQP or MQTT. The framework provides a flexible programming model bridging CDI and event-driven. SmallRye Messaging

I also used the quickstarts for inspiration and understanding the basics [Quarkus quickstarts](https://github.com/quarkusio/quarkus-quickstarts) And the accompanying [guides](https://quarkus.io/guides/)

Once you add the extensions, pom.xml in your Maven project should look like:

    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-smallrye-reactive-messaging-mqtt</artifactId>
    </dependency>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-arc</artifactId>
    </dependency>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-resteasy</artifactId>
    </dependency>

CentOS Stream

One of the Linux distributions that provides a reliable open source OS platform to handle various business applications from traditional enterprise Java to cloud, IoT edge, and AI/ML environments. CentOS Stream is a free midstream between Fedora and Red Hat Enterprise Linux (RHEL) to provide full features of RHEL by delivering a clear governance model, increased transparency, and access. For more information to download and install the CentOS Steam here.

Podman

Podman is a utility provided as part of the libpod library. It can be used to create and maintain containers. The following tutorial will teach you how to set up Podman and perform some basic commands.

Mosquitto

Eclipse Mosquitto is an open source (EPL/EDL licensed) message broker that implements the MQTT protocol versions 5.0, 3.1.1 and 3.1. Mosquitto is lightweight and is suitable for use on all devices from low power single board computers to full servers.

To start the Mosquitto message broker, Use the following Podman command on CentOS Stream:

$ podman run --name mosquitto --rm -p "9001:9001" -p "1883:1883" eclipse-mosquitto:1.6.2

For Docker CLI users:

$ docker run -p 9001:9001 -p 1883:1883 -it eclipse-mosquitto:1.6.2

Edge Devices

The device in this case an emulated one ESP8266-01 that throws Temperature and heat as a Json into the MQTT broker. That is then picked up as a reactive channel and throws that data out after processing into the stream. The stream is read by the browser and displays the data in realtime. The emulated device can easily be changed to a real one, however the data thrown should be in the correct Json format.

Running the application in dev mode

You can run your application in dev mode that enables live coding using:

./mvnw compile quarkus:dev
Note

Quarkus now ships with a Dev UI, which is available in dev mode only at http://localhost:8080/q/dev/.

Packaging and running the application

The application can be packaged using:

./mvnw package

It produces the quarkus-run.jar file in the target/quarkus-app/ directory. Be aware that it’s not an über-jar as the dependencies are copied into the target/quarkus-app/lib/ directory.

If you want to build an über-jar, execute the following command:

./mvnw package -Dquarkus.package.type=uber-jar

The application is now runnable using java -jar target/quarkus-app/quarkus-run.jar.

Creating a native executable

You can create a native executable using:

./mvnw package -Pnative

Or, if you don’t have GraalVM installed, you can run the native executable build in a container using:

./mvnw package -Pnative -Dquarkus.native.container-build=true

Monitoring IoT Edge Data Stream

Open a web browser then access the Dashboard.

You should see:

screenshot.png