-
Notifications
You must be signed in to change notification settings - Fork 1.6k
RetryableTopic - provide a mechanism to suppress non-essential headers #2155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Possibly related to this SO question. But I think it might be worth it to have a dedicated option not to include the stacktrace in |
Yeah, even if I get access to the original header function via reflection it won't help with suppressing the generation of the headers that are not strictly required. The reason for it is that |
I suggest we add something like public interface HeaderCreator {
void create(Headers kafkaHeaders, Exception exception, boolean isKey);
} (and a setter) with the default being WDYT? |
Something like Lines 635 to 643 in 3c9e00f
It is possible to replace the header names. Having programmatic access to this data could make the code a bit more generic. Although, admittedly, if the header names are replaced then you also know what they are. |
Oh, because you might want to add just some of the headers (e.g. all except the full stack trace). That makes sense. Another option would be to add a |
I think the solution seems great. Just a thought, for the SO issue, considering we already have a |
Why would we need to add a setter to the factory, given that we already have a setter for a DLPR customizer? (Or maybe I misunderstand your comment). |
Also, I think the resulting API would be simpler, since the user would have an explicit method for handling this in the feature's component, instead of having to go through the customizer and knowing to use a different method than the Of course, that's only a way of looking into this. Makes sense? |
Good point; will add that too. PR coming soon... |
Resolves spring-projects#2155 - Add a `BitSet` property to suppress individual standard headers - Support multiple `headersFunction` - Allow complete customization of exception headers - Add `setHeadersFunction` to the DLPR factory for retryable topics
Resolves spring-projects#2155 - Add a `BitSet` property to suppress individual standard headers - Support multiple `headersFunction` - Allow complete customization of exception headers - Add `setHeadersFunction` to the DLPR factory for retryable topics
Resolves spring-projects#2155 - Add a `BitSet` property to suppress individual standard headers - Support multiple `headersFunction` - Allow complete customization of exception headers - Add `setHeadersFunction` to the DLPR factory for retryable topics
Resolves spring-projects#2155 - Add a `BitSet` property to suppress individual standard headers - Support multiple `headersFunction` - Allow complete customization of exception headers - Add `setHeadersFunction` to the DLPR factory for retryable topics
Resolves spring-projects#2155 - Add a `BitSet` property to suppress individual standard headers - Support multiple `headersFunction` - Allow complete customization of exception headers - Add `setHeadersFunction` to the DLPR factory for retryable topics
Resolves #2155 Co-authored-by: Viacheslav Chernyshev <[email protected]> - Add a `BitSet` property to suppress individual standard headers - Support multiple `headersFunction` - Allow complete customization of exception headers - Add `setHeadersFunction` to the DLPR factory for retryable topics * Fix typo in doc. * Rework enum usage; other refactoring; add getters to `HeaderNames`. * Fix javadocs. * Doc polishing. * Change BitSet to EnumSet. * Fix bogus import. * Defend against immutable headers; only create new when detected. * Fix NOSONAR typo. **Cherry-pick to `2.8.x`**
Resolves #2155 Co-authored-by: Viacheslav Chernyshev <[email protected]> - Add a `BitSet` property to suppress individual standard headers - Support multiple `headersFunction` - Allow complete customization of exception headers - Add `setHeadersFunction` to the DLPR factory for retryable topics * Fix typo in doc. * Rework enum usage; other refactoring; add getters to `HeaderNames`. * Fix javadocs. * Doc polishing. * Change BitSet to EnumSet. * Fix bogus import. * Defend against immutable headers; only create new when detected. * Fix NOSONAR typo. **Cherry-pick to `2.8.x`** # Conflicts: # spring-kafka/src/main/java/org/springframework/kafka/listener/DeadLetterPublishingRecoverer.java
Expected Behavior
I'd like to have a way to suppress the generation of the exception headers as they are quite verbose and drastically increase the size of the messages.
Current Behavior
Exception information headers are unconditionally added in this function:
spring-kafka/spring-kafka/src/main/java/org/springframework/kafka/listener/DeadLetterPublishingRecoverer.java
Lines 363 to 364 in dc47e72
Context
In our application the initial attempt is quite likely to fail as we have to wait for data to be available in an external system that does not provide native notifications. The current retryable topics implementation adds a number of exception-related headers, including the full stacktrace information. When combined they increase the average message size from a couple hundred bytes to approximately 10 kilobytes. For us this overhead is hard to ignore.
Unfortunately, I do not see any way to hook into the header generation process.
setHeadersFunction
cannot be used as it is already customised by the recoverer factory:spring-kafka/spring-kafka/src/main/java/org/springframework/kafka/retrytopic/DeadLetterPublishingRecovererFactory.java
Line 139 in dc47e72
The only workaround I can think of is to add a custom producer interceptor that strips the headers out of the records, but then the CPU resources are wasted on rendering the information that is almost immediately thrown away. It would be nice to avoid generating these headers in the first place.
The text was updated successfully, but these errors were encountered: