How to build an event-driven Kotlin Android App using MQTT and Solace PubSub+ Event Broker: Cloud

hong Guest Posts: 480 ✭✭✭✭✭
edited July 2020 in Blogs & Tutorials #1

New blog post alert! This week Ghaith Dalla-Ali from our dev team delves into the world of IoT and Kotlin to build an Android App. Have you used Kotlin before? Tell us about it in the comments below.

MQTT is a lightweight publish-subscribe messaging protocol that’s fast becoming the de facto protocol of choice for Internet of Things (IoT) applications. MQTT’s popularity is largely due to its small bandwidth usage and low power consumption. In this article, we will leverage the Solace PubSub+ Event Broker’s native MQTT capabilities to build a simple event-driven Android app that uses the publish-subscribe messaging pattern. We will be using Kotlin as our programming language of choice when writing the Android app.

Creating a Solace PubSub+ Cloud Messaging Service

To build an event-driven application, you need to connect it to an event broker so that it could send and receive events asynchronously. Use Solace PubSub+ Cloud to create a free Messaging Service. Once the messaging service is up and running, navigate to its Connect tab and note its MQTT Connection Details. These details will later be used to connect our app to the Solace PubSub+ Event Broker.

Building an Event-Driven Android App in Kotlin

We will use the Android Studio IDE to build a new Kotlin project. The project will use the Eclipse Paho MQTT client library as our MQTT client library. This MQTT client library will be wrapped with a helper class that only exposes the methods we’ll need to publish and subscribe to Solace events. After writing the helper class, we will then build a simple Android MainActivity that we can use to subscribe to a user-defined topic and publish messages to the same topic.

Read the whole blog post at