RobertIndie commented on a change in pull request #14726:
URL: https://github.com/apache/pulsar/pull/14726#discussion_r830883331



##########
File path: 
pulsar-client/src/main/java/org/apache/pulsar/client/impl/ProducerBuilderImpl.java
##########
@@ -349,14 +349,24 @@ private ProducerBuilderImpl(PulsarClientImpl client, 
ProducerConfigurationData c
     private void setMessageRoutingMode() throws PulsarClientException {
         if (conf.getMessageRoutingMode() == null && 
conf.getCustomMessageRouter() == null) {
             messageRoutingMode(MessageRoutingMode.RoundRobinPartition);
-        } else if (conf.getMessageRoutingMode() == null && 
conf.getCustomMessageRouter() != null) {
+            return;
+        }
+        if (conf.getCustomMessageRouter() == null) {
+            checkMessageRoutingModeValid(conf.getMessageRoutingMode() != 
MessageRoutingMode.CustomPartition,
+                    "When 'messageRouter' is null, 'messageRoutingMode' should 
not be set as "
+                            + MessageRoutingMode.CustomPartition);
+        } else {
+            checkMessageRoutingModeValid(conf.getMessageRoutingMode() == null
+                            || conf.getMessageRoutingMode() == 
MessageRoutingMode.CustomPartition,
+                    "When 'messageRouter' is set, 'messageRoutingMode' should 
be set as "
+                            + MessageRoutingMode.CustomPartition);
             messageRoutingMode(MessageRoutingMode.CustomPartition);
-        } else if ((conf.getMessageRoutingMode() == 
MessageRoutingMode.CustomPartition
-                && conf.getCustomMessageRouter() == null)
-                || (conf.getMessageRoutingMode() != 
MessageRoutingMode.CustomPartition
-                && conf.getCustomMessageRouter() != null)) {
-            throw new PulsarClientException("When 'messageRouter' is set, 
'messageRoutingMode' "
-                    + "should be set as " + 
MessageRoutingMode.CustomPartition);
+        }
+    }
+
+    private void checkMessageRoutingModeValid(boolean expression, String 
errorMessage) throws PulsarClientException {

Review comment:
       It doesn't make sense that there is no specific checking logic in 
`checkMessageRoutingModeValid`.




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