Choreography in Google Cloud
1. Choreography in Google Cloud
Now that you understand the basics of service choreography and orchestration, we will discuss how you can choreograph services in Google Cloud. Pub/Sub is one of the services on Google Cloud that can be used to choreograph services. Pub/Sub is a fully managed real-time messaging service that lets you send and receive messages between independent services or applications. A publisher sends a message to a Pub/Sub topic. This publisher is often a custom-built application, but it could also be a Google service. The message is stored within Pub/Sub... ...and then delivered to the message queue for each subscriber for the topic. Each Pub/Sub subscriber then receives the message. A subscriber with a pull subscription would occasionally poll for messages that have been sent to the topic. A push subscription would cause the message to be automatically sent to a configured endpoint for the subscription. The subscriber would then acknowledge the message. Acknowledging a message removes it from the queue. The deletion of the queued message follows handling of the message, which guarantees that a message will be handled at least once. Here's an example of using Pub/Sub to connect services and build an application. This diagram shows an image resizing application. A Pub/Sub topic is created for image uploads. A specific Cloud Storage bucket is configured to send a Pub/Sub message to that topic when a new image is received. When the mobile device application uploads a new image to the Image Uploads bucket, a Pub/Sub message is automatically sent to Pub/Sub. This message is then forwarded to the two subscribers, the Resizing Service and the Upload Confirm application. The Upload Confirm application updates Firestore, storing the fact that the image upload completed successfully. The Resizing Service resizes the image, storing it in the Resized Images bucket and also updating Firestore with the status. The application can track status updates in Firestore using Firebase Realtime Database updates. Each of the Cloud Run services can remain fairly simple, with Pub/Sub initiating processing when there's an image to act upon. Eventarc is Google Cloud's fully managed eventing system that makes building event-driven applications easy. Eventarc supports many Google Cloud products as event sources. For some Google Cloud services, the source can directly send events to Eventarc. For Google services or event types that do not support direct access, Eventarc can seamlessly use Cloud Audit Logs entries to generate events. Third-party providers can also utilize the Eventarc API to create events. Applications don't need to write code to parse audit logs or poll for events. Pub/Sub messages to specified topics may also be used as event sources. This integration allows custom applications to send events. An event trigger is a rule-based filter to route specific event types from a particular event source to specified event consumers, or targets. Eventarc uses Pub/Sub as its transport layer due to its superior reliability and observability. Eventarc automatically creates and manages Pub/Sub topics and subscriptions to facilitate event delivery. Your applications only need to accept HTTP requests that are automatically sent by Eventarc. Applications do not need to use Pub/Sub directly. Events are delivered to targets using the standard CNCF CloudEvents format, regardless of event source. Whenever you create a trigger, you can see the format and fields that will be used for that specific event. The CloudEvents format used by Eventarc specifies a common metadata format for describing event data, providing interoperability across services, platforms, and systems. Publishers of events historically tended to use their own formats for their events. By standardizing on a specific format, CloudEvents allows developers to use the same event handling logic in their code regardless of the source or type of the event. CloudEvents provides SDKs for many of the common programming languages in use today, like Python, JavaScript, Java, Go, C#, Ruby, and PHP. Developers can use these SDKs to easily parse incoming events, increasing code portability and developer productivity. Eventarc is an abstraction layer on top of Pub/Sub that provides some significant benefits when designing an event-driven application. Eventarc can use many built-in services as a source for events. Eventarc makes it easy to detect changes within many Google Cloud services and third-party applications, and automatically trigger code to run in response to those changes. Eventarc provides a simple, rule-based interface to select the source, filter, and destination of a trigger. With Pub/Sub, you must write code to ingest events and manage topics and subscriptions. Finally, you should use Eventarc when you want a standardized event format. By using the standard CloudEvents format, you can use CloudEvent SDKs to create and consume events.2. Let's practice!
Create Your Free Account
or
By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.