HiveMQ 4 Kotlin Hello World Extension
Type: Demonstration Extension
Version: 4.3.1
License: Apache License Version 2.0
Purpose
This is the Kotlin version of the orginal HiveMQ Hello World extension. Its purpose is to demonstrate how to write HiveMQ extensions using Kotlin instead of Java.
The Hello World extension sets a ClientLifecycleEventListener which logs the MQTT Version and identifier of every connecting and disconnecting client and registers a PublishInboundInterceptor to modify the payload of every Publish with the topic 'hello/world' to 'Hello World!'.
There is a Maven Archetype available to generate a basic extension from the IDE in Java.
It is strongly recommended to read the HiveMQ Extension Documentation to grasp the core concepts of HiveMQ extension development.
Using Kotlin with Maven
You can find information on how to us Kotlin with Apache Maven in official Kotlin documentation.
Installation
-
Clone this repository into a Java 11 maven project.
-
Run
mvn package
goal from Maven to build the extension. -
Move the file: "target/hivemq-hello-world-extension-4.3.1-distribution.zip" to the directory: "HIVEMQ_HOME/extensions"
-
Unzip the file.
-
Start HiveMQ.
First Steps
Manual Testing
Connect with an MQTT client of your choice. You should see a log message with its identifier and MQTT version.
Automatic Testing
Execute the HelloWorldInterceptorIT
for automatic testing of the extension.
It uses the HiveMQ Testcontainer to automatically package, deploy and run the extension inside a HiveMQ docker container.
The test creates a HiveMQ MQTT Client to publish and receive a message with the topic 'hello/world'.
It checks whether the payload has been changed correctly to 'Hello World!'.
Next steps
Awesome, you got your first HiveMQ 4 Kotlin extension working.
Now read the HiveMQ Extension Documentation to see what extensions can do.
Need help?
If you encounter any problems, I am happy to help.