MQTT Broker Google Pubsub Integration By Ranjith kumar DSM January 14, 2019Google Pubsub is one of the leading Queue engine used to collect data from the publisher or MQTT Application for better data analytics. Integration of Bevywise MQTT Broker with Google Pubsub helps you push data from your IoT & IIoT edge devices via MQTT Broker to google pubsub.Set up Google Compute for PubsubGoogle Pubsub is accessible from your Google cloud services account. You can follow the Google Pubsub document to create Google Pubsub with a publish topic. Create Ubuntu InstanceWe will be running the Bevywise MQTT Broker on the Ubuntu instance which was created in Google Cloud. Refer to the Google help document for creating the Ubuntu instance. in Google cloud. Installation Google Pub/Sub dependenciesOnce you created an Ubuntu instance, login to that instance and install the below dependencies.Open terminal and install below gloud cloud packagessudo pip install google-cloud-coresudo pip install google-api-coresudo pip install –upgrade google-cloud-pubsubGo to “/usr/local/lib/python2.7/dist-packages/PyInstaller/hooks/” folder.cd /usr/local/lib/python2.7/dist-packages/PyInstaller/hooks/In that foldder, open “hook-google.cloud.py” file bysudo vim hook-google.cloud.pyIn that file, remove all the default lines and add the below codefrom PyInstaller.utils.hooks import copy_metadata datas = copy_metadata(‘google-cloud-core’) datas += copy_metadata(‘google-api-core’) datas += copy_metadata(‘google-cloud-pubsub’)save and exit fileMQTT Broker Google Pubsub IntegrationInstall Bevywise MQTTBroker in the created Ubuntu instance.After installation, go to Bevywise/MQTT Broker/extension folder.In that folder, open “custom_store.py” and replace the below codeimport os import sys import json from google.cloud import pubsub_v1 sys.path.append(os.getcwd()+’/lib’) sys.path.append(‘/usr/local/lib/python2.7/dist-packages’) project_Id = ‘project_name’ broker_Id = ‘testing’ def handle_Received_Payload(data): global pubsub_v1 global project_Id global broker_Id publisher = pubsub_v1.PublisherClient() topic_path = publisher.topic_path(project_Id, ‘broker’) data = json.dumps(data) data = data.encode(‘utf-8’) publisher.publish(topic_path, data=data, device=broker_Id)In this code, “project id” represent the project id which you while creating google pubsubSave and exit the fileGo to Bevywise/MQTT Broker/conf folderOpen “data_store.conf” and change the following parametersCUSTOMSTORAGE = ENABLEDSave and exit the file.If you want to run the MQTTBroker with authentication, then follow the stepsopen Bevywise/MQTTBroker/conf folderIn that open “broker.conf” file and changeAUTHENTICATION_ENABLED = YESSave and exit the file.Google Pubsub use grpc authentication, so we must export the grpc ssl certificate path in the “/etc/environment” to set the default path for grpc ssl root certificate.Go to /etc folder and open “environment” file bysudo vim environmentIn that file, paste the below command and save it.export GRPC_DEFAULT_SSL_ROOTS_FILE_PATH=”usr/local/lib/python2.7/dist-packages/grpc/_cython/_credentials/roots.pem”Next restarted the instance.Once you restarted the instance, go to “Bevywise/MQTT Broker/bin” folderNext start the Bevywise MQTTBroker bysudo sh runbroker.shNow Bevywise MQTTBroker collects the data from your edge device and send to the Google pub/sub via Custom store. From Google Pub/Sub, you can hook and send the data to your data analytics tool. Get started your data analytics by downloading our MQTTbroker. Leave a Reply Cancel replyYour email address will not be published. Required fields are marked *CommentName * Email * Website Save my name, email, and website in this browser for the next time I comment.