[Java clients] Consumer should not try to establish a connection to the broker within its constructor
- Dominant language
- Java
- Stars
- 15.3k
- Forks
- 3.8k
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 160
Description
Java Pulsar Consumer should not try to establish a connection to the broker within its constructor.
Instead, it should delay attempting to do so until the first time `receive()` is invoked. At the moment it's hard to spin up an application if Pulsar is temporary unreachable. The `subscribe()` call blocks until it successfully connects, or throws exceptions. The async alternative, `subscribeAsync()` won't complete until the connection is established. The result is that the application can crash or fail to come up if Pulsar is temporary unreachable during boot time.
As an alternative, the `Consumer` should expose explicit `connect()` and `connectAsync()` functions, for users to manually establish the connection. A property could be used to maintain backwards compatibility, like `delayEstablishingConnectionUntilNeeded`, with a default of false, so that existing code continues to work fine.
In the context of reactive streams, it's particularly important that everything happens lazily when the stream is collected, not when it's generated.
Contributor guide
Research direction
Start by tracing the Java Consumer constructor and the subscribe(), subscribeAsync(), and receive() entry points; also inspect how reactive streams trigger consumer creation and collection. Resolve the connection timing and compatibility behavior, then verify that startup does not require a broker connection and that connection establishment occurs at the intended explicit or receive-time boundary.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- distributed-systems
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100