itxaiohanglover opened a new pull request, #1304:
URL: https://github.com/apache/rocketmq-clients/pull/1304
### Which Issue(s) This PR Fixes
Fixes #1288
### Brief Description
This PR adds opt-in producer-side message body compression for the Java
client:
- New API `ProducerBuilder#setCompressBodyThresholdBytes(int)`: once set, a
message whose body size reaches the threshold is compressed with GZIP before
sending. Compression is **disabled by default** (`Integer.MAX_VALUE`), so
existing behavior is unchanged.
- `PublishingMessageImpl` now carries the transport body and its `Encoding`
(`IDENTITY` / `GZIP`), and sets `SystemProperties#bodyEncoding` accordingly,
instead of always hardcoding `IDENTITY`.
- The max body size check is applied to the transported (possibly
compressed) body, matching the intent documented on
`PublishingSettings#maxBodySizeBytes` ("it would be compressed for convenience
of transport"), which was previously not implemented.
No change is required on the consuming side: `MessageViewImpl` already
decompresses the body transparently according to the body encoding (magic-code
based, GZIP supported).
Regarding zstd (mentioned in #1288): the protocol-level
`apache.rocketmq.v2.Encoding` enum currently only defines `IDENTITY` and
`GZIP`, so zstd support requires a protocol change in rocketmq-apis first. This
PR takes GZIP as the first step; zstd can be a follow-up once the protocol
supports it. (The compression utilities for ZSTD/ZLIB/LZ4 already exist in
`Utilities` for the consuming side.)
### How Did You Test This Change?
- Added `PublishingMessageImplTest`:
- body is not compressed by default;
- body reaching the threshold is compressed, `bodyEncoding` is `GZIP`, and
`Utilities#decompressBytes` round-trips to the original body;
- body below the threshold stays `IDENTITY`.
- Added builder validation tests in `ProducerBuilderImplTest` (negative
threshold rejected).
- Ran the related unit tests locally: new tests 15/15 passed.
(`ProducerImplTest`/`TransactionImplTest` Mockito errors on my machine are a
pre-existing local JDK 21 incompatibility, reproduced on a clean master
checkout as well.)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]