79 lines
38 KiB
HTML
79 lines
38 KiB
HTML
<html><head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
|
<title>5. Google Cloud Pub/Sub</title><link rel="stylesheet" type="text/css" href="css/manual-multipage.css"><meta name="generator" content="DocBook XSL Stylesheets V1.79.1"><link rel="home" href="multi_spring-cloud-gcp.html" title="Spring Cloud GCP Reference Documentation"><link rel="up" href="multi_spring-cloud-gcp.html" title="Spring Cloud GCP Reference Documentation"><link rel="prev" href="multi_spring-cloud-gcp-core.html" title="4. Spring Cloud GCP Core"><link rel="next" href="multi__spring_resources.html" title="6. Spring Resources"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">5. Google Cloud Pub/Sub</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="multi_spring-cloud-gcp-core.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="multi__spring_resources.html">Next</a></td></tr></table><hr></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="_google_cloud_pubsub" href="#_google_cloud_pubsub"></a>5. Google Cloud Pub/Sub</h1></div></div></div><p>Spring Cloud GCP provides an abstraction layer to publish to and subscribe from Google Cloud Pub/Sub topics and to create, list or delete Google Cloud Pub/Sub topics and subscriptions.</p><p>A Spring Boot starter is provided to auto-configure the various required Pub/Sub components.</p><p>Maven coordinates, using Spring Cloud GCP BOM:</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><dependency></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><groupId></span>org.springframework.cloud<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></groupId></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><artifactId></span>spring-cloud-gcp-starter-pubsub<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></artifactId></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></dependency></span></pre><p>Gradle coordinates:</p><pre class="screen">dependencies {
|
|
compile group: 'org.springframework.cloud', name: 'spring-cloud-gcp-starter-pubsub'
|
|
}</pre><p>This starter is also available from <a class="link" href="https://start.spring.io" target="_top">Spring Initializr</a> through the <code class="literal">GCP Messaging</code> entry.</p><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_pubsub_operations_template" href="#_pubsub_operations_template"></a>5.1 Pub/Sub Operations & Template</h2></div></div></div><p><code class="literal">PubSubOperations</code> is an abstraction that allows Spring users to use Google Cloud Pub/Sub without depending on any Google Cloud Pub/Sub API semantics.
|
|
It provides the common set of operations needed to interact with Google Cloud Pub/Sub.
|
|
<code class="literal">PubSubTemplate</code> is the default implementation of <code class="literal">PubSubOperations</code> and it uses the <a class="link" href="https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-pubsub" target="_top">Google Cloud Java Client for Pub/Sub</a> to interact with Google Cloud Pub/Sub.</p><p><code class="literal">PubSubTemplate</code> depends on a <code class="literal">PublisherFactory</code> and a <code class="literal">SubscriberFactory</code>.
|
|
The <code class="literal">PublisherFactory</code> provides a Google Cloud Java Client for Pub/Sub <code class="literal">Publisher</code>.
|
|
The <code class="literal">SubscriberFactory</code> provides the <code class="literal">Subscriber</code> for asynchronous message pulling, as well as a <code class="literal">SubscriberStub</code> for synchronous pulling.
|
|
The Spring Boot starter for GCP Pub/Sub auto-configures a <code class="literal">PublisherFactory</code> and <code class="literal">SubscriberFactory</code> with default settings and uses the <code class="literal">GcpProjectIdProvider</code> and <code class="literal">CredentialsProvider</code> auto-configured by the Spring Boot GCP starter.</p><p>The <code class="literal">PublisherFactory</code> implementation provided by Spring Cloud GCP Pub/Sub, <code class="literal">DefaultPublisherFactory</code>, caches <code class="literal">Publisher</code> instances by topic name, in order to optimize resource utilization.</p><p>The <code class="literal">PubSubOperations</code> interface is actually a combination of <code class="literal">PubSubPublisherOperations</code> and <code class="literal">PubSubSubscriberOperations</code> with the corresponding <code class="literal">PubSubPublisherTemplate</code> and <code class="literal">PubSubSubscriberTemplate</code> implementations, which can be used individually or via the composite <code class="literal">PubSubTemplate</code>.
|
|
The rest of the documentation refers to <code class="literal">PubSubTemplate</code>, but the same applies to <code class="literal">PubSubPublisherTemplate</code> and <code class="literal">PubSubSubscriberTemplate</code>, depending on whether we’re talking about publishing or subscribing.</p><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_publishing_to_a_topic" href="#_publishing_to_a_topic"></a>5.1.1 Publishing to a topic</h3></div></div></div><p><code class="literal">PubSubTemplate</code> provides asynchronous methods to publish messages to a Google Cloud Pub/Sub topic.
|
|
The <code class="literal">publish()</code> method takes in a topic name to post the message to, a payload of a generic type and, optionally, a map with the message headers.</p><p>Here is an example of how to publish a message to a Google Cloud Pub/Sub topic:</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">public</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">void</span> publishMessage() {
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">this</span>.pubSubTemplate.publish(<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"topic"</span>, <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"your message payload"</span>, ImmutableMap.of(<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"key1"</span>, <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"val1"</span>));
|
|
}</pre><p>By default, the <code class="literal">SimplePubSubMessageConverter</code> is used to convert payloads of type <code class="literal">byte[]</code>, <code class="literal">ByteString</code>, <code class="literal">ByteBuffer</code>, and <code class="literal">String</code> to Pub/Sub messages.</p><div class="section"><div class="titlepage"><div><div><h4 class="title"><a name="_json_support" href="#_json_support"></a>JSON support</h4></div></div></div><p>For serialization and deserialization of POJOs using Jackson JSON, configure a <code class="literal">JacksonPubSubMessageConverter</code> bean, and the Spring Boot starter for GCP Pub/Sub will automatically wire it into the <code class="literal">PubSubTemplate</code>.</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-comment">// Note: The ObjectMapper is used to convert Java POJOs to and from JSON. You will have to configure</span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-comment">// your own instance if you are unable to depend on the ObjectMapper provided by Spring Boot starters.</span>
|
|
<em><span class="hl-annotation" style="color: gray">@Bean</span></em>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">public</span> JacksonPubSubMessageConverter jacksonPubSubMessageConverter(ObjectMapper objectMapper) {
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">return</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">new</span> JacksonPubSubMessageConverter(objectMapper);
|
|
}</pre><p>Alternatively, you can set it directly by calling the <code class="literal">setMessageConverter()</code> method on the <code class="literal">PubSubTemplate</code>.
|
|
Other implementations of the <code class="literal">PubSubMessageConverter</code> can also be configured in the same manner.</p><p>Please refer to our <a class="link" href="../spring-cloud-gcp-samples/spring-cloud-gcp-integration-pubsub-json-sample" target="_top">Pub/Sub JSON Payload Sample App</a> as a reference for using this functionality.</p></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_subscribing_to_a_subscription" href="#_subscribing_to_a_subscription"></a>5.1.2 Subscribing to a subscription</h3></div></div></div><p>Google Cloud Pub/Sub allows many subscriptions to be associated to the same topic.
|
|
<code class="literal">PubSubTemplate</code> allows you to listen to subscriptions via the <code class="literal">subscribe()</code> method.
|
|
It relies on a <code class="literal">SubscriberFactory</code> object, whose only task is to generate Google Cloud Pub/Sub
|
|
<code class="literal">Subscriber</code> objects.
|
|
When listening to a subscription, messages will be pulled from Google Cloud Pub/Sub
|
|
asynchronously, at a certain interval.</p><p>The Spring Boot starter for Google Cloud Pub/Sub auto-configures a <code class="literal">SubscriberFactory</code>.</p><p>If Pub/Sub message payload conversion is desired, you can use the <code class="literal">subscribeAndConvert()</code> method, which will use the converter configured in the template.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_pulling_messages_from_a_subscription" href="#_pulling_messages_from_a_subscription"></a>5.1.3 Pulling messages from a subscription</h3></div></div></div><p>Google Cloud Pub/Sub supports synchronous pulling of messages from a subscription.
|
|
This is different from subscribing to a subscription, in the sense that subscribing is an asynchronous task which polls the subscription on a set interval.</p><p>The <code class="literal">pullNext()</code> method allows for a single message to be pulled and automatically acknowledged from a subscription.
|
|
The <code class="literal">pull()</code> method pulls a number of messages from a subscription, allowing for the retry settings to be configured.
|
|
Any messages received by <code class="literal">pull()</code> are not automatically acknowledged.
|
|
Instead, since they are of the kind <code class="literal">AcknowledgeablePubsubMessage</code>, you can acknowledge them by calling the <code class="literal">ack()</code> method, or negatively acknowledge them by calling the <code class="literal">nack()</code> method.
|
|
The <code class="literal">pullAndAck()</code> method does the same as the <code class="literal">pull()</code> method and, additionally, acknowledges all received messages.</p><p>The <code class="literal">pullAndConvert()</code> method does the same as the <code class="literal">pull()</code> method and, additionally, converts the Pub/Sub binary payload to an object of the desired type, using the converter configured in the template.</p><p>To acknowledge multiple messages received from <code class="literal">pull()</code> or <code class="literal">pullAndConvert()</code> at once, you can use the <code class="literal">PubSubTemplate.ack()</code> method.
|
|
You can also use the <code class="literal">PubSubTemplate.nack()</code> for negatively acknowledging messages.</p><p>Using these methods for acknowledging messages in batches is more efficient than acknowledging messages individually, but they <span class="strong"><strong>require</strong></span> the collection of messages to be from the same project.</p><p>All <code class="literal">ack()</code>, <code class="literal">nack()</code>, and <code class="literal">modifyAckDeadline()</code> methods on messages as well as <code class="literal">PubSubSubscriberTemplate</code> are implemented asynchronously, returning a <code class="literal">ListenableFuture<Void></code> to be able to process the asynchronous execution.</p><p><code class="literal">PubSubTemplate</code> uses a special subscriber generated by its <code class="literal">SubscriberFactory</code> to synchronously pull messages.</p></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_pubsub_management" href="#_pubsub_management"></a>5.2 Pub/Sub management</h2></div></div></div><p><code class="literal">PubSubAdmin</code> is the abstraction provided by Spring Cloud GCP to manage Google Cloud Pub/Sub resources.
|
|
It allows for the creation, deletion and listing of topics and subscriptions.</p><p><code class="literal">PubSubAdmin</code> depends on <code class="literal">GcpProjectIdProvider</code> and either a <code class="literal">CredentialsProvider</code> or a <code class="literal">TopicAdminClient</code> and a <code class="literal">SubscriptionAdminClient</code>.
|
|
If given a <code class="literal">CredentialsProvider</code>, it creates a <code class="literal">TopicAdminClient</code> and a <code class="literal">SubscriptionAdminClient</code> with the Google Cloud Java Library for Pub/Sub default settings.
|
|
The Spring Boot starter for GCP Pub/Sub auto-configures a <code class="literal">PubSubAdmin</code> object using the <code class="literal">GcpProjectIdProvider</code> and the <code class="literal">CredentialsProvider</code> auto-configured by the Spring Boot GCP Core starter.</p><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_creating_a_topic" href="#_creating_a_topic"></a>5.2.1 Creating a topic</h3></div></div></div><p><code class="literal">PubSubAdmin</code> implements a method to create topics:</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">public</span> Topic createTopic(String topicName)</pre><p>Here is an example of how to create a Google Cloud Pub/Sub topic:</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">public</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">void</span> newTopic() {
|
|
pubSubAdmin.createTopic(<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"topicName"</span>);
|
|
}</pre></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_deleting_a_topic" href="#_deleting_a_topic"></a>5.2.2 Deleting a topic</h3></div></div></div><p><code class="literal">PubSubAdmin</code> implements a method to delete topics:</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">public</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">void</span> deleteTopic(String topicName)</pre><p>Here is an example of how to delete a Google Cloud Pub/Sub topic:</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">public</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">void</span> deleteTopic() {
|
|
pubSubAdmin.deleteTopic(<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"topicName"</span>);
|
|
}</pre></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_listing_topics" href="#_listing_topics"></a>5.2.3 Listing topics</h3></div></div></div><p><code class="literal">PubSubAdmin</code> implements a method to list topics:</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">public</span> List<Topic> listTopics</pre><p>Here is an example of how to list every Google Cloud Pub/Sub topic name in a project:</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">public</span> List<String> listTopics() {
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">return</span> pubSubAdmin
|
|
.listTopics()
|
|
.stream()
|
|
.map(Topic::getNameAsTopicName)
|
|
.map(TopicName::getTopic)
|
|
.collect(Collectors.toList());
|
|
}</pre></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_creating_a_subscription" href="#_creating_a_subscription"></a>5.2.4 Creating a subscription</h3></div></div></div><p><code class="literal">PubSubAdmin</code> implements a method to create subscriptions to existing topics:</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">public</span> Subscription createSubscription(String subscriptionName, String topicName, Integer ackDeadline, String pushEndpoint)</pre><p>Here is an example of how to create a Google Cloud Pub/Sub subscription:</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">public</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">void</span> newSubscription() {
|
|
pubSubAdmin.createSubscription(<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"subscriptionName"</span>, <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"topicName"</span>, <span class="hl-number">10</span>, “http:<span xmlns:d="http://docbook.org/ns/docbook" class="hl-comment">//my.endpoint/push”);</span>
|
|
}</pre><p>Alternative methods with default settings are provided for ease of use.
|
|
The default value for <code class="literal">ackDeadline</code> is 10 seconds.
|
|
If <code class="literal">pushEndpoint</code> isn’t specified, the subscription uses message pulling, instead.</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">public</span> Subscription createSubscription(String subscriptionName, String topicName)</pre><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">public</span> Subscription createSubscription(String subscriptionName, String topicName, Integer ackDeadline)</pre><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">public</span> Subscription createSubscription(String subscriptionName, String topicName, String pushEndpoint)</pre></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_deleting_a_subscription" href="#_deleting_a_subscription"></a>5.2.5 Deleting a subscription</h3></div></div></div><p><code class="literal">PubSubAdmin</code> implements a method to delete subscriptions:</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">public</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">void</span> deleteSubscription(String subscriptionName)</pre><p>Here is an example of how to delete a Google Cloud Pub/Sub subscription:</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">public</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">void</span> deleteSubscription() {
|
|
pubSubAdmin.deleteSubscription(<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"subscriptionName"</span>);
|
|
}</pre></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_listing_subscriptions" href="#_listing_subscriptions"></a>5.2.6 Listing subscriptions</h3></div></div></div><p><code class="literal">PubSubAdmin</code> implements a method to list subscriptions:</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">public</span> List<Subscription> listSubscriptions()</pre><p>Here is an example of how to list every subscription name in a project:</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">public</span> List<String> listSubscriptions() {
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">return</span> pubSubAdmin
|
|
.listSubscriptions()
|
|
.stream()
|
|
.map(Subscription::getNameAsSubscriptionName)
|
|
.map(SubscriptionName::getSubscription)
|
|
.collect(Collectors.toList());
|
|
}</pre></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="pubsub-configuration" href="#pubsub-configuration"></a>5.3 Configuration</h2></div></div></div><p>The Spring Boot starter for Google Cloud Pub/Sub provides the following configuration options:</p><div class="informaltable"><table class="informaltable" style="border-collapse: collapse;border-top: 1px solid ; border-bottom: 1px solid ; border-left: 1px solid ; border-right: 1px solid ; "><colgroup><col class="col_1"><col class="col_2"><col class="col_3"><col class="col_4"></colgroup><tbody><tr><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p>Name</p></td><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p>Description</p></td><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p>Required</p></td><td style="border-bottom: 1px solid ; " align="left" valign="top"><p>Default value</p></td></tr><tr><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p><code class="literal">spring.cloud.gcp.pubsub.enabled</code></p></td><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p>Enables or disables Pub/Sub auto-configuration</p></td><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p>No</p></td><td style="border-bottom: 1px solid ; " align="left" valign="top"><p><code class="literal">true</code></p></td></tr><tr><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p><code class="literal">spring.cloud.gcp.pubsub.subscriber.executor-threads</code></p></td><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p>Number of threads used by <code class="literal">Subscriber</code>
|
|
instances created by <code class="literal">SubscriberFactory</code></p></td><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p>No</p></td><td style="border-bottom: 1px solid ; " align="left" valign="top"><p>4</p></td></tr><tr><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p><code class="literal">spring.cloud.gcp.pubsub.publisher.executor-threads</code></p></td><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p>Number of threads used by <code class="literal">Publisher</code>
|
|
instances created by <code class="literal">PublisherFactory</code></p></td><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p>No</p></td><td style="border-bottom: 1px solid ; " align="left" valign="top"><p>4</p></td></tr><tr><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p><code class="literal">spring.cloud.gcp.pubsub.project-id</code></p></td><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p>GCP project ID where the Google Cloud Pub/Sub API
|
|
is hosted, if different from the one in the <a class="link" href="multi_spring-cloud-gcp-core.html" title="4. Spring Cloud GCP Core">Spring Cloud GCP Core Module</a></p></td><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p>No</p></td><td style="border-bottom: 1px solid ; " align="left" valign="top"> </td></tr><tr><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p><code class="literal">spring.cloud.gcp.pubsub.credentials.location</code></p></td><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p>OAuth2 credentials for authenticating with the
|
|
Google Cloud Pub/Sub API, if different from the ones in the
|
|
<a class="link" href="multi_spring-cloud-gcp-core.html" title="4. Spring Cloud GCP Core">Spring Cloud GCP Core Module</a></p></td><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p>No</p></td><td style="border-bottom: 1px solid ; " align="left" valign="top"> </td></tr><tr><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p><code class="literal">spring.cloud.gcp.pubsub.credentials.encoded-key</code></p></td><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p>Base64-encoded contents of OAuth2 account private key for authenticating with the
|
|
Google Cloud Pub/Sub API, if different from the ones in the
|
|
<a class="link" href="multi_spring-cloud-gcp-core.html" title="4. Spring Cloud GCP Core">Spring Cloud GCP Core Module</a></p></td><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p>No</p></td><td style="border-bottom: 1px solid ; " align="left" valign="top"> </td></tr><tr><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p><code class="literal">spring.cloud.gcp.pubsub.credentials.scopes</code></p></td><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p><a class="link" href="https://developers.google.com/identity/protocols/googlescopes" target="_top">OAuth2 scope</a> for Spring Cloud GCP
|
|
Pub/Sub credentials</p></td><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p>No</p></td><td style="border-bottom: 1px solid ; " align="left" valign="top"><p><a class="link" href="https://www.googleapis.com/auth/pubsub" target="_top">https://www.googleapis.com/auth/pubsub</a></p></td></tr><tr><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p><code class="literal">spring.cloud.gcp.pubsub.subscriber.parallel-pull-count</code></p></td><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p>The number of pull workers</p></td><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p>No</p></td><td style="border-bottom: 1px solid ; " align="left" valign="top"><p>The available number of processors</p></td></tr><tr><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p><code class="literal">spring.cloud.gcp.pubsub.subscriber.max-ack-extension-period</code></p></td><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p>The maximum period a message ack deadline will be extended, in seconds</p></td><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p>No</p></td><td style="border-bottom: 1px solid ; " align="left" valign="top"><p>0</p></td></tr><tr><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p><code class="literal">spring.cloud.gcp.pubsub.subscriber.pull-endpoint</code></p></td><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p>The endpoint for synchronous pulling messages</p></td><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p>No</p></td><td style="border-bottom: 1px solid ; " align="left" valign="top"><p>pubsub.googleapis.com:443</p></td></tr><tr><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p><code class="literal">spring.cloud.gcp.pubsub.[subscriber,publisher].retry.total-timeout-seconds</code></p></td><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p>TotalTimeout has ultimate control over how long the logic should keep trying the remote call until it gives up completely.
|
|
The higher the total timeout, the more retries can be attempted.</p></td><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p>No</p></td><td style="border-bottom: 1px solid ; " align="left" valign="top"><p>0</p></td></tr><tr><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p><code class="literal">spring.cloud.gcp.pubsub.[subscriber,publisher].retry.initial-retry-delay-second</code></p></td><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p>InitialRetryDelay controls the delay before the first retry. Subsequent retries will use this
|
|
value adjusted according to the RetryDelayMultiplier.</p></td><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p>No</p></td><td style="border-bottom: 1px solid ; " align="left" valign="top"><p>0</p></td></tr><tr><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p><code class="literal">spring.cloud.gcp.pubsub.[subscriber,publisher].retry.retry-delay-multiplier</code></p></td><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p>RetryDelayMultiplier controls the change in retry delay. The retry delay of the previous call
|
|
is multiplied by the RetryDelayMultiplier to calculate the retry delay for the next call.</p></td><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p>No</p></td><td style="border-bottom: 1px solid ; " align="left" valign="top"><p>1</p></td></tr><tr><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p><code class="literal">spring.cloud.gcp.pubsub.[subscriber,publisher].retry.max-retry-delay-seconds</code></p></td><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p>MaxRetryDelay puts a limit on the value of the retry delay, so that the RetryDelayMultiplier
|
|
can’t increase the retry delay higher than this amount.</p></td><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p>No</p></td><td style="border-bottom: 1px solid ; " align="left" valign="top"><p>0</p></td></tr><tr><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p><code class="literal">spring.cloud.gcp.pubsub.[subscriber,publisher].retry.max-attempts</code></p></td><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p>MaxAttempts defines the maximum number of attempts to perform.
|
|
If this value is greater than 0, and the number of attempts reaches this limit, the logic will
|
|
give up retrying even if the total retry time is still lower than TotalTimeout.</p></td><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p>No</p></td><td style="border-bottom: 1px solid ; " align="left" valign="top"><p>0</p></td></tr><tr><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p><code class="literal">spring.cloud.gcp.pubsub.[subscriber,publisher].retry.jittered</code></p></td><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p>Jitter determines if the delay time should be randomized.</p></td><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p>No</p></td><td style="border-bottom: 1px solid ; " align="left" valign="top"><p>true</p></td></tr><tr><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p><code class="literal">spring.cloud.gcp.pubsub.[subscriber,publisher].retry.initial-rpc-timeout-seconds</code></p></td><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p>InitialRpcTimeout controls the timeout for the initial RPC. Subsequent calls will use this
|
|
value adjusted according to the RpcTimeoutMultiplier.</p></td><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p>No</p></td><td style="border-bottom: 1px solid ; " align="left" valign="top"><p>0</p></td></tr><tr><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p><code class="literal">spring.cloud.gcp.pubsub.[subscriber,publisher].retry.rpc-timeout-multiplier</code></p></td><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p>RpcTimeoutMultiplier controls the change in RPC timeout. The timeout of the previous call is
|
|
multiplied by the RpcTimeoutMultiplier to calculate the timeout for the next call.</p></td><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p>No</p></td><td style="border-bottom: 1px solid ; " align="left" valign="top"><p>1</p></td></tr><tr><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p><code class="literal">spring.cloud.gcp.pubsub.[subscriber,publisher].retry.max-rpc-timeout-seconds</code></p></td><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p>MaxRpcTimeout puts a limit on the value of the RPC timeout, so that the RpcTimeoutMultiplier
|
|
can’t increase the RPC timeout higher than this amount.</p></td><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p>No</p></td><td style="border-bottom: 1px solid ; " align="left" valign="top"><p>0</p></td></tr><tr><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p><code class="literal">spring.cloud.gcp.pubsub.[subscriber,publisher.batching].flow-control.max-outstanding-element-count</code></p></td><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p>Maximum number of outstanding elements to keep in memory before enforcing flow control.</p></td><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p>No</p></td><td style="border-bottom: 1px solid ; " align="left" valign="top"><p>unlimited</p></td></tr><tr><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p><code class="literal">spring.cloud.gcp.pubsub.[subscriber,publisher.batching].flow-control.max-outstanding-request-bytes</code></p></td><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p>Maximum number of outstanding bytes to keep in memory before enforcing flow control.</p></td><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p>No</p></td><td style="border-bottom: 1px solid ; " align="left" valign="top"><p>unlimited</p></td></tr><tr><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p><code class="literal">spring.cloud.gcp.pubsub.[subscriber,publisher.batching].flow-control.limit-exceeded-behavior</code></p></td><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p>The behavior when the specified limits are exceeded.</p></td><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p>No</p></td><td style="border-bottom: 1px solid ; " align="left" valign="top"><p>Block</p></td></tr><tr><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p><code class="literal">spring.cloud.gcp.pubsub.publisher.batching.element-count-threshold</code></p></td><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p>The element count threshold to use for batching.</p></td><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p>No</p></td><td style="border-bottom: 1px solid ; " align="left" valign="top"><p>unset (threshold does not apply)</p></td></tr><tr><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p><code class="literal">spring.cloud.gcp.pubsub.publisher.batching.request-byte-threshold</code></p></td><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p>The request byte threshold to use for batching.</p></td><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p>No</p></td><td style="border-bottom: 1px solid ; " align="left" valign="top"><p>unset (threshold does not apply)</p></td></tr><tr><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p><code class="literal">spring.cloud.gcp.pubsub.publisher.batching.delay-threshold-seconds</code></p></td><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p>The delay threshold to use for batching. After this amount of time has elapsed (counting
|
|
from the first element added), the elements will be wrapped up in a batch and sent.</p></td><td style="border-right: 1px solid ; border-bottom: 1px solid ; " align="left" valign="top"><p>No</p></td><td style="border-bottom: 1px solid ; " align="left" valign="top"><p>unset (threshold does not apply)</p></td></tr><tr><td style="border-right: 1px solid ; " align="left" valign="top"><p><code class="literal">spring.cloud.gcp.pubsub.publisher.batching.enabled</code></p></td><td style="border-right: 1px solid ; " align="left" valign="top"><p>Enables batching.</p></td><td style="border-right: 1px solid ; " align="left" valign="top"><p>No</p></td><td style="" align="left" valign="top"><p>false</p></td></tr></tbody></table></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_sample" href="#_sample"></a>5.4 Sample</h2></div></div></div><p>A <a class="link" href="https://github.com/spring-cloud/spring-cloud-gcp/tree/master/spring-cloud-gcp-samples/spring-cloud-gcp-pubsub-sample" target="_top">sample application</a> is available.</p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="multi_spring-cloud-gcp-core.html">Prev</a> </td><td width="20%" align="center"> </td><td width="40%" align="right"> <a accesskey="n" href="multi__spring_resources.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">4. Spring Cloud GCP Core </td><td width="20%" align="center"><a accesskey="h" href="multi_spring-cloud-gcp.html">Home</a></td><td width="40%" align="right" valign="top"> 6. Spring Resources</td></tr></table></div></body></html> |