### Start Server and Client Applications Source: https://github.com/googlecloudplatform/spring-cloud-gcp/blob/main/spring-cloud-gcp-samples/spring-cloud-gcp-pubsub-bus-config-sample/README.adoc Commands to start the Spring Cloud GCP Pub/Sub Bus Config Server and Client applications using Maven. ```bash cd spring-cloud-gcp-samples/spring-cloud-gcp-pubsub-bus-config-sample mvn spring-boot:run -f spring-cloud-gcp-pubsub-bus-config-sample-server-github ``` ```bash cd spring-cloud-gcp-samples/spring-cloud-gcp-pubsub-bus-config-sample mvn spring-boot:run -f spring-cloud-gcp-pubsub-bus-config-sample-client ``` -------------------------------- ### OCR Dependencies Setup Source: https://github.com/googlecloudplatform/spring-cloud-gcp/blob/main/docs/src/main/asciidoc/vision.adoc If applying OCR on documents, include both vision and storage starters. ```APIDOC ==== Cloud Vision OCR Dependencies If you are interested in applying optical character recognition (OCR) on documents for your project, you'll need to add both `spring-cloud-gcp-starter-vision` and `spring-cloud-gcp-starter-storage` to your dependencies. The storage starter is necessary because the Cloud Vision API will process your documents and write OCR output files all within your Google Cloud Storage buckets. Maven coordinates using <>: [source,xml] ---- com.google.cloud spring-cloud-gcp-starter-vision com.google.cloud spring-cloud-gcp-starter-storage ---- Gradle coordinates: [source] ---- dependencies { implementation("com.google.cloud:spring-cloud-gcp-starter-vision") implementation("com.google.cloud:spring-cloud-gcp-starter-storage") } ---- ``` -------------------------------- ### Query by Example with Fluent Query Chaining Source: https://github.com/googlecloudplatform/spring-cloud-gcp/blob/main/docs/src/main/asciidoc/datastore.adoc Chain query specifications using a fluent API after defining an example. This allows for complex queries with sorting and limiting results. ```java userRepository.findBy( Example.of(new User(null, null, "Smith")), q -> q.sortBy(Sort.by("firstName")).firstValue()); userRepository.findBy( Example.of(new User(null, null, "Smith")), FetchableFluentQuery::stream); ``` -------------------------------- ### Start Client Application Source: https://github.com/googlecloudplatform/spring-cloud-gcp/blob/main/spring-cloud-gcp-samples/spring-cloud-gcp-pubsub-bus-config-sample/README.adoc Run the Spring Cloud client application using Maven. This client will subscribe to configuration changes. ```bash cd spring-cloud-gcp-samples/spring-cloud-gcp-pubsub-bus-config-sample mvn spring-boot:run -pl spring-cloud-gcp-pubsub-bus-config-sample-client ``` -------------------------------- ### Maven Dependency Setup Source: https://github.com/googlecloudplatform/spring-cloud-gcp/blob/main/docs/src/main/asciidoc/vision.adoc Add the spring-cloud-gcp-starter-vision artifact to your project using Maven. ```APIDOC ## Maven Dependency Setup Maven coordinates, using <>: [source,xml] ---- com.google.cloud spring-cloud-gcp-starter-vision ---- ``` -------------------------------- ### DatastoreOperations Transaction Example Source: https://github.com/googlecloudplatform/spring-cloud-gcp/blob/main/docs/src/main/asciidoc/datastore.adoc Provides an example of performing a transaction using DatastoreOperations.performTransaction, which accepts a function to execute within the transaction context. ```java @Autowired DatastoreOperations myDatastoreOperations; public String doWorkInsideTransaction() { return myDatastoreOperations.performTransaction( transactionDatastoreOperations -> { // Work with transactionDatastoreOperations here. // It is also a DatastoreOperations object. return "transaction completed"; } ); } ``` -------------------------------- ### Gradle Dependency Setup Source: https://github.com/googlecloudplatform/spring-cloud-gcp/blob/main/docs/src/main/asciidoc/vision.adoc Add the spring-cloud-gcp-starter-vision artifact to your project using Gradle. ```APIDOC ## Gradle Dependency Setup Gradle coordinates: [source] ---- dependencies { implementation("com.google.cloud:spring-cloud-gcp-starter-vision") } ---- ``` -------------------------------- ### Reactive Stream Subscriber Setup (Java) Source: https://github.com/googlecloudplatform/spring-cloud-gcp/blob/main/docs/src/main/asciidoc/pubsub.adoc Acquire a reactive stream backed by a Pub/Sub subscription using PubSubReactiveFactory. Requires Project Reactor dependency. ```java @Autowired PubSubReactiveFactory reactiveFactory; // ... Flux = reactiveFactory.poll("exampleSubscription", 1000); ``` -------------------------------- ### DatastoreTemplate Usage Example Source: https://github.com/googlecloudplatform/spring-cloud-gcp/blob/main/docs/src/main/asciidoc/datastore.adoc Demonstrates basic usage of DatastoreTemplate for deleting all entities, saving a new entity, and retrieving all entities of a specific type. ```java @SpringBootApplication public class DatastoreTemplateExample { @Autowired DatastoreTemplate datastoreTemplate; public void doSomething() { this.datastoreTemplate.deleteAll(Trader.class); //... Trader t = new Trader(); //... this.datastoreTemplate.save(t); //... List traders = datastoreTemplate.findAll(Trader.class); //... } } ``` -------------------------------- ### Start Configuration Server (Local) Source: https://github.com/googlecloudplatform/spring-cloud-gcp/blob/main/spring-cloud-gcp-samples/spring-cloud-gcp-pubsub-bus-config-sample/README.adoc Run the Spring Cloud Config server locally using Maven. This server will read configurations from the local filesystem. ```bash cd spring-cloud-gcp-samples/spring-cloud-gcp-pubsub-bus-config-sample mvn spring-boot:run -pl spring-cloud-gcp-pubsub-bus-config-sample-server-local ``` -------------------------------- ### Example JSON Data for Upload Source: https://github.com/googlecloudplatform/spring-cloud-gcp/blob/main/spring-cloud-gcp-samples/spring-cloud-gcp-bigquery-sample/src/main/resources/templates/upload-json.html This is an example of newline-delimited JSON rows that can be uploaded directly. ```json {"CompanyName":"TALES","Description":"mark","SerialNumber":97,"Leave":0,"EmpName":"Mark"} {"CompanyName":"1Q84","Description":"ark","SerialNumber":978,"Leave":0,"EmpName":"HARUKI"} {"CompanyName":"MY","Description":"M","SerialNumber":9780,"Leave":0,"EmpName":"Mark"} ``` -------------------------------- ### Curl Command Example Source: https://github.com/googlecloudplatform/spring-cloud-gcp/blob/main/spring-cloud-gcp-samples/spring-cloud-gcp-security-firebase-sample/src/main/resources/static/index.html Example curl command to test the /answer endpoint with an Authorization header. This demonstrates how to make authenticated requests from the command line. ```bash curl -H "Authorization: Bearer " http://localhost:8080/answer ``` -------------------------------- ### Run All Project Tests Source: https://github.com/googlecloudplatform/spring-cloud-gcp/blob/main/CONTRIBUTING.md Execute all tests for the project using the Maven wrapper. Ensure Java 17 or later is installed. ```bash ./mvnw clean test ``` -------------------------------- ### DatastoreTemplate Find by ID Examples Source: https://github.com/googlecloudplatform/spring-cloud-gcp/blob/main/docs/src/main/asciidoc/datastore.adoc Shows how to find single or multiple entities by their IDs, and how to retrieve all entities of a given Kind using DatastoreTemplate. ```java Trader trader = this.datastoreTemplate.findById("trader1", Trader.class); ``` ```java List traders = this.datastoreTemplate.findAllById(Arrays.asList("trader1", "trader2"), Trader.class); ``` ```java List allTraders = this.datastoreTemplate.findAll(Trader.class); ``` -------------------------------- ### Example Application Output Source: https://github.com/googlecloudplatform/spring-cloud-gcp/blob/main/spring-cloud-gcp-samples/spring-cloud-gcp-data-multi-sample/README.adoc This output indicates that both Cloud Spanner and Cloud Datastore are being utilized by the application. It shows the state of entities after deletion and saving operations. ```text Deleting all entities. The number of Person entities is now: 0 The number of Trader entities is now: 0 Saving one entity with each repository. The number of Person entities is now: 1 The number of Trader entities is now: 1 ``` -------------------------------- ### Run Sender and Receiver Applications Source: https://github.com/googlecloudplatform/spring-cloud-gcp/blob/main/spring-cloud-gcp-samples/spring-cloud-gcp-integration-pubsub-sample/README.adoc Start the sender and receiver applications using Maven. Ensure you have configured your Google Cloud project and created the Pub/Sub topic and subscription. ```bash $ mvn spring-boot:run ``` -------------------------------- ### Create Runtime Configuration using gcloud CLI Source: https://github.com/googlecloudplatform/spring-cloud-gcp/blob/main/docs/src/main/asciidoc/config.adoc Use the gcloud CLI to initialize your Google Cloud project and create a runtime configuration. This example creates a configuration named 'myapp_prod' and sets a variable 'myapp.queue-size'. ```bash gcloud init # if this is your first Google Cloud SDK run. gcloud beta runtime-config configs create myapp_prod gcloud beta runtime-config configs variables set myapp.queue-size 25 --config-name myapp_prod ``` -------------------------------- ### Configure Stackdriver JSON Layout for Logback Source: https://github.com/googlecloudplatform/spring-cloud-gcp/blob/main/docs/src/main/asciidoc/logging.adoc This Logback configuration example demonstrates how to set up the StackdriverJsonLayout, including setting the project ID and various options for trace and span ID inclusion. Use this for more granular control over log output. ```xml ${projectId}