Spring Cloud GCP

repository·main·Indexed 19 days ago

https://github.com/googlecloudplatform/spring-cloud-gcp

Spring Cloud GCP integrations for securing Spring applications with Identity-Aware Proxy (IAP) and providing starters for Google Cloud services. Includes support and configuration for AlloyDB, BigQuery, Datastore, Firestore, Pub/Sub, Spanner, and Cloud SQL, as well as a generator for creating Spring Boot Starters for Google Client Libraries.

Tokens
85.2K
Snippets
256
Records
333
Agent score
68%

What's inside spring-cloud-gcp

  1. Overview of Spring Cloud Bus Configuration Management Demo

    main

    This sample demonstrates automated configuration management using Spring Cloud Config, Spring Cloud Bus, and Spring Cloud GCP Pub/Sub.

    Architecture

    • Configuration Server: Runs on port 8888. It reads configuration from a local filesystem (using the native profile) or a Git repository. When it detects changes (via manual updates or the /monitor endpoint), it broadcasts a RefreshRemoteApplicationEvent via Spring Cloud Bus.
    • Client Application: Subscribes to the configuration server and listens for refresh events via Pub/Sub. It provides an HTTP endpoint /message to display dynamically updated property values.
    • Spring Cloud Bus: Uses a Spring Cloud Stream binder for Cloud Pub/Sub to communicate between the server and clients. By default, it uses a topic named springCloudBus.
  2. Overview of Spring Framework on Google Cloud

    main

    Spring Framework on Google Cloud provides integration between the Spring ecosystem and Google Cloud services. It simplifies running Spring applications on Google Cloud by providing auto-configuration, Spring Boot starters, and specialized modules for various GCP services.

    Key supported services include:

    • Pub/Sub: Messaging support including Spring Integration Channel Adapters and Stream Binder.
    • Storage: Spring Resource Abstraction for Google Cloud Storage.
    • Data Services: Spring Data support for Cloud Spanner, Cloud Datastore, and Cloud Firestore.
    • Vision: Google Cloud Vision API Template.
    • Security: Firebase Authentication and Google Cloud IAP Authentication.
    • Infrastructure: Google Cloud Config, Cloud Logging, Secret Manager, and Cloud SQL (MySQL/PostgreSQL).
  3. Overview of Cloud Spanner Spring Data R2DBC

    main

    The Spring Data R2DBC Dialect for Cloud Spanner enables reactive data access to Cloud Spanner using the Spring Data R2DBC framework.

    Key features provided by this integration include:

    • Spring Configuration Support: Use Java-based @Configuration classes.
    • Annotation-based Mapping: Define metadata for entity mapping via annotations.
    • Automatic Repository Implementation: Automatically implement Spring Data Repository interfaces.
    • Reactive Transactions: Support for non-blocking reactive transactions.
    • Schema/Data Utilities: Utilities for schema and data initialization.

    For general Spring Data R2DBC concepts, refer to the official Spring Data R2DBC documentation.

  4. Overview of Spring Framework on Google Cloud capabilities

    main

    Spring Framework on Google Cloud integrates Google Cloud services into the Spring ecosystem, allowing you to use standard Spring abstractions to interact with Google Cloud resources. Key capabilities include:

    • Messaging: Publish and subscribe to Google Cloud Pub/Sub topics; use Spring Integration with Google Cloud Pub/Sub; use Spring Cloud Bus with Pub/Sub.
    • Databases & Storage: Use Spring JDBC with Google Cloud SQL; use Spring Data for Cloud Spanner, Cloud Datastore, and Cloud Firestore (including Reactive Repositories); use Spring Resources backed by Google Cloud Storage; consume/produce GCS data via Spring Integration adapters.
    • Observability: Trace application execution with Micrometer and Google Cloud Trace; use Micrometer for metrics.
    • Security & Configuration: Use Spring Security via Google Cloud IAP; configure applications using Spring Cloud Config backed by Google Cloud Runtime Configuration API.
    • AI & Specialized Services: Analyze images with Google Cloud Vision; manage secrets with Secret Manager; use Cloud KMS; use AlloyDB and Memorystore.
  5. Overview of the Spring Framework on Google Cloud Kotlin Sample App

    main

    This sample application is a Kotlin Spring Boot project that demonstrates how to integrate Spring Framework on Google Cloud libraries within a Kotlin environment. It implements a registration service where registrant names are published to a Cloud Pub/Sub topic and subsequently persisted to a Cloud SQL database.

    Key integrations demonstrated include:

    • Cloud Pub/Sub using Spring Integration.
    • Cloud SQL using Spring Data JPA.
  6. Use Pub/Sub Dead Letter Topics with Spring Cloud Stream

    main

    This sample demonstrates how to configure the Spring Cloud Stream binder for Google Cloud Pub/Sub to use Dead Letter Topics (DLT).

    When a message is received by a sink and nack()ed (negative acknowledgment), Pub/Sub attempts redelivery up to a maximum number of retries. Once the retry limit is reached, the message is automatically routed to a configured dead letter topic. This sample includes a listener that monitors the dead letter topic and logs any messages received there.

    If the topics for the sink, source, or dead letter topic are not already present, the binder will automatically create them in Google Cloud Pub/Sub based on the configuration in application.properties.

  7. Explore Spring Framework on Google Cloud Code Samples

    main

    The spring-cloud-gcp-samples directory contains various code examples demonstrating how to integrate Spring Framework with different Google Cloud services. These samples cover configuration, data access, messaging, storage, logging, and observability.

    Available Samples

    • Config: Uses Spring Cloud Config with the Google Runtime Configuration API.
    • Data JPA: Uses Spring Data JPA with Google Cloud SQL.
    • Cloud Spanner (Repository): Uses Spring Data Cloud Spanner Repository.
    • Cloud Spanner (Template): Uses Spring Data Cloud Spanner Template.
    • Pub/Sub (Integration): Uses Spring Integration channel adapters for Google Cloud Pub/Sub.
    • Pub/Sub (Abstraction): Uses the Spring Framework on Google Cloud Pub/Sub abstraction.
    • Pub/Sub (Stream): Uses the Spring Cloud Stream Binder for Google Cloud Pub/Sub.
    • Storage (Integration): Uses Spring Integration channel adapters to synchronize files to Google Cloud Storage.
    • Storage (Resource): Uses the Spring Resource abstraction to read/write files to Google Cloud Storage.
    • Logging: Uses the Stackdriver Logging API to group logs by trace ID.
    • Trace: Uses Micrometer to generate trace IDs and store data in Google Cloud Trace.
    • Cloud SQL (MySQL/PostgreSQL): Demonstrates best practices for connecting to Google Cloud SQL instances.
    • Vision API: Demonstrates improved usability of Google Cloud Client Libraries within Spring.
  8. Use Spring Data JPA with Cloud SQL (MySQL or PostgreSQL)

    main

    This sample demonstrates how to integrate Spring Data JPA with Google Cloud SQL using either the MySQL or PostgreSQL starter. The Spring Framework on Google Cloud SQL starter automatically configures a JdbcTemplate, which is then used by Spring Data JPA to manage database connections and operations.

    To use MySQL, include the spring-cloud-gcp-starter-sql-mysql dependency. To use PostgreSQL, include the spring-cloud-gcp-starter-sql-postgresql dependency.

  9. Connect to Cloud SQL PostgreSQL using Spring Framework on Google Cloud

    main
    This sample demonstrates how to connect a Spring Boot application to a Google Cloud SQL PostgreSQL instance using the spring-cloud-gcp-starter-sql-postgresql starter. The application automatically handles the connection logic, populates the database using schema.sql and data.sql, and provides an endpoint to query the data.
  10. Use the Spring Cloud Stream binder for Google Cloud Pub/Sub

    main

    This sample demonstrates how to use the Spring Cloud Stream binder to integrate Spring applications with Google Cloud Pub/Sub using a functional programming model. It consists of two components:

    1. Source Application: Collects user input (name and message) via a web form, wraps it in a UserMessage object with a timestamp, and publishes it to a Pub/Sub topic.
    2. Sink Application: Subscribes to the topic and logs the received messages.

    Key Behaviors:

    • Automatic Topic Creation: If the configured topic does not exist, the binder automatically creates it in Google Cloud Pub/Sub.
    • Subscription Management:
      • If a group is specified in the sink's application.properties, the sink uses a named subscription (e.g., my-topic.my-group). This allows for load balancing multiple subscribers reading from the same subscription.
      • If no group is specified, an anonymous subscription is generated with the pattern anonymous.<topicName>.<randomUUID>. These anonymous subscriptions are automatically cleaned up when the application shuts down.
  11. Use Cloud Spanner and Cloud Datastore in a single Spring application

    main
    This sample demonstrates how to integrate both spring-cloud-gcp-starter-data-spanner and spring-cloud-gcp-starter-data-datastore within a single Spring Boot application. It specifically showcases how to manage multiple data modules and use transactions across both Cloud Spanner and Cloud Datastore simultaneously.