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-kotlin-sample-all.jar' file under build/libs/

Create a new topic

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

Create a subscription

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

Publish messages

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

Receive messages

java -jar build/libs/pubsub-kotlin-sample-all.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-kotlin-sample-all.jar del-topic <topic>

Delete a subscription

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

Testing

Run the test with Gradle Wrapper

./gradlew test

Contributing changes

Licensing