Topic 1 Question 64
You want to deploy an application on Cloud Run that processes messages from a Cloud Pub/Sub topic. You want to follow Google-recommended practices. What should you do?
- Create a Cloud Function that uses a Cloud Pub/Sub trigger on that topic. 2. Call your application on Cloud Run from the Cloud Function for every message.
- Grant the Pub/Sub Subscriber role to the service account used by Cloud Run. 2. Create a Cloud Pub/Sub subscription for that topic. 3. Make your application pull messages from that subscription.
- Create a service account. 2. Give the Cloud Run Invoker role to that service account for your Cloud Run application. 3. Create a Cloud Pub/Sub subscription that uses that service account and uses your Cloud Run application as the push endpoint.
- Deploy your application on Cloud Run on GKE with the connectivity set to Internal. 2. Create a Cloud Pub/Sub subscription for that topic. 3. In the same Google Kubernetes Engine cluster as your application, deploy a container that takes the messages and sends them to your application.
ユーザの投票
コメント(17)
C looks right for me as per https://cloud.google.com/run/docs/tutorials/pubsub#integrating-pubsub
👍 49Meix2020/06/05why c ? explained>> You can use Pub/Sub to push messages to the endpoint of your Cloud Run service, where the messages are subsequently delivered to containers as HTTP requests. You cannot use Pub/Sub pull subscriptions because Cloud Run only allocates CPU during the processing of a request.
👍 34Bhagirathi2020/12/19Ans is C (push subscription).
I think B (pull subscription) can work, but it does not follow best practices. With pull subscription, you cannot take advantage of scale-to-zero for Cloud Run. Why is this the case? Because you need to keep your subscriber client (Cloud Run in option B) running, otherwise you don't know if there are new messages. (Whereas if you use push subscription instead, you can scale to zero and rest assured that Cloud Run will be "notified" of new messages).
See 3:15 and 4:10 of this video: https://www.youtube.com/watch?v=KObJkda4ZfY
Remember this: Push subscription -> Pub/Sub server initiates a request to your subscriber client to deliver messages Pull subscription -> Your subscriber client initiates requests to a Pub/Sub server to retrieve messages
Documentation: https://cloud.google.com/pubsub/docs/subscriber
👍 4Pho_King2022/11/30
シャッフルモード