I would like to store published MQTT messages to database (postgresql). I did a search on how to do this and found an article https://www.hivemq.com/blog/mqtt-sql-database/ that rather than having a client to subscribe to all topic (#) and store to database, I should let the MQTT server handle it. So the solution is to use HiveMQ with plugins or extensions.
I have been trying to create an extensions to store MQTT messages to database but I am having a problem with java.lang.ClassNotFoundException: org.postgresql.Driver. In my extension, I use postgresql-42.2.18.jar. But I have no idea how to add the .jar to newly created extension. I have tried to put the .jar file in the same folder as the extension, but still I have the same error: class not found. I already use CLASSPATH variable. My simple java program is able to connect to the database without a problem using the .jar file from the CLASSPATH. I also tried to add “-cp /home/user/jar/postgresql-42.2.18.jar” to the JAVA_OPTS in run.sh, but still have no luck.
Please suggest what should I do in order to resolve this problem. Or are there any resources I should take a look as an example on how to store messages to database? Thank you very much.