Skip to content

[feat] Add consumer PriorityLevel support#1487

Open
grishaf wants to merge 2 commits intoapache:masterfrom
grishaf:feat/consumer-priority-level
Open

[feat] Add consumer PriorityLevel support#1487
grishaf wants to merge 2 commits intoapache:masterfrom
grishaf:feat/consumer-priority-level

Conversation

@grishaf
Copy link
Copy Markdown

@grishaf grishaf commented Apr 27, 2026

Add PriorityLevel field to ConsumerOptions to allow setting the
priority level for consumers on Shared and Failover subscriptions,
matching the Java client's ConsumerBuilder.priorityLevel(int) API.

Negative priority levels are rejected with InvalidConfiguration error,
matching the Java client's IllegalArgumentException behavior.

Master Issue: apache/pulsar#134
Supersedes: #783 (closed without merge, lacked tests and had validation bugs)

    Add PriorityLevel field to ConsumerOptions to allow setting the
    priority level for consumers on Shared and Failover subscriptions,
    matching the Java client's ConsumerBuilder.priorityLevel(int) API.

    In Shared subscription mode, the broker dispatches messages to the
    highest priority consumers first (0 = max priority). In Failover
    subscription mode for partitioned topics, the broker selects the
    active consumer based on priority level and lexicographic consumer
    name sorting.

    Previously the Go client hardcoded PriorityLevel to nil in the
    CommandSubscribe protobuf message. This change threads the user-
    provided priority level through ConsumerOptions -> partitionConsumerOpts
    -> CommandSubscribe.

    Negative priority levels are rejected with InvalidConfiguration error,
    matching the Java client's IllegalArgumentException behavior.

    Master Issue: apache/pulsar#134
    Supersedes: apache#783 (closed without merge, lacked tests and had validation bugs)
@crossoverJie
Copy link
Copy Markdown
Member

@grishaf Please check the CI errors.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds consumer-side support for Pulsar consumer priority_level by exposing PriorityLevel on ConsumerOptions, validating configuration, and wiring the value into the subscribe command; includes new integration tests for shared + failover priority behavior.

Changes:

  • Add PriorityLevel to ConsumerOptions with GoDoc describing shared/failover semantics.
  • Validate negative priority levels as InvalidConfiguration.
  • Plumb PriorityLevel through partition consumer options into CommandSubscribe.PriorityLevel, and add tests covering invalid config + shared/failover scenarios.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
pulsar/consumer.go Adds the public ConsumerOptions.PriorityLevel field and documentation.
pulsar/consumer_impl.go Adds validation for priority level and passes it into partition consumer options.
pulsar/consumer_partition.go Sends the priority level in the subscribe protocol command.
pulsar/consumer_test.go Adds tests for invalid priority, shared-subscription dispatch behavior, and failover-partition distribution behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pulsar/consumer_impl.go Outdated
Comment thread pulsar/consumer_test.go Outdated
Comment thread pulsar/consumer_test.go Outdated
Comment thread pulsar/consumer_test.go Outdated
- Validate PriorityLevel <= math.MaxInt32 to prevent int64-to-int32
  overflow when casting for the CommandSubscribe protobuf field
- Assert Receive() results in TestPriorityConsumer drain loops instead
  of silently ignoring errors
- Remove duplicate explicit Close() calls in TestPriorityConsumer and
  TestFailOverConsumerPriority (already handled by defer)
- Rename unused parameter `at` to `_` in retryAssert callback to fix
  revive unused-parameter lint error
@grishaf
Copy link
Copy Markdown
Author

grishaf commented Apr 30, 2026

@crossoverJie
thank, was fixed

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