Skip to content

Commit 7dd3009

Browse files
Merge pull request #1 from apache/master
merge master from apache
2 parents 66d08e9 + 0fbf52a commit 7dd3009

File tree

11 files changed

+443
-2
lines changed

11 files changed

+443
-2
lines changed

CMakeLists.txt

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ if (COMMAND cmake_policy)
3131
cmake_policy(SET CMP0005 NEW)
3232
endif ()
3333

34+
if (POLICY CMP0048)
35+
cmake_policy(SET CMP0048 NEW)
36+
endif ()
37+
38+
if (POLICY CMP0064)
39+
cmake_policy(SET CMP0064 NEW)
40+
endif ()
3441
# First, declare project (important for prerequisite checks).
3542
project(rocketmq-client-python)
3643

@@ -56,7 +63,7 @@ if (NOT CMAKE_BUILD_TYPE)
5663
endif ()
5764

5865
set(CXX_FLAGS
59-
#-std=c++0x
66+
-std=c++11
6067
-g
6168
-Wall
6269
-Wno-deprecated
@@ -151,7 +158,7 @@ option(Boost_USE_STATIC_LIBS "only find boost static libs" OFF) # find boost lib
151158
if (WIN32)
152159
find_package(Boost REQUIRED COMPONENTS python)
153160
elseif (APPLE)
154-
find_package(Boost REQUIRED COMPONENTS python27)
161+
find_package(Boost REQUIRED COMPONENTS python)
155162
else ()
156163
find_package(Boost REQUIRED COMPONENTS python)
157164
endif (WIN32)
@@ -196,4 +203,14 @@ set(STDC_HEADERS 1)
196203
set(TIME_WITH_SYS_TIME 1)
197204
set(HAVE_SOCKLEN_T 1)
198205

206+
option(TEST "Build test cases" OFF)
207+
208+
if (TEST)
209+
enable_testing()
210+
option(gtest_build_tests OFF)
211+
add_subdirectory(third_party/googletest/googletest)
212+
include_directories(SYSTEM ${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})
213+
add_subdirectory(unitests)
214+
endif ()
215+
199216
add_subdirectory(project)

install_boostpython.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/bin/bash
2+
3+
# Licensed to the Apache Software Foundation (ASF) under one or more
4+
# contributor license agreements. See the NOTICE file distributed with
5+
# this work for additional information regarding copyright ownership.
6+
# The ASF licenses this file to You under the Apache License, Version 2.0
7+
# (the "License"); you may not use this file except in compliance with
8+
# the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
VERSION=1.58.0
18+
BOOST=boost_1_58_0
19+
20+
if [ ! -d ${HOME}/${BOOST} ]; then
21+
if [ -e ${HOME}/${BOOST}.tar.gz ]; then
22+
echo "Find Packge ${HOME}/${BOOST}.tar.gz......."
23+
else
24+
wget -O ${HOME}/${BOOST}.tar.gz http://sourceforge.net/projects/boost/files/boost/${VERSION}/${BOOST}.tar.gz
25+
fi
26+
if [ $? -ne 0 ];then
27+
exit 1
28+
fi
29+
tar -xzf ${HOME}/${BOOST}.tar.gz -C ${HOME}
30+
if [ $? -ne 0 ];then
31+
exit 1
32+
fi
33+
else
34+
echo "Find Boost Source:${HOME}/${BOOST}, Build and install....."
35+
fi
36+
37+
cd ${HOME}/${BOOST}
38+
39+
./bootstrap.sh --prefix=/usr/local --with-libraries=python
40+
if [ $? -ne 0 ];then
41+
exit 1
42+
fi
43+
echo "Install boost static library...."
44+
sudo ./bjam cflags="-fPIC" cxxflags="-fPIC -Wno-unused-local-typedefs -Wno-strict-aliasing" link=static \
45+
--with-python \
46+
-a install
47+
if [ $? -ne 0 ];then
48+
exit 1
49+
fi
50+
echo "Install boost dynamic library....."
51+
sudo ./bjam cflags="-fPIC" cxxflags="-fPIC -Wno-unused-local-typedefs -Wno-strict-aliasing" link=shared \
52+
--with-python
53+
-a install

sample/testProducer.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@ def testSendMssage(producer,topic,key,body):
4242
DestroyMessage(msg)
4343
print("Done...............")
4444

45+
def testSendMessageOneway(producer, topic, key, body):
46+
print("Starting Sending(Oneway).....")
47+
msg = CreateMessage(topic)
48+
SetMessageBody(msg, body)
49+
SetMessageKeys(msg, key)
50+
SetMessageTags(msg, "Send Message Oneway Test.")
51+
SendMessageOneway(producer,msg)
52+
DestroyMessage(msg)
53+
print("Done...............")
54+
4555
def releaseProducer(producer):
4656
ShutdownProducer(producer)
4757
DestroyProducer(producer)
@@ -59,4 +69,9 @@ def releaseProducer(producer):
5969

6070
print("Now Send Message:",i)
6171

72+
while i < 10:
73+
i += 1
74+
testSendMessageOneway(producer, topic, key, body)
75+
print("Now Send Message One way:",i)
76+
6277
releaseProducer(producer)

src/PythonWrapper.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ PySendResult PySendMessageSync(void *producer, void *msg) {
133133
return ret;
134134
}
135135

136+
int PySendMessageOneway(void *producer, void *msg) {
137+
return SendMessageOneway((CProducer *) producer, (CMessage *) msg);
138+
}
139+
136140
//SendResult
137141
const char *PyGetSendResultMsgID(CSendResult &sendResult) {
138142
return (const char *) (sendResult.msgId);
@@ -263,6 +267,7 @@ BOOST_PYTHON_MODULE (librocketmqclientpython) {
263267
def("SetProducerInstanceName", PySetProducerInstanceName);
264268
def("SetProducerSessionCredentials", PySetProducerSessionCredentials);
265269
def("SendMessageSync", PySendMessageSync);
270+
def("SendMessageOneway", PySendMessageOneway);
266271

267272
//For Consumer
268273
def("CreatePushConsumer", PyCreatePushConsumer, return_value_policy<return_opaque_pointer>());

src/PythonWrapper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ int PySetProducerNameServerAddress(void *producer, const char *namesrv);
7474
int PySetProducerInstanceName(void *producer, const char *instanceName);
7575
int PySetProducerSessionCredentials(void *producer, const char *accessKey, const char *secretKey, const char *channel);
7676
PySendResult PySendMessageSync(void *producer, void *msg);
77+
int PySendMessageOneway(void *producer, void *msg);
7778

7879
//sendResult
7980
const char *PyGetSendResultMsgID(CSendResult &sendResult);

test/TestConsumeMessages.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# /*
2+
# * Licensed to the Apache Software Foundation (ASF) under one or more
3+
# * contributor license agreements. See the NOTICE file distributed with
4+
# * this work for additional information regarding copyright ownership.
5+
# * The ASF licenses this file to You under the Apache License, Version 2.0
6+
# * (the "License"); you may not use this file except in compliance with
7+
# * the License. You may obtain a copy of the License at
8+
# *
9+
# * http://www.apache.org/licenses/LICENSE-2.0
10+
# *
11+
# * Unless required by applicable law or agreed to in writing, software
12+
# * distributed under the License is distributed on an "AS IS" BASIS,
13+
# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# * See the License for the specific language governing permissions and
15+
# * limitations under the License.
16+
# */
17+
18+
import __init__
19+
from librocketmqclientpython import *
20+
21+
import time
22+
import sys
23+
24+
topic = 'test'
25+
name_srv = '127.0.0.1:9876'
26+
tag = 'rmq-tag'
27+
consumer_group = 'test-consumer-group'
28+
totalMsg = 0
29+
30+
31+
def sigint_handler(signum, frame):
32+
global is_sigint_up
33+
is_sigint_up = True
34+
sys.exit(0)
35+
36+
37+
def consumer_message(msg):
38+
global totalMsg
39+
totalMsg += 1
40+
print 'total count %d' % totalMsg
41+
print 'topic=%s' % GetMessageTopic(msg)
42+
print 'tag=%s' % GetMessageTags(msg)
43+
print 'body=%s' % GetMessageBody(msg)
44+
print 'msg id=%s' % GetMessageId(msg)
45+
46+
print 'map.keys %s' % GetMessageKeys(msg)
47+
48+
print 'map.name %s' % GetMessageProperty(msg, 'name')
49+
print 'map.id %s' % GetMessageProperty(msg, 'id')
50+
return 0
51+
52+
53+
def init_producer(_group, _topic, _tag):
54+
consumer = CreatePushConsumer(_group)
55+
SetPushConsumerNameServerAddress(consumer, name_srv)
56+
SetPushConsumerThreadCount(consumer, 1)
57+
Subscribe(consumer, _topic, _tag)
58+
RegisterMessageCallback(consumer, consumerMessage)
59+
StartPushConsumer(consumer)
60+
print 'consumer is ready...'
61+
return consumer
62+
63+
64+
def start_one_consumer(_group, _topic, _tag):
65+
consumer = init_producer(_group, _topic, _tag)
66+
i = 1
67+
while i <= 10:
68+
print 'clock: ' + str(i)
69+
i += 1
70+
time.sleep(10)
71+
72+
ShutdownPushConsumer(consumer)
73+
DestroyPushConsumer(consumer)
74+
print("Consumer Down....")
75+
76+
77+
if __name__ == '__main__':
78+
start_one_consumer(consumer_group, topic, '*')

0 commit comments

Comments
 (0)