pulsar-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mme...@apache.org
Subject [pulsar] branch master updated: Fixed getting message properties map in Python client (#3595)
Date Thu, 14 Feb 2019 04:03:06 GMT
This is an automated email from the ASF dual-hosted git repository.

mmerli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git


The following commit(s) were added to refs/heads/master by this push:
     new 01f0d35  Fixed getting message properties map in Python client (#3595)
01f0d35 is described below

commit 01f0d350121581f21121d7e01b11118dc7021968
Author: Matteo Merli <mmerli@apache.org>
AuthorDate: Wed Feb 13 20:03:01 2019 -0800

    Fixed getting message properties map in Python client (#3595)
---
 pulsar-client-cpp/python/pulsar_test.py | 25 +++++++++++++++++++++++++
 pulsar-client-cpp/python/src/message.cc | 10 +++++++++-
 2 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/pulsar-client-cpp/python/pulsar_test.py b/pulsar-client-cpp/python/pulsar_test.py
index 8710350..8467dc3 100755
--- a/pulsar-client-cpp/python/pulsar_test.py
+++ b/pulsar-client-cpp/python/pulsar_test.py
@@ -140,6 +140,31 @@ class PulsarTest(TestCase):
         consumer.unsubscribe()
         client.close()
 
+    def test_message_properties(self):
+        client = Client(self.serviceUrl)
+        topic = 'my-python-test-message-properties'
+        consumer = client.subscribe(topic=topic,
+                                    subscription_name='my-subscription',
+                                    schema=pulsar.schema.StringSchema())
+        producer = client.create_producer(topic=topic,
+                                          schema=StringSchema())
+        producer.send('hello',
+                      properties={
+                          'a': '1',
+                          'b': '2'
+                      })
+
+        msg = consumer.receive()
+        self.assertTrue(msg)
+        self.assertEqual(msg.value(), 'hello')
+        self.assertEqual(msg.properties(), {
+                          'a': '1',
+                          'b': '2'
+                      })
+
+        consumer.unsubscribe()
+        client.close()
+
     def test_tls_auth(self):
         certs_dir = '/pulsar/pulsar-broker/src/test/resources/authentication/tls/'
         if not os.path.exists(certs_dir):
diff --git a/pulsar-client-cpp/python/src/message.cc b/pulsar-client-cpp/python/src/message.cc
index 6cff712..19aa7bb 100644
--- a/pulsar-client-cpp/python/src/message.cc
+++ b/pulsar-client-cpp/python/src/message.cc
@@ -66,6 +66,14 @@ boost::python::object Message_data(const Message& msg) {
     return boost::python::object(boost::python::handle<>(PyBytes_FromStringAndSize((const
char*)msg.getData(), msg.getLength())));
 }
 
+boost::python::object Message_properties(const Message& msg) {
+    boost::python::dict pyProperties;
+    for (const auto& item : msg.getProperties()) {
+        pyProperties[item.first] = item.second;
+    }
+    return pyProperties;
+}
+
 std::string Topic_name_str(const Message& msg) {
     std::stringstream ss;
     ss << msg.getTopicName();
@@ -115,7 +123,7 @@ void export_message() {
             ;
 
     class_<Message>("Message")
-            .def("properties", &Message::getProperties, return_value_policy<copy_const_reference>())
+            .def("properties", &Message_properties)
             .def("data", &Message_data)
             .def("length", &Message::getLength)
             .def("partition_key", &Message::getPartitionKey, return_value_policy<copy_const_reference>())


Mime
View raw message