b06-01-Cloud-PubSub-HelloWorld

In this article I will show you how to publish and receive messages in PubSub with Java

  1. create topic

    1
    gcloud pubsub topics create my-topic
  2. create subscription to this topic

    1
    gcloud pubsub subscriptions create my-sub --topic my-topic
  3. git clone project into cloud shell

    1
    git clone https://github.com/googleapis/java-pubsub.git
  4. go into the sample

    1
    cd samples/snippets/
  5. modify PublisherExample.java and SubscribeAsyncExample.java to put the right project id, topic id and subscription id

  6. compile project

    1
    mvn clean install -DskipTests
  7. run subscriber

    1
    mvn exec:java -Dexec.mainClass="pubsub.SubscribeAsyncExample"
  8. run publisher in another screen and observe subscriber

    1
    mvn exec:java -Dexec.mainClass="pubsub.PublisherExample"