A MQTT command receiver for Apache Flink, using MQTT.fx to perform test
-
Download
mqtt.fx 1.7.1
-
Install mosquitto server on your virtual machine or server by linux command:
$ sudo apt install -y mosquitto
-
Use this command to check the status of mosquitto server, where it should be both
active
andloaded
$ sudo systemctl status mosquitto
-
After installation, mosquitto should be automatically started. If not use this command to manually start it:
$ sudo systemctl start mosquitto
Moreover, use this command to stop it:
$ sudo systemctl stop mosquitto
Or restart it:
$ sudo systemctl restart mosquitto
-
Install Mosquitto Clients using this command:
$ sudo apt install -y mosquitto-clients
-
A TOPIC is like a relative path but in IoT setting, like:
home/living_room/TV
,home/bathroom/toilet
,home/garden/fountain
, etc. You can subscribe a topic by command line:$ mosquitto_sub -t [TOPIC NAME]
For example:
$ mosquitto_sub -t "home/living_room/TV"
-
You can push notifications using command, for example, set the
TV
in theliving room
ON
:$ mosquitto_pub -m "ON" -t "home/living_room/TV"
Since we use
mqtt.fx
, it is not necessary to use command to subscribe and push commands. -
Open
mqtt.fx
, click the gear icon, connect tolocalhost: 1883
, we choose 1883 because it does not need any authentication to connect. Then specify theusername
,password
,hostname
,clientID
andmsgTopic
properties for objectMqttConfig
in line24
inMqttConsumer.java
The values of
username
,password
,hostname
andmsgTopic
should be the SAME as those inmqtt.fx
configuration, whileclientID
should be DIFFERENT with the one inmqtt.fx
! Or you will get frequently kicked out whenever you try to connect to both clients. -
Start both
mqtt.fx
client and the java program, pushing notifications onmqtt.fx
and you should be able to see the commands on the terminal where you run Java program.