Installing MQTT Broker on Google Cloud

If you want to install MQTT broker on Google Cloud then you need a VM instance which allows you to install Services or Applications on Google cloud. If you don’t know how to create a VM instance on google cloud , please click on the following link. If you have already created VM instance on google cloud then direct start from the following steps.
Creating VM Instance on Google cloud



Installation steps for installing the MQTT broker on Google Cloud

To install MQTT broker on Google Cloud, please follow the following steps:
1)Open your SSH terminal by clicking on the SSH of respective Virtual instance.
2)use the following command to go in root directory:

sudo su
cd ..
cd ..

3)Execute the following command to Update Existing Packages.

sudo apt-get update

4)Execute the following command to install MQTT broker.

sudo apt-get install mosquitto

While Installing if its asking for Do you want to continue? [Y/n] enter Y and hit ENTER

5)Execute the following command to install MQTT clients such as publisher and subscriber.

sudo apt-get install mosquitto-clients

While Installing if its asking for Do you want to continue? [Y/n] enter Y and hit ENTER

6)Execute the following command to check Mosquitto version.

mosquitto -v


If it shows Mosquitto version 1.4.10 or higher version means Mosquitto Installed Successfully.




7)When you install particular service or application on google cloud , ports related to that service don’t get open automatically you need to open it. To open MQTT port 1883 , please click on the following link.
Opening port on Google Cloud

Google Cloud SSH Terminal as MQTT Subscriber:

Please follow the following steps to use, google cloud SSH terminal as MQTT Subscriber.
1)Open SSH terminal of respective VM Instance.
2)Execute the following command to Subscribe TOPIC test.

mosquitto_sub -t test

Google Cloud SSH Terminal as MQTT Publisher:

Please follow the following steps to use, google cloud SSH terminal as MQTT Publisher.
1)Open another SSH terminal of respective VM Instance.
2)Execute the following commands to Publish message(-m) on TOPIC test.

mosquitto_pub -t test -m “Google cloud”
mosquitto_pub -t test -m “Google broker”

After Executing above commands, Check your SSH Terminal as Subscriber, you should receive Google cloud and Google broker. If you have received the message Google cloud and Google broker on Subscriber SSH Terminal that means MQTT broker is Running and both publisher and subscriber are working correctly.

How to restart MQTT broker on google cloud?

Please follow the following steps to restart MQTT broker on google cloud.
1)Open your respective SSH terminal.
2)First, execute the following command to stop MQTT broker on google cloud.

sudo service mosquitto stop

3)Now, execute the following command to start MQTT broker on google cloud.

sudo service mosquitto start

You may also like...

2 Responses

  1. I cant subscribe for topic mqtt on google compute engine

Leave a Reply