BewareMyPower commented on code in PR #17256:
URL: https://github.com/apache/pulsar/pull/17256#discussion_r989028068


##########
pulsar-client/src/main/java/org/apache/pulsar/client/impl/TypedMessageBuilderImpl.java:
##########
@@ -105,14 +106,12 @@ public CompletableFuture<MessageId> sendAsync() {
 
     @Override
     public TypedMessageBuilder<T> key(String key) {
-        if (schema.getSchemaInfo().getType() == SchemaType.KEY_VALUE) {
-            KeyValueSchemaImpl kvSchema = (KeyValueSchemaImpl) schema;
-            checkArgument(kvSchema.getKeyValueEncodingType() != 
KeyValueEncodingType.SEPARATED,
-                    "This method is not allowed to set keys when in encoding 
type is SEPARATED");
-            if (key == null) {
-                msgMetadata.setNullPartitionKey(true);
-                return this;
-            }
+        getKeyValueSchema().ifPresent(keyValueSchema -> checkArgument(

Review Comment:
   Because the schema type is `Schema<KeyValue<K, V>>`, the value's type must 
be `KeyValue<K, V>`, then the code will look like:
   
   ```java
   .key("key")
   .value(new KeyValue<>("key-1", "value"))
   ```
   
   The root cause is that Pulsar only stores the schema of the value. So it can 
only support key schema by passing a pair of "key" and "value" as the whole 
value.



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