Skip to content

Add support for Pub/Sub message ordering #85

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

Closed
meltsufin opened this issue Oct 14, 2020 · 8 comments
Closed

Add support for Pub/Sub message ordering #85

meltsufin opened this issue Oct 14, 2020 · 8 comments
Labels
pubsub type: enhancement New feature or request

Comments

@meltsufin
Copy link
Member

meltsufin commented Oct 14, 2020

PubSubAdmin.createSubscription() will need to be expanded to allow enabling ordering, and whenever we create a PubsubMessage, we need to be able to set the ordering key for it.
Also, the Pub/Sub Cloud Stream Binder will need to be updated to support the option.
See: https://cloud.google.com/pubsub/docs/ordering
See: https://cloud.google.com/pubsub/docs/publisher#using_ordering_keys

Q: Does it makes sense to expose the keys as partitions in a Kafka-binder-like API?

@meltsufin
Copy link
Member Author

@ttomsu What do you think of focusing on this one after DLQ?

@DerMorb
Copy link

DerMorb commented Mar 12, 2021

The PubSubMessageConverter.toPubSubMessage(Object payload, Map<String, String> headers) method might also need a way to set the ordering key or we need another way to provide the ordering key.
Right now the payload is ending up in the data and the headers in the attributes of a PubSubMessage but the ordering key is a separate field.

Or do we need to write our own message converter somehow like this?

public class OrderMessagePubSubMessageConverter extends JacksonPubSubMessageConverter {

    public OrderMessagePubSubMessageConverter(ObjectMapper objectMapper) {
        super(objectMapper);
    }

    @Override
    public PubsubMessage toPubSubMessage(Object payload, Map<String, String> headers) {
        PubsubMessage pubsubMessage = super.toPubSubMessage(payload, headers);
        return PubsubMessage.newBuilder()
                            .mergeFrom(pubsubMessage)
                            .setOrderingKey(???)
                            .build();
    }
}

@meltsufin
Copy link
Member Author

@DerMorb I think we just need to pick a name for the header by adding it to GcpPubSubHeaders and then extend all implementations of PubSubMessageConverter to marshal that header back and forth between headers and PubsubMessage.orderingKey. It's kind of what you're suggesting, but more general.

meltsufin added a commit that referenced this issue Mar 24, 2021
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 added a commit that referenced this issue Mar 24, 2021
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 added a commit that referenced this issue Mar 25, 2021
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
Copy link
Member Author

Now that #85 is in, what's left?

  1. In Spring Cloud Stream Binder for Pub/Sub, we should add the ability to automatically create subscriptions that support message ordering. This will involve adding enableMessageOrdering property to PubSubConsumerProperties and updating PubSubChannelProvisioner.createSubscription.
  2. In Spring Integration Outbound Channel Adapter AKA PubSubMessageHandler we can add a property to specify a default ordering key.
  3. Once (2) is done, we can expose this ability to the Binder by adding the orderingKey property to the PubSubProducerProperties and using it in the PubSubMessageChannelBinder.createProducerMessageHandler.

@vijaysdey88
Copy link

Is this feature implemented in latest release?

@meltsufin
Copy link
Member Author

No, only the latest SNAPSHOT release has the change.

@pivotaleventing
Copy link

Hello,

Do you have a plan when this will be published?

@elefeint
Copy link
Contributor

Publisher endpoints for message ordering have been available since version 2.0.3

@zhumin8 zhumin8 closed this as completed Sep 3, 2021
kateryna216 added a commit to kateryna216/spring-cloud-gcp that referenced this issue 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
pubsub type: enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants