BewareMyPower commented on issue #12087:
URL: https://github.com/apache/pulsar/issues/12087#issuecomment-922235898


   There're something in addition to the implementation.
   
   Before this proposal, I tried to add following method.
   
   ```java
       /**
        * Set the payload converter class.
        *
        * The class must implement 
org.apache.pulsar.common.api.raw.PayloadConverter in pulsar-common module. 
Otherwise,
        * this method will fail silently. If this method was called 
successfully, each time a message arrived, the raw
        * payload will be replaced by a new payload returned by 
PayloadConverter#convert(ByteBuf).
        *
        * @param clazz
        * @return
        */
       ConsumerBuilder<T> payloadConverterClass(Class<?> clazz);
   ```
   
   It's simple but looks ugly. After discussing with @codelipenghui, I adopted 
the current way to load converter at runtime. But there's something different. 
@codelipenghui's original opinion was that no changes should be made for client 
configs like `ConsumerBuilder`. However, there're some flaws for this solution. 
Because reflection brings overhead when creating a consumer. Though the 
overhead might not be significant, we should still avoid it for the regular 
cases.
   
   I've thought of another solution that all consumers share the same converter 
so that the class loader could only be called once. But it might become 
complicated if there're multiple entry formats. For example, assuming we've 
enabled KoP, AoP, MoP for the same broker and there're three different entry 
formats. With PIP 96, we can implement three converters like:
   
   - org.apache.pulsar.client.converter.kop.KafkaPayloadConverter
   - org.apache.pulsar.client.converter.aop.AmqpPayloadConverter
   - org.apache.pulsar.client.converter.mop.MqttPayloadConverter
   
   Then we can create three consumers using a common `PulsarClient`. It's also 
why I configured the converter package at consumer level instead of client 
level.


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