113 lines
25 KiB
HTML
113 lines
25 KiB
HTML
<html><head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
|
<title>156. Spring Integration</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 XVIII. Spring Cloud GCP"><link rel="prev" href="multi__spring_jdbc.html" title="155. Spring JDBC"><link rel="next" href="multi__spring_cloud_stream_2.html" title="157. Spring Cloud Stream"></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">156. Spring Integration</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="multi__spring_jdbc.html">Prev</a> </td><th width="60%" align="center">Part XVIII. Spring Cloud GCP</th><td width="20%" align="right"> <a accesskey="n" href="multi__spring_cloud_stream_2.html">Next</a></td></tr></table><hr></div><div class="chapter"><div class="titlepage"><div><div><h2 class="title"><a name="_spring_integration" href="#_spring_integration"></a>156. Spring Integration</h2></div></div></div><p>Spring Cloud GCP provides Spring Integration adapters that allow your applications to use Enterprise Integration Patterns backed up by Google Cloud Platform services.</p><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_channel_adapters_for_cloud_pubsub" href="#_channel_adapters_for_cloud_pubsub"></a>156.1 Channel Adapters for Cloud Pub/Sub</h2></div></div></div><p>The channel adapters for Google Cloud Pub/Sub connect your Spring <a class="link" href="https://docs.spring.io/spring-integration/reference/html/messaging-channels-section.html#channel" target="_top"><code class="literal">MessageChannels</code></a> to Google Cloud Pub/Sub topics and subscriptions.
|
|
This enables messaging between different processes, applications or micro-services backed up by Google Cloud Pub/Sub.</p><p>The Spring Integration Channel Adapters for Google Cloud Pub/Sub are included in the <code class="literal">spring-cloud-gcp-pubsub</code> module.</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-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>
|
|
<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.integration<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-integration-core<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-pubsub'
|
|
compile group: 'org.springframework.integration', name: 'spring-integration-core'
|
|
}</pre><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_inbound_channel_adapter" href="#_inbound_channel_adapter"></a>156.1.1 Inbound channel adapter</h3></div></div></div><p><code class="literal">PubSubInboundChannelAdapter</code> is the inbound channel adapter for GCP Pub/Sub that listens to a GCP Pub/Sub subscription for new messages.
|
|
It converts new messages to an internal Spring <a class="link" href="https://docs.spring.io/spring-integration/reference/html/messaging-construction-chapter.html#message" target="_top"><code class="literal">Message</code></a> and then sends it to the bound output channel.</p><p>Google Pub/Sub treats message payloads as byte arrays.
|
|
So, by default, the inbound channel adapter will construct the Spring <code class="literal">Message</code> with <code class="literal">byte[]</code> as the payload.
|
|
However, you can change the desired payload type by setting the <code class="literal">payloadType</code> property of the <code class="literal">PubSubInboundChannelAdapter</code>.
|
|
The <code class="literal">PubSubInboundChannelAdapter</code> delegates the conversion to the desired payload type to the <code class="literal">PubSubMessageConverter</code> configured in the <code class="literal">PubSubTemplate</code>.</p><p>To use the inbound channel adapter, a <code class="literal">PubSubInboundChannelAdapter</code> must be provided and configured on the user application side.</p><pre class="programlisting"><em><span class="hl-annotation" style="color: gray">@Bean</span></em>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">public</span> MessageChannel pubsubInputChannel() {
|
|
<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> PublishSubscribeChannel();
|
|
}
|
|
|
|
<em><span class="hl-annotation" style="color: gray">@Bean</span></em>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">public</span> PubSubInboundChannelAdapter messageChannelAdapter(
|
|
<em><span class="hl-annotation" style="color: gray">@Qualifier("pubsubInputChannel")</span></em> MessageChannel inputChannel,
|
|
SubscriberFactory subscriberFactory) {
|
|
PubSubInboundChannelAdapter adapter =
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">new</span> PubSubInboundChannelAdapter(subscriberFactory, <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"subscriptionName"</span>);
|
|
adapter.setOutputChannel(inputChannel);
|
|
adapter.setAckMode(AckMode.MANUAL);
|
|
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">return</span> adapter;
|
|
}</pre><p>In the example, we first specify the <code class="literal">MessageChannel</code> where the adapter is going to write incoming messages to.
|
|
The <code class="literal">MessageChannel</code> implementation isn’t important here.
|
|
Depending on your use case, you might want to use a <code class="literal">MessageChannel</code> other than <code class="literal">PublishSubscribeChannel</code>.</p><p>Then, we declare a <code class="literal">PubSubInboundChannelAdapter</code> bean.
|
|
It requires the channel we just created and a <code class="literal">SubscriberFactory</code>, which creates <code class="literal">Subscriber</code> objects from the Google Cloud Java Client for Pub/Sub.
|
|
The Spring Boot starter for GCP Pub/Sub provides a configured <code class="literal">SubscriberFactory</code>.</p><p>The <code class="literal">PubSubInboundChannelAdapter</code> supports three acknowledgement modes, with <code class="literal">AckMode.AUTO</code> being the default value;</p><p>Automatic acking (<code class="literal">AckMode.AUTO</code>)</p><p>A message is acked with GCP Pub/Sub if the adapter sent it to the channel and no exceptions were thrown.
|
|
If a <code class="literal">RuntimeException</code> is thrown while the message is processed, then the message is nacked.</p><p>Automatic acking OK (<code class="literal">AckMode.AUTO_ACK</code>)</p><p>A message is acked with GCP Pub/Sub if the adapter sent it to the channel and no exceptions were thrown.
|
|
If a <code class="literal">RuntimeException</code> is thrown while the message is processed, then the message is neither acked / nor nacked.</p><p>This is useful when using the subscription’s ack deadline timeout as a retry delivery backoff mechanism.</p><p>Manually acking (<code class="literal">AckMode.MANUAL</code>)</p><p>The adapter attaches a <code class="literal">BasicAcknowledgeablePubsubMessage</code> object to the <code class="literal">Message</code> headers.
|
|
Users can extract the <code class="literal">BasicAcknowledgeablePubsubMessage</code> using the <code class="literal">GcpPubSubHeaders.ORIGINAL_MESSAGE</code> key and use it to (n)ack a message.</p><pre class="programlisting"><em><span class="hl-annotation" style="color: gray">@Bean</span></em>
|
|
<em><span class="hl-annotation" style="color: gray">@ServiceActivator(inputChannel = "pubsubInputChannel")</span></em>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">public</span> MessageHandler messageReceiver() {
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">return</span> message -> {
|
|
LOGGER.info(<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"Message arrived! Payload: "</span> + <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">new</span> String((<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">byte</span>[]) message.getPayload()));
|
|
BasicAcknowledgeablePubsubMessage originalMessage =
|
|
message.getHeaders().get(GcpPubSubHeaders.ORIGINAL_MESSAGE, BasicAcknowledgeablePubsubMessage.<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">class</span>);
|
|
originalMessage.ack();
|
|
};
|
|
}</pre></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_outbound_channel_adapter" href="#_outbound_channel_adapter"></a>156.1.2 Outbound channel adapter</h3></div></div></div><p><code class="literal">PubSubMessageHandler</code> is the outbound channel adapter for GCP Pub/Sub that listens for new messages on a Spring <code class="literal">MessageChannel</code>.
|
|
It uses <code class="literal">PubSubTemplate</code> to post them to a GCP Pub/Sub topic.</p><p>To construct a Pub/Sub representation of the message, the outbound channel adapter needs to convert the Spring <code class="literal">Message</code> payload to a byte array representation expected by Pub/Sub.
|
|
It delegates this conversion to the <code class="literal">PubSubTemplate</code>.
|
|
To customize the conversion, you can specify a <code class="literal">PubSubMessageConverter</code> in the <code class="literal">PubSubTemplate</code> that should convert the <code class="literal">Object</code> payload and headers of the Spring <code class="literal">Message</code> to a <code class="literal">PubsubMessage</code>.</p><p>To use the outbound channel adapter, a <code class="literal">PubSubMessageHandler</code> bean must be provided and configured on the user application side.</p><pre class="programlisting"><em><span class="hl-annotation" style="color: gray">@Bean</span></em>
|
|
<em><span class="hl-annotation" style="color: gray">@ServiceActivator(inputChannel = "pubsubOutputChannel")</span></em>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">public</span> MessageHandler messageSender(PubSubTemplate pubsubTemplate) {
|
|
<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> PubSubMessageHandler(pubsubTemplate, <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"topicName"</span>);
|
|
}</pre><p>The provided <code class="literal">PubSubTemplate</code> contains all the necessary configuration to publish messages to a GCP Pub/Sub topic.</p><p><code class="literal">PubSubMessageHandler</code> publishes messages asynchronously by default.
|
|
A publish timeout can be configured for synchronous publishing.
|
|
If none is provided, the adapter waits indefinitely for a response.</p><p>It is possible to set user-defined callbacks for the <code class="literal">publish()</code> call in <code class="literal">PubSubMessageHandler</code> through the <code class="literal">setPublishFutureCallback()</code> method.
|
|
These are useful to process the message ID, in case of success, or the error if any was thrown.</p><p>To override the default destination you can use the <code class="literal">GcpPubSubHeaders.DESTINATION</code> header.</p><pre class="programlisting"><em><span class="hl-annotation" style="color: gray">@Autowired</span></em>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">private</span> MessageChannel pubsubOutputChannel;
|
|
|
|
<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> handleMessage(Message<?> msg) <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">throws</span> MessagingException {
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">final</span> Message<?> message = MessageBuilder
|
|
.withPayload(msg.getPayload())
|
|
.setHeader(GcpPubSubHeaders.TOPIC, <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"customTopic"</span>).build();
|
|
pubsubOutputChannel.send(message);
|
|
}</pre><p>It is also possible to set an SpEL expression for the topic with the <code class="literal">setTopicExpression()</code> or <code class="literal">setTopicExpressionString()</code> methods.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_header_mapping" href="#_header_mapping"></a>156.1.3 Header mapping</h3></div></div></div><p>These channel adapters contain header mappers that allow you to map, or filter out, headers from Spring to Google Cloud Pub/Sub messages, and vice-versa.
|
|
By default, the inbound channel adapter maps every header on the Google Cloud Pub/Sub messages to the Spring messages produced by the adapter.
|
|
The outbound channel adapter maps every header from Spring messages into Google Cloud Pub/Sub ones, except the ones added by Spring, like headers with key <code class="literal">"id"</code>, <code class="literal">"timestamp"</code> and <code class="literal">"gcp_pubsub_acknowledgement"</code>.
|
|
In the process, the outbound mapper also converts the value of the headers into string.</p><p>Each adapter declares a <code class="literal">setHeaderMapper()</code> method to let you further customize which headers you want to map from Spring to Google Cloud Pub/Sub, and vice-versa.</p><p>For example, to filter out headers <code class="literal">"foo"</code>, <code class="literal">"bar"</code> and all headers starting with the prefix "prefix_", you can use <code class="literal">setHeaderMapper()</code> along with the <code class="literal">PubSubHeaderMapper</code> implementation provided by this module.</p><pre class="programlisting">PubSubMessageHandler adapter = ...
|
|
...
|
|
PubSubHeaderMapper headerMapper = <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">new</span> PubSubHeaderMapper();
|
|
headerMapper.setOutboundHeaderPatterns(<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"!foo"</span>, <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"!bar"</span>, <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"!prefix_*"</span>, <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"*"</span>);
|
|
adapter.setHeaderMapper(headerMapper);</pre><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>The order in which the patterns are declared in <code class="literal">PubSubHeaderMapper.setOutboundHeaderPatterns()</code> and <code class="literal">PubSubHeaderMapper.setInboundHeaderPatterns()</code> matters.
|
|
The first patterns have precedence over the following ones.</p></td></tr></table></div><p>In the previous example, the <code class="literal">"*"</code> pattern means every header is mapped.
|
|
However, because it comes last in the list, <a class="link" href="https://docs.spring.io/spring-integration/api/org/springframework/integration/util/PatternMatchUtils.html#smartMatch-java.lang.String-java.lang.String%E2%80%A6%E2%80%8B-" target="_top">the previous patterns take precedence</a>.</p></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_sample_3" href="#_sample_3"></a>156.2 Sample</h2></div></div></div><p>Available examples:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><a class="link" href="https://github.com/spring-cloud/spring-cloud-gcp/tree/master/spring-cloud-gcp-samples/spring-cloud-gcp-integration-pubsub-sample" target="_top">sender and receiver sample application</a></li><li class="listitem"><a class="link" href="https://github.com/spring-cloud/spring-cloud-gcp/tree/master/spring-cloud-gcp-samples/spring-cloud-gcp-integration-pubsub-json-sample" target="_top">JSON payloads sample application</a></li><li class="listitem"><a class="link" href="https://codelabs.developers.google.com/codelabs/cloud-spring-cloud-gcp-pubsub-integration/index.html" target="_top">codelab</a></li></ul></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_channel_adapters_for_google_cloud_storage" href="#_channel_adapters_for_google_cloud_storage"></a>156.3 Channel Adapters for Google Cloud Storage</h2></div></div></div><p>The channel adapters for Google Cloud Storage allow you to read and write files to Google Cloud Storage through <code class="literal">MessageChannels</code>.</p><p>Spring Cloud GCP provides two inbound adapters, <code class="literal">GcsInboundFileSynchronizingMessageSource</code> and <code class="literal">GcsStreamingMessageSource</code>, and one outbound adapter, <code class="literal">GcsMessageHandler</code>.</p><p>The Spring Integration Channel Adapters for Google Cloud Storage are included in the <code class="literal">spring-cloud-gcp-storage</code> module.</p><p>To use the Storage portion of Spring Integration for Spring Cloud GCP, you must also provide the <code class="literal">spring-integration-file</code> dependency, since it isn’t pulled transitively.</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-storage<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>
|
|
<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.integration<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-integration-file<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-storage'
|
|
compile group: 'org.springframework.integration', name: 'spring-integration-file'
|
|
}</pre><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_inbound_channel_adapter_2" href="#_inbound_channel_adapter_2"></a>156.3.1 Inbound channel adapter</h3></div></div></div><p>The Google Cloud Storage inbound channel adapter polls a Google Cloud Storage bucket for new files and sends each of them in a <code class="literal">Message</code> payload to the <code class="literal">MessageChannel</code> specified in the <code class="literal">@InboundChannelAdapter</code> annotation.
|
|
The files are temporarily stored in a folder in the local file system.</p><p>Here is an example of how to configure a Google Cloud Storage inbound channel adapter.</p><pre class="programlisting"><em><span class="hl-annotation" style="color: gray">@Bean</span></em>
|
|
<em><span class="hl-annotation" style="color: gray">@InboundChannelAdapter(channel = "new-file-channel", poller = @Poller(fixedDelay = "5000"))</span></em>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">public</span> MessageSource<File> synchronizerAdapter(Storage gcs) {
|
|
GcsInboundFileSynchronizer synchronizer = <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">new</span> GcsInboundFileSynchronizer(gcs);
|
|
synchronizer.setRemoteDirectory(<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"your-gcs-bucket"</span>);
|
|
|
|
GcsInboundFileSynchronizingMessageSource synchAdapter =
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">new</span> GcsInboundFileSynchronizingMessageSource(synchronizer);
|
|
synchAdapter.setLocalDirectory(<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">new</span> File(<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"local-directory"</span>));
|
|
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">return</span> synchAdapter;
|
|
}</pre></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_inbound_streaming_channel_adapter" href="#_inbound_streaming_channel_adapter"></a>156.3.2 Inbound streaming channel adapter</h3></div></div></div><p>The inbound streaming channel adapter is similar to the normal inbound channel adapter, except it does not require files to be stored in the file system.</p><p>Here is an example of how to configure a Google Cloud Storage inbound streaming channel adapter.</p><pre class="programlisting"><em><span class="hl-annotation" style="color: gray">@Bean</span></em>
|
|
<em><span class="hl-annotation" style="color: gray">@InboundChannelAdapter(channel = "streaming-channel", poller = @Poller(fixedDelay = "5000"))</span></em>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">public</span> MessageSource<InputStream> streamingAdapter(Storage gcs) {
|
|
GcsStreamingMessageSource adapter =
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">new</span> GcsStreamingMessageSource(<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">new</span> GcsRemoteFileTemplate(<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">new</span> GcsSessionFactory(gcs)));
|
|
adapter.setRemoteDirectory(<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"your-gcs-bucket"</span>);
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">return</span> adapter;
|
|
}</pre></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_outbound_channel_adapter_2" href="#_outbound_channel_adapter_2"></a>156.3.3 Outbound channel adapter</h3></div></div></div><p>The outbound channel adapter allows files to be written to Google Cloud Storage.
|
|
When it receives a <code class="literal">Message</code> containing a payload of type <code class="literal">File</code>, it writes that file to the Google Cloud Storage bucket specified in the adapter.</p><p>Here is an example of how to configure a Google Cloud Storage outbound channel adapter.</p><pre class="programlisting"><em><span class="hl-annotation" style="color: gray">@Bean</span></em>
|
|
<em><span class="hl-annotation" style="color: gray">@ServiceActivator(inputChannel = "writeFiles")</span></em>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">public</span> MessageHandler outboundChannelAdapter(Storage gcs) {
|
|
GcsMessageHandler outboundChannelAdapter = <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">new</span> GcsMessageHandler(<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">new</span> GcsSessionFactory(gcs));
|
|
outboundChannelAdapter.setRemoteDirectoryExpression(<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">new</span> ValueExpression<>(<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"your-gcs-bucket"</span>));
|
|
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">return</span> outboundChannelAdapter;
|
|
}</pre></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_sample_4" href="#_sample_4"></a>156.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-integration-storage-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_jdbc.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="multi_spring-cloud-gcp-reference.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="multi__spring_cloud_stream_2.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">155. Spring JDBC </td><td width="20%" align="center"><a accesskey="h" href="multi_spring-cloud.html">Home</a></td><td width="40%" align="right" valign="top"> 157. Spring Cloud Stream</td></tr></table></div></body></html> |