rdhabalia commented on a change in pull request #11728:
URL: https://github.com/apache/pulsar/pull/11728#discussion_r693282904



##########
File path: 
pulsar-client/src/main/java/org/apache/pulsar/client/impl/PartitionedProducerImpl.java
##########
@@ -93,6 +98,19 @@ private MessageRouter getMessageRouter() {
 
         switch (messageRouteMode) {
             case CustomPartition:
+                String messageRouterClassName = 
conf.getMessageRouterClassName();
+                if (isNotBlank(messageRouterClassName)) {
+                    Class<?> clazz;
+                    try {
+                        clazz = Class.forName(messageRouterClassName);
+                        messageRouter = (MessageRouter) 
clazz.getDeclaredConstructor().newInstance();
+                        conf.setCustomMessageRouter(messageRouter);
+                    } catch (ClassNotFoundException | NoSuchMethodException | 
InvocationTargetException |
+                            InstantiationException | IllegalAccessException | 
ClassCastException e) {
+                        log.error("[{}] Error occurred while instantiating the 
messageRouterClassName",
+                                messageRouterClassName, new 
PulsarClientException(e));
+                    }

Review comment:
       and yes, we should not eat the exception rather fail the producer 
creation.

##########
File path: 
pulsar-client/src/main/java/org/apache/pulsar/client/impl/PartitionedProducerImpl.java
##########
@@ -93,6 +98,19 @@ private MessageRouter getMessageRouter() {
 
         switch (messageRouteMode) {
             case CustomPartition:
+                String messageRouterClassName = 
conf.getMessageRouterClassName();
+                if (isNotBlank(messageRouterClassName)) {
+                    Class<?> clazz;
+                    try {
+                        clazz = Class.forName(messageRouterClassName);
+                        messageRouter = (MessageRouter) 
clazz.getDeclaredConstructor().newInstance();
+                        conf.setCustomMessageRouter(messageRouter);
+                    } catch (ClassNotFoundException | NoSuchMethodException | 
InvocationTargetException |
+                            InstantiationException | IllegalAccessException | 
ClassCastException e) {
+                        log.error("[{}] Error occurred while instantiating the 
messageRouterClassName",
+                                messageRouterClassName, new 
PulsarClientException(e));

Review comment:
       should not create wrapper PulsarClientException.

##########
File path: 
pulsar-client/src/main/java/org/apache/pulsar/client/impl/conf/ProducerConfigurationData.java
##########
@@ -64,6 +64,7 @@
     private int maxPendingMessages = DEFAULT_MAX_PENDING_MESSAGES;
     private int maxPendingMessagesAcrossPartitions = 
DEFAULT_MAX_PENDING_MESSAGES_ACROSS_PARTITIONS;
     private MessageRoutingMode messageRoutingMode = null;
+    private String messageRouterClassName = null;

Review comment:
       instead having `messageRouterClassName`, we should have factory-class 
name with param properties so, one can initialize with custom value based on 
the environemnt.




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