lhotari commented on code in PR #24020:
URL: https://github.com/apache/pulsar/pull/24020#discussion_r1975495488


##########
pulsar-client-api/src/main/java/org/apache/pulsar/client/api/DeadLetterPolicy.java:
##########
@@ -62,4 +63,16 @@ public class DeadLetterPolicy implements Serializable {
      * to be created.
      */
     private String initialSubscriptionName;
+
+    /**
+     * Function to build the producer for the retry letter topic.
+     * The input parameter is the topic name.
+     */
+    private Function<String, ProducerBuilder<byte[]>> 
retryLetterProducerBuilder;
+
+    /**
+     * Function to build the producer for the dead letter topic.
+     * The input parameter is the topic name.
+     */
+    private Function<String, ProducerBuilder<byte[]>> 
deadLetterProducerBuilder;

Review Comment:
   Instead of using java.util.function.Function, I'd suggest using a richer 
interface so that more context parameters can be added besides the topic name. 
   
   ```suggestion
       /**
        * Customizer for configuring the producer builder for the retry letter 
topic.
        *
        * <p>This field holds a function that allows the caller to customize 
the producer builder
        * settings for the retry letter topic before the producer is created. 
The customization logic
        * can use the provided context (which includes input topic and 
subscription details) to adjust
        * configurations such as timeouts, batching, or message routing.
        */
       private ProducerBuilderCustomizer retryLetterProducerBuilder;
   
       /**
        * Customizer for configuring the producer builder for the dead letter 
topic.
        *
        * <p>This field holds a function that allows the caller to customize 
the producer builder
        * settings for the dead letter topic before the producer is created. 
Using the provided context,
        * implementations can perform specific adjustments that ensure the dead 
letter queue operates
        * with the appropriate configurations tailored for handling 
undeliverable messages.
        */
       private ProducerBuilderCustomizer deadLetterProducerBuilder;
   
   
       /**
        * Functional interface for customizing a producer builder for a 
specific topic.
        *
        * <p>This interface allows for customizing the producer builder 
configuration for either the retry letter topic
        * or the dead letter topic. The customization might include setting 
producer properties such as batching, timeouts,
        * or any other producer-specific configuration.
        *
        * @see ProducerBuilderContext
        */
       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);
       }
   
       /**
        * Provides context information required for customizing a producer 
builder.
        *
        * <p>This interface supplies relevant details such as the name of the 
input topic and associated subscription name.
        * This contextual information helps in correctly configuring the 
producer for the appropriate topic.
        */
       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();
       }
   ```



-- 
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]

Reply via email to