<commit_before>= Google Cloud Reactive Pub/Sub Code Sample

This code sample demonstrates consuming data from a GCP Cloud Pub/Sub subscription as a reactive stream.

Acquiring and processing the reactive stream is done in link:src/main/java/com/example/ReactiveController.java/[ReactiveController.java].
Each message in the stream is acknowledged with `doOnNext()` operator.
Then the `map()` operator converts the message's payload into a proper `String` and returns it to the subscriber:

[source,java]
----
return flux
  .doOnNext(message -> {
    System.out.println("Received a message: " + message.getPubsubMessage().getMessageId());
    message.ack();
  })
  .map(message -> new String(
	  message.getPubsubMessage().getData().toByteArray(), Charset.defaultCharset()));
----

The other two classes (link:src/main/java/com/example/ReactiveReceiverApplication.java/[ReactiveReceiverApplication.java] and link:src/main/java/com/example/MessageSenderController.java/[MessageSenderController.java]) boostrap the application and simplify publishing test data to a topic.

== Setup & Configuration

image:http://gstatic.com/cloudssh/images/open-btn.svg[link=https://ssh.cloud.google.com/cloudshell/editor?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2FGoogleCloudPlatform%2Fspring-cloud-gcp&cloudshell_open_in_editor=spring-cloud-gcp-samples/spring-cloud-gcp-pubsub-reactive-sample/README.adoc]

1. Configure your GCP project ID and credentials by following link:../../docs/src/main/asciidoc/core.adoc#project-id[these instructions].
+
Alternatively, if you have the https://cloud.google.com/sdk/[Google Cloud SDK] installed and initialized, and are logged in with https://developers.google.com/identity/protocols/application-default-credentials[application default credentials], Spring will auto-discover those parameters for you.

2. Go to the https://console.cloud.google.com/cloudpubsub/topicList[Google Cloud Console Pub/Sub topics page] and create a topic called `exampleTopic`.

3. Still in the same page, locate the newly created topic, click the button with the three vertical dots at the end of the topic's line and click "New subscription".
Create a new subscription called `exampleSubscription` with all default parameters.

4. Run `$ mvn clean install` from the root directory of the project.

5. In a terminal window, move into this directory (`spring-cloud-gcp-samples/spring-cloud-gcp-pubsub-reactive-sample`) and run:

  mvn spring-boot:run

6. In a browser, open http://localhost:8080, or use the `Web Preview` button in Cloud Shell to preview the app on
port 8080, and send some (`N`) messages to the GCP Pub/Sub topic.
The messages sent will all start with the message text provided, and end with a number from `0` to `N-1`.
Observe that nothing is received by the sample application, since there are no subscribers yet.

7. In another terminal, open a connection to `/getmessages` streaming endpoint.
This stream will remain open until you stop it with `Ctrl+C`.

  curl localhost:8080/getmessages

8. Verify that the `curl` terminal received the messages, while the application itself logged their IDs.

9. Publish some more messages from http://localhost:8080 or from Cloud Shell `Web Preview`;
observe that the additional data is streamed to the `curl` client.<commit_msg>Update README.adoc (#1189)<commit_after>= Google Cloud Reactive Pub/Sub Code Sample

This code sample demonstrates consuming data from a GCP Cloud Pub/Sub subscription as a reactive stream.

Acquiring and processing the reactive stream is done in link:src/main/java/com/example/ReactiveController.java/[ReactiveController.java].
Each message in the stream is acknowledged with `doOnNext()` operator.
Then the `map()` operator converts the message's payload into a proper `String` and returns it to the subscriber:

[source,java]
----
return flux
  .doOnNext(message -> {
    System.out.println("Received a message: " + message.getPubsubMessage().getMessageId());
    message.ack();
  })
  .map(message -> new String(
	  message.getPubsubMessage().getData().toByteArray(), Charset.defaultCharset()));
----

The other two classes (link:src/main/java/com/example/ReactiveReceiverApplication.java/[ReactiveReceiverApplication.java] and link:src/main/java/com/example/MessageSenderController.java/[MessageSenderController.java]) boostrap the application and simplify publishing test data to a topic.

== Setup & Configuration

image:http://gstatic.com/cloudssh/images/open-btn.svg[link=https://ssh.cloud.google.com/cloudshell/editor?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2FGoogleCloudPlatform%2Fspring-cloud-gcp&cloudshell_open_in_editor=spring-cloud-gcp-samples/spring-cloud-gcp-pubsub-reactive-sample/README.adoc]

1. Configure your GCP project ID and credentials by following link:../../docs/src/main/asciidoc/core.adoc#project-id[these instructions].
+
Alternatively, if you have the https://cloud.google.com/sdk/[Google Cloud SDK] installed and initialized, and are logged in with https://developers.google.com/identity/protocols/application-default-credentials[application default credentials], Spring will auto-discover those parameters for you.

2. Go to the https://console.cloud.google.com/cloudpubsub/topicList[Google Cloud Console Pub/Sub topics page] and create a topic called `exampleTopic`.

3. Still in the same page, locate the newly created topic, click the button with the three vertical dots at the end of the topic's line and click "New subscription".
Create a new subscription called `exampleSubscription` with all default parameters.

4. Run `$ mvn clean install` from the root directory of the project.

5. In a terminal window, move into this directory (`spring-cloud-gcp-samples/spring-cloud-gcp-pubsub-reactive-sample`) and run:

  mvn spring-boot:run

6. In a browser, open http://localhost:8080, or use the `Web Preview` button in Cloud Shell to preview the app on
port 8080, and send some (`N`) messages to the GCP Pub/Sub topic.
The messages sent will all start with the message text provided, and end with a number from `0` to `N-1`.
Observe that nothing is received by the sample application, since there are no subscribers yet.

7. In another terminal, open a connection to `/getMessages` streaming endpoint.
This stream will remain open until you stop it with `Ctrl+C`.

  curl localhost:8080/getMessages

8. Verify that the `curl` terminal received the messages, while the application itself logged their IDs.

9. Publish some more messages from http://localhost:8080 or from Cloud Shell `Web Preview`;
observe that the additional data is streamed to the `curl` client.
{'fraction_non_alphanumeric': 0.09392516285411301, 'fraction_numerical': 0.010301469474322072, 'mean_word_length': 4.958483754512636, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3439090', 'n_tokens_mistral': 1864, 'n_tokens_neox': 1776, 'n_words': 695}