Want to get rid of all the mqtt connections and callbacks handling from your application? If yes, simply use the exposed apis to publish or subscribe/unsubscribe to your topic and you are done! The web-service will establish a connection with the mqtt broker on your behalf and publish/subscribe to your topic for you. Thus, your application does what it is supposed to do and all the mqtt part is extracted. For eg, your application running on raspberry pi can publish data to the topic via web-service without itself estalishing connections.
It is a Spring Boot application and the final executable is .jar file.
Requirements:
Java - 1.8
Redis
Steps to run the web-service:
- Clone the master branch into your local machine.
- Run the project as a Maven build. Command : mvn clean install
- Look for the .jar file in the target folder of the project.
- Copy the .jar file to a particular(for deployment) folder.
- You can have application.properties in the same folder where you placed your .jar to override default properties. Refer https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html for more details.
- Execute the .jar file. Command:java -jar mqtt.jar Note: Run the command in background to keep it running even if you log out of the computer.
Getting started with development:
Requirements: IDE- preferred Eclipse with Spring boot plugin and maven build support or STS.
- Clone the master branch into your local machine.
- Import in your ide.
- Run MqttWebServiceApplication.java as java application. Wait for successfull completion.
- If your application wants to publish data, make a GET/POST call
Sample GET:
https://localhost:8443/mqtt/publish?message=hey%20Vis&topic=/sometopic/somesubtopic
where, message: message you want to publish topic : name of the topic to which you want to publish.
Response:{"published":true}
Note: This will publish data to the broker configured in https://github.com/ANRGUSC/MQTT_WEBSERVICE/blob/master/src/main/resources/application.properties.
-
If you want to subscribe to the topic
Sample GET: https://localhost:8443/mqtt/subscribe?callbackUrl=http%3A%2F%2Fexample-url.edu%3A8084&topic=/sometopic/somesubtopic
where, callbackUrl: rest endpoint where you will receive messages from the topic topic : name of the topic you want to subscribe.
Response:{"subscribed":true} -
If you want to unsubscribe to the topic
Sample GET: https://localhost:8443/mqtt/unsubscribe?topic=/sometopic/somesubtopic
where, topic : name of the topic you want to unsubscribe from.
Response:{"unsubscribed":true}
See https://github.com/ANRGUSC/MQTT_WEBSERVICE/blob/master/License.md
Drop an email to rahane@usc.edu if you need any other info.