Skip to content

feat(pulsar): message binding with key for ordering - #315

Open
reinaut-krekels-acerta wants to merge 5 commits into
asyncapi:masterfrom
reinaut-krekels-acerta:feat/pulsar-message-key
Open

reinaut-krekels-acerta wants to merge 5 commits into
asyncapi:masterfrom
reinaut-krekels-acerta:feat/pulsar-message-key

Conversation

@reinaut-krekels-acerta

Copy link
Copy Markdown

Add a Pulsar Message Binding Object with a key field, used for Key_Shared ordering.

Description

Adds a Message Binding Object to the Pulsar binding with an optional key field, similar to the Kafka message binding.

  • Added key (Schema Object | Reference Object) to the message binding. Pulsar uses the message key to guarantee ordering for consumers on a Key_Shared subscription. Documenting it lets producers and consumers agree on how messages are partially ordered.
  • Bumped the Pulsar binding version from 0.1.0 to 0.2.0.
  • Unchanged: server and channel bindings.

Related issue(s)

Resolves #289

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Welcome to AsyncAPI. Thanks a lot for creating your first pull request. Please check out our contributors guide useful for opening a pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.

Comment thread pulsar/README.md Outdated

Field Name | Type | Required | Description | Default value |
---|:---:|:---:|:---|:---|
`key` | [Schema Object][schemaObject] \| [Reference Object][referenceObject] | No | The message key, determining the [order](https://pulsar.apache.org/docs/next/concepts-messaging/#ordering-guarantee) for consumers using a [Key_Shared](https://pulsar.apache.org/docs/next/concepts-messaging/#key_shared) subscription. | N/A |

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't agree with the current design

Apache Pulsar allows to send messages with:

  • key (routing)
  • partitionKey (may act as orderingKey for ordering when orderingKey not present)
  • orderingKey (has priority over key for ordering)

Instead of introduction only one key we MUST add them all

binding is internal representation of message properties(like config dump). So if we started adding keys, lets add them all also as provide correct documentation

All keys are of string type. Allow pass general JSON Schema without restrictions is bad idea which leads to incorrect representation

@reinaut-krekels-acerta reinaut-krekels-acerta Oct 22, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Ok, I'll fix the type and update it to include all. Before this, I tried to keep the change as minimal as possible.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ok, I'll fix the type and update it to include all. Before this, I tried to keep the change as minimal as possible.

Don't worry to propose big changes :)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

They don’t enumerate available config keys. We can start from here https://github.com/api-evangelist/apache-pulsar/blob/master/json-schema/apache-pulsar-pulsar-message-schema.json

I'll double check Java SDK also as try to dump messages from Pulsar to get how they are written inside broke

@reinaut-krekels-acerta reinaut-krekels-acerta Oct 23, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I've added orderingKey and restricted both keys to type: string.
I didn't add a separate partitionKey, as it seems to be the same as key, i.e. AFAICT there are only 2 key fields (Javadoc).

Currently I kept Schema Object rather than a strict string so the key's values can be described (e.g. format: uuid), similar to the Kafka binding's key. Is it ok like this or do you prefer the stricter plain string form?

@reinaut-krekels-acerta reinaut-krekels-acerta Oct 26, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I've changed them to Type String and update an example to match yours.
Will you please re-review?

FYI, inside the broker they use protobuf with a partition_key field (and an ordering key): https://github.com/apache/pulsar/blob/master/pulsar-common/src/main/proto/PulsarApi.proto#L107
In the API they use key https://github.com/apache/pulsar/blob/master/pulsar-client-api/src/main/java/org/apache/pulsar/client/api/Message.java#L146 but it returns that partition_key field: https://github.com/apache/pulsar/blob/master/pulsar-client/src/main/java/org/apache/pulsar/client/impl/MessageImpl.java#L702

Add a Pulsar Message Binding Object with a `key` field, used for Key_Shared ordering.
Add `orderingKey` and restrict key and orderingKey to string schemas.
Use Type String for the fields, as Type defines a restriction on the field content, not on the field's form.
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.

[FEATURE] Pulsar Order Key

3 participants