This page gives step by step instructions to do the TCP routing demo as done in Cloud Foundry Summit 2016.
The demo at Cloud Foundry Summit 2016 was to push MQTT broker (mosquitto
) as CF app and create and bind a TCP route to it. To showcase that MQTT broker running as CF app is accessible for publishing and subscribing using TCP route, a subscriber web app and publisher android app was used.
This web app subscribes to accelerometer
topic of MQTT broker and displays the data published on this topic in a chart. It expects numeric data to be published on this topic.
-
Fetch the repo for sample-mqtt-subscriber
mkdir -p ~/workspace cd ~/workspace git clone https://github.com/GESoftware-CF/sample-mqtt-subscriber.git cd sample-mqtt-subscriber/
-
Build the project as follows:
mvn clean package
-
Push the resulting jar as CF app
cf push mqttsub target/mqttsubscriber-0.0.1-SNAPSHOT.jar
-
Verify that the app is successfully deployed and running by hitting endpoint
mqttsub.<app-domain>
. You should see web page like this:
![Image of mqttsubscriber landing page] (images/mqttsub_landing_page.png)
This android app registers itself to accelerometer sensor of the device and publishes y-axis acceleration to accelerometer
topic of MQTT broker.
-
Fetch the repo for sample-android-mqtt
mkdir -p ~/workspace cd ~/workspace git clone https://github.com/atulkc/sample-android-mqtt.git cd sample-android-mqtt/
-
Load the project in android studio.
-
Install the application on your favorite android phone using android studio.
-
Verify that the app is successfully installed and running by tapping the
Accelerometer
icon on your smartphone. You should see something like this:
We will be using mosquitto broker's docker image to push mqtt broker as CF app. We will use toke/mosquitto docker image.
-
Make sure you have created tcp domain:
cf create-shared-domain <tcp-domain> --router-group default-tcp
Replace
<tcp-domain>
with the name of the domain you want to give to your tcp domain. Of course, here we are assuming that dns entries for above created tcp domain will resolve to load balancer in front of tcp router groups or if tcp routers have public IP addresses then it will resolve to tcp routers. This has to be done by the operator/administrator of your Cloud Foundry deployment. -
Push mosquitto as CF app as follows:
cf push mqttbroker --docker-image toke/mosquitto -d <tcp-domain> --random-route
This will download the required docker image and push it as CF app and create and bind a tcp route.
-
Now you are ready to supply this tcp route information to your publisher and subscriber.
This is where we tie together the subscriber web app, android app and mqtt broker.
-
Enter
<tcp-domain>
as host name on landing page of web app and port of tcp route asport
. You should see an empty chart as follows:![Image of mqttsubscriber landing page] (images/mqttsub_empty_chart_page.png)
-
Now enter same information on android accelerometer app. You should see the next screen on android app indicating the y-axis acceleration:
-
The y-axis acceleration of your device should now start showing up on chart on web app:
![Image of chart of web app] (images/mqttsub_chart_page.png)