Files
spring-cloud-static/Greenwich.SR4/multi/multi__spring_cloud_stream_2.html
2019-11-19 16:34:05 +01:00

21 lines
8.8 KiB
HTML

<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>157.&nbsp;Spring Cloud Stream</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.html" title="Spring Cloud"><link rel="up" href="multi_spring-cloud-gcp-reference.html" title="Part&nbsp;XVIII.&nbsp;Spring Cloud GCP"><link rel="prev" href="multi__spring_integration.html" title="156.&nbsp;Spring Integration"><link rel="next" href="multi__spring_cloud_sleuth_2.html" title="158.&nbsp;Spring Cloud Sleuth"></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">157.&nbsp;Spring Cloud Stream</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="multi__spring_integration.html">Prev</a>&nbsp;</td><th width="60%" align="center">Part&nbsp;XVIII.&nbsp;Spring Cloud GCP</th><td width="20%" align="right">&nbsp;<a accesskey="n" href="multi__spring_cloud_sleuth_2.html">Next</a></td></tr></table><hr></div><div class="chapter"><div class="titlepage"><div><div><h2 class="title"><a name="_spring_cloud_stream_2" href="#_spring_cloud_stream_2"></a>157.&nbsp;Spring Cloud Stream</h2></div></div></div><p>Spring Cloud GCP provides a <a class="link" href="https://cloud.spring.io/spring-cloud-stream/" target="_top">Spring Cloud Stream</a> binder to Google Cloud Pub/Sub.</p><p>The provided binder relies on the <a class="link" href="https://github.com/spring-cloud/spring-cloud-gcp/tree/master/spring-cloud-gcp-pubsub/src/main/java/org/springframework/cloud/gcp/pubsub/integration" target="_top">Spring Integration Channel Adapters for Google Cloud Pub/Sub</a>.</p><p>Maven coordinates, using Spring Cloud GCP BOM:</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag">&lt;dependency&gt;</span>
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag">&lt;groupId&gt;</span>org.springframework.cloud<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag">&lt;/groupId&gt;</span>
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag">&lt;artifactId&gt;</span>spring-cloud-gcp-pubsub-stream-binder<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag">&lt;/artifactId&gt;</span>
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag">&lt;/dependency&gt;</span></pre><p>Gradle coordinates:</p><pre class="screen">dependencies {
compile group: 'org.springframework.cloud', name: 'spring-cloud-gcp-pubsub-stream-binder'
}</pre><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_overview_2" href="#_overview_2"></a>157.1&nbsp;Overview</h2></div></div></div><p>This binder binds producers to Google Cloud Pub/Sub topics and consumers to subscriptions.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note"><tr><td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="images/note.png"></td><th align="left">Note</th></tr><tr><td align="left" valign="top"><p>Partitioning is currently not supported by this binder.</p></td></tr></table></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_configuration_4" href="#_configuration_4"></a>157.2&nbsp;Configuration</h2></div></div></div><p>You can configure the Spring Cloud Stream Binder for Google Cloud Pub/Sub to automatically generate the underlying resources, like the Google Cloud Pub/Sub topics and subscriptions for producers and consumers.
For that, you can use the <code class="literal">spring.cloud.stream.gcp.pubsub.bindings.&lt;channelName&gt;.&lt;consumer|producer&gt;.auto-create-resources</code> property, which is turned ON by default.</p><p>Starting with version 1.1, these and other binder properties can be configured globally for all the bindings, e.g. <code class="literal">spring.cloud.stream.gcp.pubsub.default.consumer.auto-create-resources</code>.</p><p>If you are using Pub/Sub auto-configuration from the Spring Cloud GCP Pub/Sub Starter, you should refer to the <a class="link" href="multi__google_cloud_pubsub.html#pubsub-configuration" title="153.3&nbsp;Configuration">configuration</a> section for other Pub/Sub parameters.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note"><tr><td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="images/note.png"></td><th align="left">Note</th></tr><tr><td align="left" valign="top"><p>To use this binder with a <a class="link" href="https://cloud.google.com/pubsub/docs/emulator" target="_top">running emulator</a>, configure its host and port via <code class="literal">spring.cloud.gcp.pubsub.emulator-host</code>.</p></td></tr></table></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_producer_destination_configuration" href="#_producer_destination_configuration"></a>157.2.1&nbsp;Producer Destination Configuration</h3></div></div></div><p>If automatic resource creation is turned ON and the topic corresponding to the destination name does not exist, it will be created.</p><p>For example, for the following configuration, a topic called <code class="literal">myEvents</code> would be created.</p><p><b>application.properties.&nbsp;</b>
</p><pre class="screen">spring.cloud.stream.bindings.events.destination=myEvents
spring.cloud.stream.gcp.pubsub.bindings.events.producer.auto-create-resources=true</pre><p>
</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_consumer_destination_configuration" href="#_consumer_destination_configuration"></a>157.2.2&nbsp;Consumer Destination Configuration</h3></div></div></div><p>If automatic resource creation is turned ON and the subscription and/or the topic do not exist for a consumer, a subscription and potentially a topic will be created.
The topic name will be the same as the destination name, and the subscription name will be the destination name followed by the consumer group name.</p><p>Regardless of the <code class="literal">auto-create-resources</code> setting, if the consumer group is not specified, an anonymous one will be created with the name <code class="literal">anonymous.&lt;destinationName&gt;.&lt;randomUUID&gt;</code>.
Then when the binder shuts down, all Pub/Sub subscriptions created for anonymous consumer groups will be automatically cleaned up.</p><p>For example, for the following configuration, a topic named <code class="literal">myEvents</code> and a subscription called <code class="literal">myEvents.counsumerGroup1</code> would be created.
If the consumer group is not specified, a subscription called <code class="literal">anonymous.myEvents.a6d83782-c5a3-4861-ac38-e6e2af15a7be</code> would be created and later cleaned up.</p><div class="important" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Important"><tr><td rowspan="2" align="center" valign="top" width="25"><img alt="[Important]" src="images/important.png"></td><th align="left">Important</th></tr><tr><td align="left" valign="top"><p>If you are manually creating Pub/Sub subscriptions for consumers, make sure that they follow the naming convention of <code class="literal">&lt;destinationName&gt;.&lt;consumerGroup&gt;</code>.</p></td></tr></table></div><p><b>application.properties.&nbsp;</b>
</p><pre class="screen">spring.cloud.stream.bindings.events.destination=myEvents
spring.cloud.stream.gcp.pubsub.bindings.events.consumer.auto-create-resources=true
# specify consumer group, and avoid anonymous consumer group generation
spring.cloud.stream.bindings.events.group=consumerGroup1</pre><p>
</p></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_sample_5" href="#_sample_5"></a>157.3&nbsp;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-binder-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_integration.html">Prev</a>&nbsp;</td><td width="20%" align="center"><a accesskey="u" href="multi_spring-cloud-gcp-reference.html">Up</a></td><td width="40%" align="right">&nbsp;<a accesskey="n" href="multi__spring_cloud_sleuth_2.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">156.&nbsp;Spring Integration&nbsp;</td><td width="20%" align="center"><a accesskey="h" href="multi_spring-cloud.html">Home</a></td><td width="40%" align="right" valign="top">&nbsp;158.&nbsp;Spring Cloud Sleuth</td></tr></table></div></body></html>