Commit 240d03b
authored
[fix][client]Add setCompressMinMsgBodySize method to ProducerBuilder for compression configuration flexibility (#24164)
PIP: #23526
#### Motivation
Currently, the `ProducerBuilder` API lacks the ability to directly configure the `compressMinMsgBodySize` property during producer initialization. Users are forced to modify the internal `ProducerConfigurationData` post-creation, which:
1. **Violates encapsulation** by exposing internal configuration fields.
2. **Introduces inconsistency** with other compression settings (e.g., `compressionType`) that are already configurable via the builder.
3. **Creates usability hurdles**, requiring workarounds like:
```java
Producer<byte[]> producer = client.newProducer().topic("test").create();
producer.conf.setCompressMinMsgBodySize(1024); // Insecure and error-prone
```
This change aligns the builder API with standard compression configuration patterns and improves developer ergonomics.
#### Modifications
1. **API Enhancement**:
- Added `compressMinMsgBodySize(int)` method to the `ProducerBuilder` interface.
- Propagate the configured value to `ProducerConfigurationData` during producer initialization.
2. **Behavior Preservation**:
- Default value remains unchanged if the method is not invoked.
- Fully backward-compatible with existing code.
3. **Testing & Documentation**:
- Added unit tests to validate compression threshold behavior via the new builder method.
- Updated Javadoc and configuration examples to reflect the new API.1 parent 610b72e commit 240d03b
3 files changed
Lines changed: 20 additions & 2 deletions
File tree
- pulsar-broker/src/test/java/org/apache/pulsar/client/impl
- pulsar-client-api/src/main/java/org/apache/pulsar/client/api
- pulsar-client/src/main/java/org/apache/pulsar/client/impl
Lines changed: 1 addition & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
245 | 245 | | |
246 | 246 | | |
247 | 247 | | |
| 248 | + | |
248 | 249 | | |
249 | 250 | | |
250 | 251 | | |
251 | 252 | | |
252 | 253 | | |
253 | 254 | | |
254 | 255 | | |
255 | | - | |
256 | | - | |
257 | 256 | | |
258 | 257 | | |
259 | 258 | | |
| |||
Lines changed: 13 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
293 | 293 | | |
294 | 294 | | |
295 | 295 | | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
296 | 309 | | |
297 | 310 | | |
298 | 311 | | |
| |||
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
174 | 174 | | |
175 | 175 | | |
176 | 176 | | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
177 | 183 | | |
178 | 184 | | |
179 | 185 | | |
| |||
0 commit comments