Skip to content

Enable Pub/Sub message ordering for publishing #408

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 25, 2021
Merged

Conversation

meltsufin
Copy link
Member

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: #85.

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: #85.
@meltsufin meltsufin requested review from ttomsu, elefeint and dzou March 24, 2021 20:30
Copy link
Contributor

@elefeint elefeint left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, couple of minor things.

//tag::publish_ordering[]
Map<String, String> headers = Collections.singletonMap(GcpPubSubHeaders.ORDERING_KEY, "key1");
pubSubTemplate.publish(topicName, "message1", headers).get();
pubSubTemplate.publish(topicName, "message2", headers).get();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a comment to explain that messages with the same ordering key will be delivered in the same order they were sent.

/**
* Enable message ordering setting.
*/
private Boolean enableMessageOrdering;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not a primitive boolean? Default state is false; would be no need to mess with nulls.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 yeah would also prefer the primitive boolean to avoid implying that not setting it is different than setting it to false.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sometimes we follow the pattern that is to allow not setting it, so that the client library default can be used automatically. Otherwise, we have to maintain the default, which in this case probably doesn't matter.

publisherBuilder.setBatchingSettings(this.batchingSettings);
}

if (this.enableMessageOrdering != null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's primitive, then we don't need to check for null here, just straight set the value, or, to be extra safe, check if true.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The question is whether we want to allow not setting the value at all and letting the client lib control the default.

.build());

this.adapter.handleMessage(this.message);
verify(this.pubSubTemplate, times(1))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can omit times(1)

@sonarqubecloud
Copy link

@meltsufin meltsufin merged commit 8b4b714 into main Mar 25, 2021
@meltsufin meltsufin deleted the pubsub-ordering branch March 25, 2021 19:22
kateryna216 added a commit to kateryna216/spring-cloud-gcp that referenced this pull request Oct 20, 2022
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants