Skip to content

fix: handle reconnection logic for zero queue consumer - #1404

Merged
BewareMyPower merged 5 commits into
apache:masterfrom
crossoverJie:fix-1330
Aug 29, 2025
Merged

BewareMyPower merged 5 commits into
apache:masterfrom
crossoverJie:fix-1330

Conversation

@crossoverJie

@crossoverJie crossoverJie commented Jul 31, 2025 •

Copy link
Copy Markdown
Member

Fixes #1330 #398

Motivation

ZeroQueueConsumer cannot consume messages when the broker restarts or unload topic.

Modifications

  • Increase availablePermits on reconnect for ZeroQueueConsumer
  • Add test case for zero queue consumer reconnection
  • Suppress/Do not print the "unable to send initial permits to broker" error log when using ZeroQueueConsumer.

Verifying this change

  • Make sure that the change passes the CI checks.

(Please pick either of the following options)

This change is a trivial rework / code cleanup without any test coverage.

(or)

This change is already covered by existing tests, such as (please describe tests).

(or)

This change added tests and can be verified as follows:

(example:)

  • Added integration tests for end-to-end deployment with large payloads (10MB)
  • Extended integration test for recovery after broker failure

Does this pull request potentially affect one of the following parts:

If yes was chosen, please highlight the changes

  • Dependencies (does it add or upgrade a dependency): (yes / no)
  • The public API: (yes / no)
  • The schema: (yes / no / don't know)
  • The default values of configurations: (yes / no)
  • The wire protocol: (yes / no)

Documentation

  • Does this pull request introduce a new feature? (yes / no)
  • If yes, how is the feature documented? (not applicable / docs / GoDocs / not documented)
  • If a feature is not applicable for documentation, explain why?
  • If a feature is not documented yet in this PR, please create a followup issue for adding the documentation

- Add enableZeroQueueConsumer flag to ConsumerOptions- Implement reconnection logic for zero queue consumer
- Update availablePermits on reconnect for zero queue consumer
- Add test case for zero queue consumer reconnection
@crossoverJie
crossoverJie requested a review from Copilot July 31, 2025 03:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes reconnection issues for ZeroQueueConsumer when the broker restarts or unloads topics. The fix ensures that zero queue consumers can continue consuming messages after broker interruptions.

  • Increases availablePermits on reconnection for zero queue consumers to restore message flow
  • Suppresses error logging for initial permits when using zero queue consumers
  • Adds comprehensive test coverage for zero queue consumer reconnection scenarios

Reviewed Changes

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

File Description
pulsar/consumer_zero_queue_test.go Adds integration test that simulates broker restart with Docker containers
pulsar/consumer_partition.go Implements reconnection logic and suppresses error logging for zero queue consumers
pulsar/consumer_impl.go Passes enableZeroQueueConsumer flag to partition consumer options
Comments suppressed due to low confidence (4)

pulsar/consumer_zero_queue_test.go:220

  • The test has a fixed 5-second sleep after receiving each message, making it take 50+ seconds to complete. This creates an unnecessarily slow test. Consider reducing the sleep time or removing it entirely if it's not essential for the test logic.
		time.Sleep(5 * time.Second)

pulsar/consumer_zero_queue_test.go:195

  • The variable name 'time' shadows the imported 'time' package, which could cause confusion. Consider renaming it to 'timeout' or 'stopTimeout'.
		time := 5 * time.Second

pulsar/consumer_zero_queue_test.go:206

  • The test uses log.Fatal(err) which will terminate the entire test suite if a message receive fails. This prevents proper cleanup of the Docker container. Consider using assert.NoError(t, err) or require.NoError(t, err) instead to ensure proper test failure handling.
		if err != nil {

pulsar/consumer_zero_queue_test.go:141

  • Setting Reuse: true for the test container could cause issues if multiple tests run concurrently or if the container state persists between test runs. Consider setting this to false for more predictable test behavior.
		Reuse:            true,

Comment thread pulsar/consumer_zero_queue_test.go Resolved
Comment thread pulsar/consumer_zero_queue_test.go Resolved
- Replace broker restart simulation with topic unloading
- Add pulsar admin client to perform topic operations
- Synchronize message reception with topic unloading event
- Remove unnecessary sleep for more deterministic test behavior
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.

Zero queue consumer doesn't seem to work properly

3 participants