GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — java-docs-samples/iot/api-client/mqtt_example at master · abdul-git/java-docs-samples

Expand file tree

/

mqtt_example

/
Copy path

Directory actions

More options

More options

Directory actions

More options

More options

Latest commit

 

History

History
History
 
 
/

mqtt_example

/
Copy path

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
src/main/java/com/google/cloud/iot/examples
src/main/java/com/google/cloud/iot/examples
 
 
README.md
README.md
 
 
pom.xml
pom.xml
 
 

README.md

Outline

Cloud IoT Core Java MQTT example

This sample app publishes data to Cloud Pub/Sub using the MQTT bridge provided as part of Google Cloud IoT Core.

Note that before you can run the sample, you must configure a Google Cloud PubSub topic for Cloud IoT Core and register a device as described in the parent README.

Setup

Run the following command to install the dependencies using Maven:

mvn clean compile

Running the sample

The following command summarizes the sample usage:

mvn exec:java \
    -Dexec.mainClass="com.google.cloud.iot.examples.MqttExample" \
    -Dexec.args="-project_id=my-iot-project \
                 -registry_id=my-registry \
                 -device_id=my-device \
                 -private_key_file=rsa_private_pkcs8 \
                 -algorithm=RS256"

For example, if your project ID is blue-jet-123, your service account credentials are stored in your home folder in creds.json and you have generated your credentials using the generate_keys.sh script provided in the parent folder, you can run the sample as:

mvn exec:java \
    -Dexec.mainClass="com.google.cloud.iot.examples.MqttExample" \
    -Dexec.args="-project_id=blue-jet-123 \
                 -registry_id=my-registry \
                 -device_id=my-device \
                 -private_key_file=../rsa_private_pkcs8 \
                 -algorithm=RS256"

Reading the messages written by the sample client

  1. Create a subscription to your topic.

    gcloud beta pubsub subscriptions create
    projects/your-project-id/subscriptions/my-subscription
    --topic device-events

  2. Read messages published to the topic

    gcloud beta pubsub subscriptions pull --auto-ack
    projects/my-iot-project/subscriptions/my-subscription

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.