-
Notifications
You must be signed in to change notification settings - Fork 533
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TUBEMQ-399] expose C++ SDK method by Pybind11 (#299)
Co-authored-by: dockerzhang <dockerzhang@tencent.com>
- Loading branch information
1 parent
831f2e8
commit 0981ae2
Showing
5 changed files
with
226 additions
and
0 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
tubemq-client-twins/tubemq-client-python/src/cpp/tubemq_client.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
#include <pybind11/pybind11.h> | ||
#include "tubemq/tubemq_client.h" | ||
|
||
namespace py = pybind11; | ||
|
||
using namespace tubemq; | ||
using std::string; | ||
|
||
PYBIND11_MODULE(tubemq_client, m) { | ||
m.def("startTubeMQService", &StartTubeMQService, "start TubeMQ Service"); | ||
m.def("stopTubeMQService", &StopTubeMQService, "stop TubeMQ Service"); | ||
|
||
py::class_<TubeMQConsumer>(m, "TubeMQConsumer") | ||
.def(py::init<>()) | ||
.def("start", &TubeMQConsumer::Start) | ||
.def("shutDown", &TubeMQConsumer::ShutDown) | ||
.def("getClientId", &TubeMQConsumer::GetClientId) | ||
.def("getMessage", &TubeMQConsumer::GetMessage) | ||
.def("confirm", &TubeMQConsumer::Confirm) | ||
.def("getCurConsumedInfo", &TubeMQConsumer::GetCurConsumedInfo); | ||
} |
42 changes: 42 additions & 0 deletions
42
tubemq-client-twins/tubemq-client-python/src/cpp/tubemq_config.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
#include <pybind11/pybind11.h> | ||
#include <pybind11/stl.h> | ||
#include "tubemq/tubemq_config.h" | ||
|
||
namespace py = pybind11; | ||
|
||
using namespace tubemq; | ||
using std::map; | ||
using std::set; | ||
using std::string; | ||
|
||
PYBIND11_MODULE(tubemq_config, m) { | ||
py::class_<ConsumerConfig>(m, "ConsumerConfig") | ||
.def(py::init<>()) | ||
.def("setRpcReadTimeoutMs", &ConsumerConfig::SetRpcReadTimeoutMs) | ||
.def("setMasterAddrInfo", &ConsumerConfig::SetMasterAddrInfo) | ||
.def("setGroupConsumeTarget", static_cast<bool (ConsumerConfig::*)\ | ||
(string&, const string&, const set<string>&)>(&ConsumerConfig::SetGroupConsumeTarget), "") | ||
.def("setGroupConsumeTarget", static_cast<bool (ConsumerConfig::*)\ | ||
(string&, const string&, const map<string, set<string>>&)>(&ConsumerConfig::SetGroupConsumeTarget), "") | ||
.def("getRpcReadTimeoutMs", &ConsumerConfig::GetRpcReadTimeoutMs) | ||
.def("getMasterAddrInfo", &ConsumerConfig::GetMasterAddrInfo); | ||
} |
58 changes: 58 additions & 0 deletions
58
tubemq-client-twins/tubemq-client-python/src/cpp/tubemq_errcode.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
#include <pybind11/pybind11.h> | ||
#include "tubemq/tubemq_errcode.h" | ||
|
||
namespace py = pybind11; | ||
|
||
using namespace tubemq; | ||
using namespace tubemq::err_code; | ||
using std::string; | ||
|
||
PYBIND11_MODULE(tubemq_errcode, m) { | ||
py::enum_<Result>(m, "Result") | ||
.value("kErrSuccess", Result::kErrSuccess) | ||
.value("kErrNotReady", Result::kErrNotReady) | ||
.value("kErrMoved", Result::kErrMoved) | ||
.value("kErrBadRequest", Result::kErrBadRequest) | ||
.value("kErrUnAuthorized", Result::kErrUnAuthorized) | ||
.value("kErrForbidden", Result::kErrForbidden) | ||
.value("kErrNotFound", Result::kErrNotFound) | ||
.value("kErrNoPartAssigned", Result::kErrNoPartAssigned) | ||
.value("kErrAllPartWaiting", Result::kErrAllPartWaiting) | ||
.value("kErrAllPartInUse", Result::kErrAllPartInUse) | ||
.value("kErrPartitionOccupied", Result::kErrPartitionOccupied) | ||
.value("kErrHbNoNode", Result::kErrHbNoNode) | ||
.value("kErrDuplicatePartition", Result::kErrDuplicatePartition) | ||
.value("kErrCertificateFailure", Result::kErrCertificateFailure) | ||
.value("kErrServerOverflow", Result::kErrServerOverflow) | ||
.value("kErrConsumeGroupForbidden", Result::kErrConsumeGroupForbidden) | ||
.value("kErrConsumeSpeedLimit", Result::kErrConsumeSpeedLimit) | ||
.value("kErrConsumeContentForbidden", Result::kErrConsumeContentForbidden) | ||
.export_values(); | ||
|
||
py::class_<ErrorCode>(m, "ErrorCode") | ||
.def(py::init<>()) | ||
.def(py::init<int, const string&>()) | ||
.def("clear", &ErrorCode::Clear) | ||
.def("assign", &ErrorCode::Assign) | ||
.def("value", &ErrorCode::Value) | ||
.def("message", &ErrorCode::Message); | ||
} |
40 changes: 40 additions & 0 deletions
40
tubemq-client-twins/tubemq-client-python/src/cpp/tubemq_message.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
#include <pybind11/pybind11.h> | ||
#include <stdint.h> | ||
#include "tubemq/tubemq_message.h" | ||
|
||
namespace py = pybind11; | ||
|
||
using namespace tubemq; | ||
using std::string; | ||
|
||
PYBIND11_MODULE(tubemq_message, m) { | ||
py::class_<Message>(m, "Message") | ||
.def(py::init<>()) | ||
.def(py::init<const Message&>()) | ||
.def(py::init<const string&, const char*, uint32_t>()) | ||
.def("getMessageId", &Message::GetMessageId) | ||
.def("setMessageId", &Message::SetMessageId) | ||
.def("getTopic", &Message::GetTopic) | ||
.def("setTopic", &Message::SetTopic) | ||
.def("getData", &Message::GetData) | ||
.def("getDataLength", &Message::GetDataLength); | ||
} |
46 changes: 46 additions & 0 deletions
46
tubemq-client-twins/tubemq-client-python/src/cpp/tubemq_return.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
#include <pybind11/pybind11.h> | ||
#include <pybind11/stl.h> | ||
#include <stdlib.h> | ||
#include "tubemq/tubemq_return.h" | ||
|
||
namespace py = pybind11; | ||
|
||
using namespace tubemq; | ||
using std::string; | ||
|
||
PYBIND11_MODULE(tubemq_return, m) { | ||
py::class_<ConsumerResult>(m, "ConsumerResult") | ||
.def(py::init<>()) | ||
.def(py::init<const ConsumerResult&>()) | ||
.def(py::init<int32_t, string>()) | ||
.def("setFailureResult", static_cast<void (ConsumerResult::*)\ | ||
(int32_t, string)>(&ConsumerResult::SetFailureResult), "set Failure Result") | ||
.def("isSuccess", &ConsumerResult::IsSuccess) | ||
.def("getErrCode", &ConsumerResult::GetErrCode) | ||
.def("getErrMessage", &ConsumerResult::GetErrMessage) | ||
.def("getTopicName", &ConsumerResult::GetTopicName) | ||
.def("getPeerInfo", &ConsumerResult::GetPeerInfo) | ||
.def("getConfirmContext", &ConsumerResult::GetConfirmContext) | ||
.def("getMessageList", &ConsumerResult::GetMessageList) | ||
.def("getPartitionKey", &ConsumerResult::GetPartitionKey) | ||
.def("getCurrOffset", &ConsumerResult::GetCurrOffset); | ||
} |