-
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-162]Python SDK support in TubeMQ (#303)
* [TUBEMQ-260] Init Python client module (#201) Co-authored-by: dockerzhang(张超) <dockerzhang@tencent.com> * [TUBEMQ-276] add python client encode/decode protobuf message for TubeMQ RPC Protocol (#203) Co-authored-by: dockerzhang(张超) <dockerzhang@tencent.com> * [TUBEMQ-398] reinit project for using pybind11 (#298) Co-authored-by: dockerzhang <dockerzhang@tencent.com> * [TUBEMQ-399] expose C++ SDK method by Pybind11 (#299) Co-authored-by: dockerzhang <dockerzhang@tencent.com> * [TUBEMQ-400] add example for consume message (#300) Co-authored-by: dockerzhang <dockerzhang@tencent.com> * [TUBEMQ-383] add readme for installation and example (#301) Co-authored-by: dockerzhang <dockerzhang@tencent.com> * [TUBEMQ-401] fix readme bug (#302) Co-authored-by: dockerzhang <dockerzhang@tencent.com> Co-authored-by: dockerzhang <zhchao_beyond@outlook.com> Co-authored-by: dockerzhang(张超) <dockerzhang@tencent.com>
- Loading branch information
1 parent
b433ceb
commit f64863d
Showing
15 changed files
with
565 additions
and
1 deletion.
There are no files selected for viewing
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
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,44 @@ | ||
# | ||
# 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. | ||
# | ||
|
||
version: '{build}' | ||
image: Visual Studio 2015 | ||
platform: | ||
- x86 | ||
- x64 | ||
environment: | ||
global: | ||
DISTUTILS_USE_SDK: 1 | ||
PYTHONWARNINGS: ignore:DEPRECATION | ||
MSSdk: 1 | ||
matrix: | ||
- PYTHON: 27 | ||
- PYTHON: 36 | ||
install: | ||
- cmd: '"%VS140COMNTOOLS%\..\..\VC\vcvarsall.bat" %PLATFORM%' | ||
- ps: | | ||
if ($env:PLATFORM -eq "x64") { $env:PYTHON = "$env:PYTHON-x64" } | ||
$env:PATH = "C:\Python$env:PYTHON\;C:\Python$env:PYTHON\Scripts\;$env:PATH" | ||
python -m pip install --disable-pip-version-check --upgrade --no-warn-script-location pip build | ||
build_script: | ||
- ps: | | ||
python -m build -s | ||
cd dist | ||
python -m pip install --verbose tubemq-client-0.0.1.tar.gz | ||
cd .. |
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,30 @@ | ||
### TubeMQ Python Client | ||
TubeMQ Python Client library is a wrapper over the existing [C++ client library](https://github.com/apache/incubator-tubemq/tree/master/tubemq-client-twins/tubemq-client-cpp/) and exposes all of the same features. | ||
|
||
#### Install from source | ||
##### install python-devel | ||
- build and install C++ client SDK | ||
|
||
build C++ client SDK from source, and install: | ||
1, copy `tubemq` include directory to `/usr/local/include/` | ||
2, copy `libtubemq_rel.a` to `/usr/local/lib` | ||
| ||
|
||
- install python-devel | ||
``` | ||
yum install python-devel -y | ||
``` | ||
- install required dependency | ||
``` | ||
pip install -r requirements.txt | ||
``` | ||
|
||
- install client | ||
``` | ||
pip install ./ | ||
``` | ||
|
||
#### Examples | ||
##### Producer example | ||
##### Consumer example | ||
Consumer example is [available](https://github.com/apache/incubator-tubemq/tree/tubemq-client-python/tubemq-client-twins/tubemq-client-python/src/python/example/consumer). |
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,18 @@ | ||
# | ||
# 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. | ||
# |
53 changes: 53 additions & 0 deletions
53
tubemq-client-twins/tubemq-client-python/conda.recipe/meta.yaml
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,53 @@ | ||
# | ||
# 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. | ||
# | ||
|
||
package: | ||
name: tubemq-client | ||
version: 0.0.1 | ||
|
||
source: | ||
path: .. | ||
|
||
build: | ||
number: 0 | ||
script: python -m pip install . -vvv | ||
|
||
requirements: | ||
build: | ||
- {{ compiler('cxx') }} | ||
|
||
host: | ||
- python | ||
- pip | ||
- pybind11 >=2.6.0 | ||
|
||
run: | ||
- python | ||
|
||
|
||
test: | ||
imports: | ||
- tubemq-client | ||
source_files: | ||
- tests | ||
commands: | ||
- python tests/test_comsumer.py | ||
|
||
about: | ||
summary: TubeMQ Python SDK Client project built with pybind11. |
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,20 @@ | ||
# | ||
# 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. | ||
# | ||
|
||
pybind11==2.6.0 |
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,48 @@ | ||
# | ||
# 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. | ||
# | ||
|
||
from pybind11.setup_helpers import Pybind11Extension, build_ext | ||
from glob import glob | ||
from setuptools import setup | ||
|
||
import sys | ||
|
||
__version__ = "0.0.1" | ||
|
||
ext_modules = [ | ||
Pybind11Extension("tubemq_client", | ||
sorted(glob("src/cpp/*.cc")), | ||
cxx_std=11, | ||
define_macros=[('VERSION_INFO', __version__)], | ||
) | ||
] | ||
|
||
setup( | ||
name="tubemq-client", | ||
version=__version__, | ||
author="dockerzhang", | ||
author_email="dockerzhang@apache.org", | ||
url="https://github.com/apache/incubator-tubemq/tree/tubemq-client-python", | ||
description="TubeMq Python SDK Client project built with pybind11", | ||
long_description="", | ||
ext_modules=ext_modules, | ||
extras_require={"test": "pytest"}, | ||
cmdclass={"build_ext": build_ext}, | ||
zip_safe=False, | ||
) |
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); | ||
} |
Oops, something went wrong.