BewareMyPower commented on code in PR #24020:
URL: https://github.com/apache/pulsar/pull/24020#discussion_r1977233110
##########
pip/pip-409.md:
##########
@@ -33,25 +33,88 @@ retry/dead letter topic.
## Design & Implementation Details
-- Add two new configurations in `DeadLetterPolicy`:
+- Add `ProducerBuilderContext` and `ProducerBuilderCustomizer` interface:
+```java
+public interface ProducerBuilderContext {
+ /**
+ * Returns the default name of topic for the dead letter or retry letter
producer. This topic name is used
+ * unless the ProducerBuilderCustomizer overrides it.
+ *
+ * @return a {@code String} representing the input topic name
+ */
+ String getDefaultTopicName();
+
+ /**
+ * Returns the name of the input topic for which the dead letter or retry
letter producer is being configured.
+ *
+ * @return a {@code String} representing the input topic name
+ */
+ String getInputTopicName();
+
+ /**
+ * Returns the name of the subscription for which the dead letter or retry
letter producer is being configured.
+ *
+ * @return a {@code String} representing the subscription name
+ */
+ String getInputTopicSubscriptionName();
+}
+
+public interface ProducerBuilderCustomizer {
+ /**
+ * Customize the given producer builder with settings specific to the
topic context provided.
+ *
+ * @param context the context containing information about the
input topic and the subscription
+ * @param producerBuilder the producer builder instance to be customized
+ */
+ void customize(ProducerBuilderContext context, ProducerBuilder<byte[]>
producerBuilder);
Review Comment:
This interface can be implemented from the client side. Unnecessary
flexibility might cause unexpected behaviors that are hard to diagnose. The
current interceptor is such a bad example:
https://github.com/apache/pulsar/blob/998bb51f5ea256c59110e5b8bef0f9daef1ac48d/pulsar-client-api/src/main/java/org/apache/pulsar/client/api/interceptor/ProducerInterceptor.java#L83
With incorrect implementations, `beforeSend` could return `null` or a
customized `Message` implementation. What's worse, if it returns a valid
`MessageImpl` with broken `getValue()` implementation, it won't fail fast.
Instead, a broken data could be written.
Therefore, I still suggest limiting such tricky use cases.
--
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]