AnonHxy commented on code in PR #20481:
URL: https://github.com/apache/pulsar/pull/20481#discussion_r1219676986


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java:
##########
@@ -3119,9 +3120,11 @@ private Response generateResponseWithEntry(Entry entry) 
throws IOException {
 
         ResponseBuilder responseBuilder = Response.ok();
         responseBuilder.header("X-Pulsar-Message-ID", pos.toString());
-        for (KeyValue keyValue : metadata.getPropertiesList()) {
-            responseBuilder.header("X-Pulsar-PROPERTY-" + keyValue.getKey(), 
keyValue.getValue());
-        }
+
+        Map<String, String> properties = metadata.getPropertiesList().stream()
+                .collect(Collectors.toMap(KeyValue::getKey, 
KeyValue::getValue, (v1, v2) -> v2));
+        responseBuilder.header("X-Pulsar-PROPERTY", JSON.toString(properties));
+

Review Comment:
   Note that we will lost the `X-Pulsar-PROPERTY-*` in the message properties, 
for details:
   
   
https://github.com/apache/pulsar/blob/d7f355881b2b1eebf2be6ea262c202660d684fb7/pulsar-client-admin/src/main/java/org/apache/pulsar/client/admin/internal/TopicsImpl.java#L1392-L1398
   
   IMO, we should also change the `TopicsImpl.java` to put the new added 
`X-Pulsar-PROPERTY`  into message's properties



##########
pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/PersistentTopicsTest.java:
##########
@@ -1386,6 +1386,27 @@ public void testGetMessageById() throws Exception {
         }
     }
 
+    @Test
+    public void testGetMessageById4SpecialPropsInMsg() throws Exception {
+        TenantInfoImpl tenantInfo = new TenantInfoImpl(Set.of("role1", 
"role2"), Set.of("test"));
+        admin.tenants().createTenant("tenant-xyz", tenantInfo);
+        admin.namespaces().createNamespace("tenant-xyz/ns-abc", 
Set.of("test"));
+        final String topicName1 = 
"persistent://tenant-xyz/ns-abc/testGetMessageById1";
+        admin.topics().createNonPartitionedTopic(topicName1);
+        Map<String, String> specialProps = new HashMap<>();
+        specialProps.put("city=shanghai", "tag");
+        specialProps.put("city,beijing", "haidian");
+        @Cleanup
+        ProducerBase<byte[]> producer1 = (ProducerBase<byte[]>) 
pulsarClient.newProducer().topic(topicName1)
+                .enableBatching(false).create();
+        String data1 = "test1";
+        MessageIdImpl id1 = (MessageIdImpl) 
producer1.newMessage().value(data1.getBytes()).properties(specialProps)
+                .send();
+
+        Message<byte[]> message1 = admin.topics().getMessageById(topicName1, 
id1.getLedgerId(), id1.getEntryId());
+        Assert.assertEquals(message1.getData(), data1.getBytes());

Review Comment:
   We should verify the message.properties to make sure `X-Pulsar-PROPERTY` is 
in the message.properties



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