This is an automated email from the ASF dual-hosted git repository.
gosonzhang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-tubemq.git
The following commit(s) were added to refs/heads/master by this push:
new 3a03ba1 [TUBEMQ-420] python client support parse message from binary
data for Python SDK based on pybind11 (#321)
3a03ba1 is described below
commit 3a03ba1441cb0ab2d87d6a7ae383893d6c1a126a
Author: dockerzhang <[email protected]>
AuthorDate: Sun Nov 22 07:43:22 2020 +0800
[TUBEMQ-420] python client support parse message from binary data for
Python SDK based on pybind11 (#321)
Co-authored-by: dockerzhang <[email protected]>
---
.../tubemq-client-python/src/cpp/tubemq_message.cc | 14 +++++++++++++-
.../src/python/example/test_consumer.py | 17 +++++++++++++----
2 files changed, 26 insertions(+), 5 deletions(-)
diff --git a/tubemq-client-twins/tubemq-client-python/src/cpp/tubemq_message.cc
b/tubemq-client-twins/tubemq-client-python/src/cpp/tubemq_message.cc
index 1ff5106..44cb936 100644
--- a/tubemq-client-twins/tubemq-client-python/src/cpp/tubemq_message.cc
+++ b/tubemq-client-twins/tubemq-client-python/src/cpp/tubemq_message.cc
@@ -18,13 +18,17 @@
*/
#include <pybind11/pybind11.h>
+#include <pybind11/stl.h>
#include <stdint.h>
+#include <stdio.h>
+
#include "tubemq/tubemq_message.h"
namespace py = pybind11;
using namespace tubemq;
using std::string;
+using std::map;
PYBIND11_MODULE(tubemq_message, m) {
py::class_<Message>(m, "Message")
@@ -36,5 +40,13 @@ PYBIND11_MODULE(tubemq_message, m) {
.def("getTopic", &Message::GetTopic)
.def("setTopic", &Message::SetTopic)
.def("getData", &Message::GetData)
- .def("getDataLength", &Message::GetDataLength);
+ .def("getDataLength", &Message::GetDataLength)
+ .def("getVectorData", &Message::GetVectorData)
+ .def("getFlag", &Message::GetFlag)
+ .def("setFlag", &Message::SetFlag)
+ .def("getProperties", &Message::GetProperties)
+ .def("hasProperty", &Message::HasProperty)
+ .def("getProperty", &Message::GetProperty)
+ .def("getFilterItem", &Message::GetFilterItem)
+ .def("addProperty", &Message::AddProperty);
}
\ No newline at end of file
diff --git
a/tubemq-client-twins/tubemq-client-python/src/python/example/test_consumer.py
b/tubemq-client-twins/tubemq-client-python/src/python/example/test_consumer.py
index a08edbf..7c141f2 100644
---
a/tubemq-client-twins/tubemq-client-python/src/python/example/test_consumer.py
+++
b/tubemq-client-twins/tubemq-client-python/src/python/example/test_consumer.py
@@ -30,10 +30,19 @@ consumer = tubemq.consumer(master_addr, group_name,
topic_list)
# Test consumer
start_time = time.time()
while True:
- msgs = consumer.receive()
- if msgs:
- print("GetMessage success, msssage count =", len(msgs))
- consumer.acknowledge()
+ messageList = consumer.receive()
+ if messageList:
+ print("GetMessage success, msssage count =", len(messageList))
+ for message in messageList:
+ attributeMap = message.getProperties()
+ attribute = ''
+ for (key, value) in attributeMap.items():
+ attribute = attribute + key + '=' + value + ','
+ attribute = attribute[:-1]
+ rawMsgList = message.getVectorData()
+ print("GetMessage success, raw message byte count =",
len(rawMsgList))
+ msgLen = message.getDataLength()
+ print("GetMessage success, raw message length =", len(rawMsgList))
# used for test, consume 10 minutes only
stop_time = time.time()