This sample shows how to create a service that processes Pub/Sub messages.
For more details on how to work with this sample read the Google Cloud Run Java Samples README.
- Spring Boot: Web server framework.
- Jib: Container build tool.
- Junit + SpringBootTest: [development] Test running framework.
- MockMVC: [development] Integration testing support framework.
Create a Cloud Pub/Sub topic:
gcloud pubsub topics create my-topicUse the Jib Maven Plugin to build and push your container image:
mvn jib:build -Dimage gcr.io/$(gcloud config get-value project)/cloudrun-events-pubsubDeploy your Cloud Run service:
gcloud run deploy cloudrun-events-pubsub \
--image gcr.io/$(gcloud config get-value project)/cloudrun-events-pubsubCreate a Cloud Pub/Sub trigger:
gcloud alpha events triggers create pubsub-trigger \
--target-service cloudrun-events-pubsub \
--type com.google.cloud.pubsub.topic.publish \
--parameters topic=my-topicTest your Cloud Run service by publishing a message to the topic:
gcloud pubsub topics publish my-topic --message="Hello there"You may observe the Run service receiving an event in Cloud Logging.