You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Introduces `GcpPubSubHeaders.ORDERING_KEY` header that will be automatically applied to the `PubsubMessage` up conversion.
Also, introduces `spring.cloud.gcp.pubsub.publisher.enable-message-ordering` property to enable message ordering on the `Publisher`.
First step in addressing: GoogleCloudPlatform#85.
Copy file name to clipboardExpand all lines: docs/src/main/asciidoc/pubsub.adoc
+12
Original file line number
Diff line number
Diff line change
@@ -77,6 +77,8 @@ The delay threshold to use for batching.
77
77
After this amount of time has elapsed (counting from the first element added), the elements will be wrapped up in a batch and sent. | No | 1 ms (batching off)
By default, the `SimplePubSubMessageConverter` is used to convert payloads of type `byte[]`, `ByteString`, `ByteBuffer`, and `String` to Pub/Sub messages.
178
180
181
+
===== Ordering messages
182
+
183
+
If you are relying on message converters and would like to provide an ordering key, use the `GcpPubSubHeaders.ORDERING_KEY` header.
184
+
You will also need to make sure to enable message ordering on the publisher via the `spring.cloud.gcp.pubsub.publisher.enable-message-ordering` property.
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.
298
298
By default, the inbound channel adapter maps every header on the Google Cloud Pub/Sub messages to the Spring messages produced by the adapter.
299
-
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 `"id"`, `"timestamp"`and `"gcp_pubsub_acknowledgement"`.
299
+
The outbound channel adapter maps every header from Spring messages into Google Cloud Pub/Sub ones, except the ones added by Spring and some special headers, like headers with key `"id"`, `"timestamp"`, `"gcp_pubsub_acknowledgement"`, and `"gcp_pubsub_ordering_key"`.
300
300
In the process, the outbound mapper also converts the value of the headers into string.
301
301
302
+
Note that you can provide the `GcpPubSubHeaders.ORDERING_KEY` (`"gcp_pubsub_ordering_key"`) header, which will be automatically mapped to `PubsubMessage.orderingKey` property, and excluded from the headers in the published message.
303
+
Remember to set `spring.cloud.gcp.pubsub.publisher.enable-message-ordering` to `true`, if you are publishing messages with this header.
304
+
302
305
Each adapter declares a `setHeaderMapper()` method to let you further customize which headers you want to map from Spring to Google Cloud Pub/Sub, and vice-versa.
303
306
304
307
For example, to filter out headers `"foo"`, `"bar"` and all headers starting with the prefix "prefix_", you can use `setHeaderMapper()` along with the `PubSubHeaderMapper` implementation provided by this module.
Copy file name to clipboardExpand all lines: spring-cloud-gcp-autoconfigure/src/main/java/com/google/cloud/spring/autoconfigure/pubsub/GcpPubSubAutoConfiguration.java
+1
Original file line number
Diff line number
Diff line change
@@ -309,6 +309,7 @@ public PublisherFactory defaultPublisherFactory(
Copy file name to clipboardExpand all lines: spring-cloud-gcp-autoconfigure/src/main/java/com/google/cloud/spring/autoconfigure/pubsub/GcpPubSubProperties.java
+13
Original file line number
Diff line number
Diff line change
@@ -126,6 +126,11 @@ public static class Publisher {
126
126
*/
127
127
privatefinalBatchingbatching = newBatching();
128
128
129
+
/**
130
+
* Enable message ordering setting.
131
+
*/
132
+
privateBooleanenableMessageOrdering;
133
+
129
134
publicBatchinggetBatching() {
130
135
returnthis.batching;
131
136
}
@@ -141,6 +146,14 @@ public int getExecutorThreads() {
Copy file name to clipboardExpand all lines: spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/pubsub/it/PubSubTemplateDocumentationIntegrationTests.java
Copy file name to clipboardExpand all lines: spring-cloud-gcp-pubsub/src/main/java/com/google/cloud/spring/pubsub/support/converter/JacksonPubSubMessageConverter.java
+2-8
Original file line number
Diff line number
Diff line change
@@ -48,14 +48,8 @@ public JacksonPubSubMessageConverter(ObjectMapper objectMapper) {
Copy file name to clipboardExpand all lines: spring-cloud-gcp-pubsub/src/main/java/com/google/cloud/spring/pubsub/support/converter/PubSubMessageConverter.java
Copy file name to clipboardExpand all lines: spring-cloud-gcp-pubsub/src/main/java/com/google/cloud/spring/pubsub/support/converter/SimplePubSubMessageConverter.java
+1-8
Original file line number
Diff line number
Diff line change
@@ -63,14 +63,7 @@ else if (payload instanceof byte[]) {
63
63
payload.getClass().getName() + " to byte[] for sending to Pub/Sub.");
Copy file name to clipboardExpand all lines: spring-cloud-gcp-pubsub/src/test/java/com/google/cloud/spring/pubsub/integration/outbound/PubSubMessageHandlerTests.java
0 commit comments