Skip to content

Latest commit

 

History

History
 
 

pubsub

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Google Cloud Pub/Sub Kotlin Sample

Open in Cloud Shell

Description

Google Cloud Pub/Sub is a fully-managed real-time messaging service that allows you to send and receive messages between independent applications. This simple Kotlin command-line application demonstrates how to access the Pub/Sub API using the Google Cloud Client Library for Java.

Quickstart

Setup

Build

  • Clone the repository
    git clone https://github.com/GoogleCloudPlatform/kotlin-samples
    cd kotlin-samples/pubsub
  • Build the project with Gradle Wrapper:
    # run with "-info" flag to print potential errors
    ./gradlew build -info

You should now have a 'pubsub.jar' file under build/libs/

Create a new topic

java -jar build/libs/pubsub.jar create <topic>

Create a subscription

java -jar build/libs/pubsub.jar sub <topic> <subscription>

Publish messages

java -jar build/libs/pubsub.jar pub <topic> <count>

Receive messages

java -jar build/libs/pubsub.jar listen <subscription>

Subscriber will continue to listen on the topic for 5 minutes and print out message id and data as messages are received.

Delete a topic

java -jar build/libs/pubsub.jar del-topic <topic>

Delete a subscription

java -jar build/libs/pubsub.jar del-sub <subscription>

Testing

Run the test with Gradle Wrapper

./gradlew test

Contributing changes

Licensing