You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by "itxaiohanglover (via GitHub)" <gi...@apache.org> on 2026/07/22 05:13:37 UTC

[PR] feat(java): support GZIP message body compression on producer side [rocketmq-clients]

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: commits-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(java): support GZIP message body compression on producer side [rocketmq-clients]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #1304:
URL: https://github.com/apache/rocketmq-clients/pull/1304#issuecomment-5593989604

   This PR is stale because it has been open for 30 days with no activity. It will be closed in 3 days if no further activity occurs. If you wish not to mark it as stale, please leave a comment in this PR.


-- 
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: commits-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(java): support GZIP message body compression on producer side [rocketmq-clients]

Posted by "itxaiohanglover (via GitHub)" <gi...@apache.org>.
itxaiohanglover commented on PR #1304:
URL: https://github.com/apache/rocketmq-clients/pull/1304#issuecomment-5053630604

   Thanks for the thorough review — all four points adopted in 621b7af:
   
   1. **Encapsulation**: `PublishingSettings#setCompressBodyThresholdBytes` is now package-private, called only from `ProducerBuilderImpl` in the same package (tests go through a same-package helper).
   2. **Compression fallback**: GZIP output is now used only when it is strictly smaller than the original body; otherwise the message falls back to `IDENTITY`, so already-compressed/encrypted payloads are never inflated.
   3. **`sync()` clarification**: added an inline comment marking the threshold as a client-only setting that is never synced from the server.
   4. **Tests**: added the three suggested cases — exact-threshold boundary (`== threshold` compresses), incompressible random body falls back to `IDENTITY` deterministically, and an oversized incompressible body is rejected against `maxBodySizeBytes`. Also added a case documenting that a >4 MiB compressible body is accepted when its compressed form fits, matching the documented transport-size semantics.
   
   All 19 tests pass locally (`PublishingMessageImplTest` 7/7, `ProducerBuilderImplTest` 12/12).


-- 
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: commits-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(java): support GZIP message body compression on producer side [rocketmq-clients]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] closed pull request #1304: feat(java): support GZIP message body compression on producer side
URL: https://github.com/apache/rocketmq-clients/pull/1304


-- 
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: commits-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(java): support GZIP message body compression on producer side [rocketmq-clients]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #1304:
URL: https://github.com/apache/rocketmq-clients/pull/1304#issuecomment-5649758058

   This PR was closed because it has been inactive for 3 days since being marked as stale.


-- 
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: commits-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org