├── .asf.yaml ├── .clang-format ├── .github └── ISSUE_TEMPLATE │ └── issue_template.md ├── .gitignore ├── .travis.yml ├── .travis ├── check-git-clang-format.sh └── git-clang-format ├── CMakeLists.txt ├── CONTRIBUTING.md ├── LICENSE ├── NOTICE ├── PULL_REQUEST_TEMPLATE.md ├── README.md ├── Win32 ├── rocketmq-client-cpp.sln ├── rocketmq-client-cpp.vcxproj └── rocketmq-client-cpp.vcxproj.filters ├── build.sh ├── cmake ├── FindJsoncpp.cmake └── FindLibevent.cmake ├── dep ├── build.sh └── rocketmq_amd64 │ └── DEBIAN │ ├── control │ └── postinst ├── distribution └── deploy.sh ├── example ├── AsyncProducer.cpp ├── AsyncPushConsumer.cpp ├── BatchProducer.cpp ├── CAsyncProducer.c ├── CBatchProducer.c ├── CMakeLists.txt ├── COrderlyAsyncProducer.c ├── OrderProducer.cpp ├── OrderlyPushConsumer.cpp ├── Producer.c ├── PullConsumeMessage.c ├── PullConsumer.cpp ├── PushConsumeMessage.c ├── PushConsumer.cpp ├── PushConsumerOrderly.c ├── README.md ├── SendDelayMsg.cpp ├── SyncProducer.cpp ├── TransactionProducer.cpp └── common.h ├── format.sh ├── include ├── Arg_helper.h ├── AsyncCallback.h ├── CBatchMessage.h ├── CCommon.h ├── CErrorMessage.h ├── CMQException.h ├── CMessage.h ├── CMessageExt.h ├── CMessageQueue.h ├── CProducer.h ├── CPullConsumer.h ├── CPullResult.h ├── CPushConsumer.h ├── CSendResult.h ├── CTransactionStatus.h ├── ConsumeType.h ├── DefaultMQProducer.h ├── DefaultMQPullConsumer.h ├── DefaultMQPushConsumer.h ├── MQClient.h ├── MQClientException.h ├── MQMessage.h ├── MQMessageExt.h ├── MQMessageListener.h ├── MQMessageQueue.h ├── MQSelector.h ├── MQueueListener.h ├── PullResult.h ├── RocketMQClient.h ├── SendResult.h ├── SessionCredentials.h ├── TransactionListener.h ├── TransactionMQProducer.h └── TransactionSendResult.h ├── libs ├── CMakeLists.txt └── signature │ ├── CMakeLists.txt │ ├── include │ ├── base64.h │ ├── hmac.h │ ├── param_list.h │ ├── sha1.h │ ├── sha256.h │ ├── sha512.h │ ├── spas_client.h │ └── u64.h │ └── src │ ├── base64.c │ ├── hmac.c │ ├── param_list.c │ ├── sha1.c │ ├── sha256.c │ ├── sha512.c │ └── spas_client.c ├── package_rocketmq.mri ├── project └── CMakeLists.txt ├── rpm ├── build.sh └── rocketmq_x64 │ └── CENTOS │ └── rocketmq-client-cpp.spec ├── src ├── MQClientAPIImpl.cpp ├── MQClientAPIImpl.h ├── MQClientFactory.cpp ├── MQClientFactory.h ├── MQClientManager.cpp ├── MQClientManager.h ├── common │ ├── Arg_helper.cpp │ ├── AsyncArg.h │ ├── AsyncCallbackWrap.cpp │ ├── AsyncCallbackWrap.h │ ├── ByteOrder.h │ ├── ClientRPCHook.cpp │ ├── ClientRPCHook.h │ ├── CommunicationMode.h │ ├── DefaultMQClient.cpp │ ├── FilterAPI.h │ ├── InputStream.cpp │ ├── InputStream.h │ ├── MQClientErrorContainer.cpp │ ├── MQClientErrorContainer.h │ ├── MQVersion.cpp │ ├── MQVersion.h │ ├── MemoryInputStream.cpp │ ├── MemoryInputStream.h │ ├── MemoryOutputStream.cpp │ ├── MemoryOutputStream.h │ ├── MessageAccessor.cpp │ ├── MessageAccessor.h │ ├── MessageSysFlag.cpp │ ├── MessageSysFlag.h │ ├── NameSpaceUtil.cpp │ ├── NameSpaceUtil.h │ ├── NamesrvConfig.h │ ├── OutputStream.cpp │ ├── OutputStream.h │ ├── PermName.cpp │ ├── PermName.h │ ├── PullSysFlag.cpp │ ├── PullSysFlag.h │ ├── ServiceState.h │ ├── SubscriptionGroupConfig.h │ ├── TopAddressing.cpp │ ├── TopAddressing.h │ ├── TopicConfig.cpp │ ├── TopicConfig.h │ ├── TopicFilterType.h │ ├── UtilAll.cpp │ ├── UtilAll.h │ ├── Validators.cpp │ ├── Validators.h │ ├── VirtualEnvUtil.cpp │ ├── VirtualEnvUtil.h │ ├── big_endian.cpp │ ├── big_endian.h │ ├── dataBlock.cpp │ ├── dataBlock.h │ ├── noncopyable.h │ ├── sync_http_client.cpp │ ├── sync_http_client.h │ ├── url.cpp │ └── url.h ├── consumer │ ├── AllocateMQStrategy.h │ ├── ConsumeMessageConcurrentlyService.cpp │ ├── ConsumeMessageHookImpl.cpp │ ├── ConsumeMessageHookImpl.h │ ├── ConsumeMessageOrderlyService.cpp │ ├── ConsumeMsgService.h │ ├── DefaultMQPullConsumer.cpp │ ├── DefaultMQPullConsumerImpl.cpp │ ├── DefaultMQPullConsumerImpl.h │ ├── DefaultMQPushConsumer.cpp │ ├── DefaultMQPushConsumerImpl.cpp │ ├── DefaultMQPushConsumerImpl.h │ ├── FindBrokerResult.h │ ├── OffsetStore.cpp │ ├── OffsetStore.h │ ├── PullAPIWrapper.cpp │ ├── PullAPIWrapper.h │ ├── PullRequest.cpp │ ├── PullRequest.h │ ├── PullResult.cpp │ ├── PullResultExt.h │ ├── Rebalance.cpp │ ├── Rebalance.h │ ├── SubscriptionData.cpp │ └── SubscriptionData.h ├── dllmain.cpp ├── extern │ ├── CBatchMessage.cpp │ ├── CErrorMessage.cpp │ ├── CMessage.cpp │ ├── CMessageExt.cpp │ ├── CProducer.cpp │ ├── CPullConsumer.cpp │ ├── CPushConsumer.cpp │ └── CSendResult.cpp ├── include │ ├── BatchMessage.h │ ├── DefaultMQClient.h │ ├── MQConsumer.h │ ├── MQProducer.h │ └── QueryResult.h ├── log │ ├── Logging.cpp │ └── Logging.h ├── message │ ├── BatchMessage.cpp │ ├── MQDecoder.cpp │ ├── MQDecoder.h │ ├── MQMessage.cpp │ ├── MQMessageExt.cpp │ ├── MQMessageId.h │ └── MQMessageQueue.cpp ├── producer │ ├── DefaultMQProducer.cpp │ ├── DefaultMQProducerImpl.cpp │ ├── DefaultMQProducerImpl.h │ ├── SendMessageHookImpl.cpp │ ├── SendMessageHookImpl.h │ ├── SendResult.cpp │ ├── StringIdMaker.cpp │ ├── StringIdMaker.h │ ├── TopicPublishInfo.h │ ├── TransactionMQProducer.cpp │ ├── TransactionMQProducerImpl.cpp │ └── TransactionMQProducerImpl.h ├── protocol │ ├── CommandHeader.cpp │ ├── CommandHeader.h │ ├── ConsumerRunningInfo.cpp │ ├── ConsumerRunningInfo.h │ ├── HeartbeatData.h │ ├── KVTable.h │ ├── LockBatchBody.cpp │ ├── LockBatchBody.h │ ├── MQProtos.h │ ├── MessageQueue.cpp │ ├── MessageQueue.h │ ├── ProcessQueueInfo.h │ ├── RemotingCommand.cpp │ ├── RemotingCommand.h │ ├── RemotingSerializable.h │ ├── TopicList.h │ └── TopicRouteData.h ├── status │ ├── ConsumeStats.cpp │ ├── ConsumeStats.h │ ├── StatsItem.h │ ├── StatsServer.cpp │ ├── StatsServer.h │ ├── StatsServerManager.cpp │ └── StatsServerManager.h ├── thread │ ├── disruptor │ │ ├── batch_descriptor.h │ │ ├── claim_strategy.h │ │ ├── event_processor.h │ │ ├── event_publisher.h │ │ ├── exception_handler.h │ │ ├── exceptions.h │ │ ├── interface.h │ │ ├── ring_buffer.h │ │ ├── sequence.h │ │ ├── sequence_barrier.h │ │ ├── sequencer.h │ │ ├── utils.h │ │ └── wait_strategy.h │ ├── disruptorLFQ.h │ ├── task_queue.cpp │ └── task_queue.h ├── trace │ ├── ConsumeMessageContext.cpp │ ├── ConsumeMessageContext.h │ ├── ConsumeMessageHook.h │ ├── SendMessageContext.cpp │ ├── SendMessageContext.h │ ├── SendMessageHook.h │ ├── TraceBean.cpp │ ├── TraceBean.h │ ├── TraceConstant.cpp │ ├── TraceConstant.h │ ├── TraceContext.cpp │ ├── TraceContext.h │ ├── TraceTransferBean.cpp │ ├── TraceTransferBean.h │ ├── TraceUtil.cpp │ └── TraceUtil.h └── transport │ ├── ClientRemotingProcessor.cpp │ ├── ClientRemotingProcessor.h │ ├── EventLoop.cpp │ ├── EventLoop.h │ ├── ResponseFuture.cpp │ ├── ResponseFuture.h │ ├── SocketUtil.cpp │ ├── SocketUtil.h │ ├── TcpRemotingClient.cpp │ ├── TcpRemotingClient.h │ ├── TcpTransport.cpp │ └── TcpTransport.h ├── test ├── CMakeLists.txt └── src │ ├── MQClientAPIImpTest.cpp │ ├── MQClientFactoryTest.cpp │ ├── MQClientManagerTest.cpp │ ├── common │ ├── ClientRPCHookTest.cpp │ ├── MQVersionTest.cpp │ ├── MemoryBlockTest.cpp │ ├── MemoryOutputStreamTest.cpp │ ├── NameSpaceUtilTest.cpp │ ├── NamesrvConfigTest.cpp │ ├── PermNametTest.cpp │ ├── PullSysFlagTest.cpp │ ├── TopicConfigTest.cpp │ ├── UrlTest.cpp │ ├── UtilAllTest.cpp │ ├── ValidatorsTest.cpp │ ├── VirtualEnvUtilTest.cpp │ └── big_endianTest.cpp │ ├── consumer │ └── DefaultMQPushConsumerImplTest.cpp │ ├── extern │ ├── CMessageExtTest.cpp │ ├── CMessageTest.cpp │ ├── CProducerTest.cpp │ ├── CPullConsumerTest.cpp │ └── CPushConsumerTest.cpp │ ├── message │ ├── BatchMessageTest.cpp │ ├── MQDecoderTest.cpp │ ├── MQMessageExtTest.cpp │ ├── MQMessageIdTest.cpp │ ├── MQMessageQueueTest.cpp │ └── MQMessageTest.cpp │ ├── producer │ ├── DefaultMQProducerImplTest.cpp │ ├── StringIdMakerTest.cpp │ └── TopicPublishInfoTest.cpp │ ├── protocol │ ├── CommandHeaderTest.cpp │ ├── ConsumerRunningInfoTest.cpp │ ├── HeartbeatDataTest.cpp │ ├── KVTableTest.cpp │ ├── LockBatchBodyTest.cpp │ ├── MessageQueueTest.cpp │ ├── ProcessQueueInfoTest.cpp │ ├── RemotingCommandTest.cpp │ └── TopicRouteDataTest.cpp │ ├── trace │ ├── TraceBeanTest.cpp │ └── TraceUtilTest.cpp │ └── transport │ ├── ClientRemotingProcessorTest.cpp │ ├── ResponseFutureTest.cpp │ └── SocketUtilTest.cpp └── win32_build.bat /.asf.yaml: -------------------------------------------------------------------------------- 1 | notifications: 2 | commits: commits@rocketmq.apache.org 3 | issues: commits@rocketmq.apache.org 4 | pullrequests: commits@rocketmq.apache.org 5 | jobs: commits@rocketmq.apache.org 6 | discussions: dev@rocketmq.apache.org 7 | -------------------------------------------------------------------------------- /.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: Chromium 2 | ColumnLimit: 120 3 | TabWidth: 2 4 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/issue_template.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: ISSUE_TEMPLATE 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | The issue tracker is **ONLY** used for the CPP/C client (feature request of RocketMQ need to follow [RIP process](https://github.com/apache/rocketmq/wiki/RocketMQ-Improvement-Proposal)). Keep in mind, please check whether there is an existing same report before your raise a new one. 11 | 12 | Alternately (especially if your communication is not a bug report), you can send mail to our [mailing lists](http://rocketmq.apache.org/about/contact/). We welcome any friendly suggestions, bug fixes, collaboration, and other improvements. 13 | 14 | Please ensure that your bug report is clear and that it is complete. Otherwise, we may be unable to understand it or to reproduce it, either of which would prevent us from fixing the bug. We strongly recommend the report(bug report or feature request) could include some hints as to the following: 15 | 16 | **BUG REPORT** 17 | 18 | 1. Please describe the issue you observed: 19 | 20 | - What did you do (The steps to reproduce)? 21 | 22 | - What did you expect to see? 23 | 24 | - What did you see instead? 25 | 26 | 2. Please tell us about your environment: 27 | 28 | - What is your OS? 29 | 30 | - What is your client version? 31 | 32 | - What is your RocketMQ version? 33 | 34 | 3. Other information (e.g. detailed explanation, logs, related issues, suggestions on how to fix, etc): 35 | 36 | **FEATURE REQUEST** 37 | 38 | 1. Please describe the feature you are requesting. 39 | 40 | 2. Provide any additional detail on your proposed use case for this feature. 41 | 42 | 2. Indicate the importance of this issue to you (blocker, must-have, should-have, nice-to-have). Are you currently using any workarounds to address this issue? 43 | 44 | 4. If there are some sub-tasks using -[] for each subtask and create a corresponding issue to map to the sub task: 45 | 46 | - [sub-task1-issue-number](example_sub_issue1_link_here): sub-task1 description here, 47 | - [sub-task2-issue-number](example_sub_issue2_link_here): sub-task2 description here, 48 | - ... 49 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | cmake-build-debug/ 3 | bin 4 | build 5 | libs/signature/lib 6 | tmp_* 7 | Testing 8 | .vscode 9 | .cache 10 | compile_commands.json 11 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: cpp 2 | sudo: required 3 | dist: trusty 4 | compiler: gcc 5 | 6 | addons: 7 | apt: 8 | packages: lcov 9 | 10 | install: 11 | #- sudo apt-get update 12 | #- sudo apt-get install -y git gcc-4.8 g++-4.8 autoconf cmake libtool wget unzip libbz2-dev zlib1g-dev 13 | - echo 'MAVEN_OPTS="$MAVEN_OPTS -Xmx1024m -XX:MaxPermSize=512m -XX:+BytecodeVerificationLocal"' >> ~/.mavenrc 14 | - cat ~/.mavenrc 15 | - if [ "$TRAVIS_OS_NAME" == "osx" ]; then export JAVA_HOME=$(/usr/libexec/java_home); fi 16 | - if [ "$TRAVIS_OS_NAME" == "linux" ]; then jdk_switcher use "$CUSTOM_JDK"; fi 17 | 18 | before_script: 19 | - wget https://archive.apache.org/dist/rocketmq/4.3.2/rocketmq-all-4.3.2-bin-release.zip 20 | - unzip rocketmq-all-4.3.2-bin-release.zip 21 | - cd rocketmq-all-4.3.2-bin-release 22 | - perl -i -pe's/-Xms8g -Xmx8g -Xmn4g/-Xms2g -Xmx2g -Xmn1g/g' bin/runbroker.sh 23 | - nohup sh bin/mqnamesrv & 24 | - nohup sh bin/mqbroker -n localhost:9876 & 25 | - sleep 10 26 | - ./bin/mqadmin updateTopic -b '127.0.0.1:10911' –n '127.0.0.1:9876' -t test 27 | - ./bin/mqadmin updateSubGroup -b '127.0.0.1:10911' –n '127.0.0.1:9876' -g testGroup 28 | - cd .. 29 | 30 | script: 31 | - ./build.sh test codecov noVerbose 32 | 33 | after_success: 34 | # Create lcov report 35 | # capture coverage info 36 | - lcov --directory . --capture --output-file coverage.info 37 | # filter out system and extra files. 38 | # To also not include test code in coverage add them with full path to the patterns: '*/tests/*' 39 | - lcov --remove coverage.info '/usr/*' '/home/travis/build/*/rocketmq-client-cpp/bin/*' '/home/travis/build/*/rocketmq-client-cpp/libs/*' --output-file coverage.info 40 | # output coverage data for debugging (optional) 41 | - lcov --list coverage.info 42 | # Uploading to CodeCov 43 | # '-f' specifies file(s) to use and disables manual coverage gathering and file search which has already been done above 44 | - bash <(curl -s https://codecov.io/bash) -f coverage.info || echo "Codecov did not collect coverage reports" 45 | 46 | matrix: 47 | include: 48 | - os: linux 49 | env: CUSTOM_JDK="oraclejdk8" 50 | 51 | # This is the job to check code format. 52 | - os: linux 53 | dist: trusty 54 | env: LINT=1 PYTHON=2.7 55 | before_install: 56 | #- sudo apt-get update -qq 57 | #- sudo apt-get install -qq clang-format-3.8 58 | install: [] 59 | script: 60 | - sudo sh .travis/check-git-clang-format.sh 61 | -------------------------------------------------------------------------------- /.travis/check-git-clang-format.sh: -------------------------------------------------------------------------------- 1 | # contributor license agreements. See the NOTICE file distributed with 2 | # this work for additional information regarding copyright ownership. 3 | # The ASF licenses this file to You under the Apache License, Version 2.0 4 | # (the "License"); you may not use this file except in compliance with 5 | # the License. You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | #!/bin/bash 16 | 17 | if [ "$TRAVIS_PULL_REQUEST" = "true" ]; then 18 | base_commit="$TRAVIS_BRANCH" 19 | else 20 | base_commit="HEAD^" 21 | fi 22 | 23 | output="$(sudo python .travis/git-clang-format --binary clang-format-3.8 --commit $base_commit --diff)" 24 | 25 | if [ "$output" = "no modified files to format" ] || [ "$output" = "clang-format did not modify any files" ]; then 26 | echo "clang-format passed." 27 | exit 0 28 | else 29 | echo "clang-format failed." 30 | echo "$output" 31 | exit 1 32 | fi 33 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## How to Contribute 2 | Contributions are warmly welcome! Be it trivial cleanup, major new feature or other suggestion. Read this [how to contribute](http://rocketmq.apache.org/docs/how-to-contribute/) guide for more details. 3 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Apache RocketMQ 2 | Copyright 2016-2024 The Apache Software Foundation 3 | 4 | This product includes software developed at 5 | The Apache Software Foundation (http://www.apache.org/). 6 | -------------------------------------------------------------------------------- /PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## What is the purpose of the change 2 | 3 | XXXXX 4 | 5 | ## Brief changelog 6 | 7 | XX 8 | 9 | ## Verifying this change 10 | 11 | XXXX 12 | 13 | Follow this checklist to help us incorporate your contribution quickly and easily. Notice, `it would be helpful if you could finish the following 5 checklist(the last one is not necessary)before request the community to review your PR`. 14 | 15 | - [x] Make sure there is a [Github issue](https://github.com/apache/rocketmq/issues) filed for the change (usually before you start working on it). Trivial changes like typos do not require a Github issue. Your pull request should address just this issue, without pulling in other changes - one PR resolves one issue. 16 | - [x] Format the pull request title like `[ISSUE #123] Fix UnknownException when host config not exist`. Each commit in the pull request should have a meaningful subject line and body. 17 | - [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why. 18 | - [x] Write necessary unit-test(over 80% coverage) to verify your logic correction, more mock a little better when a cross-module dependency exists. 19 | - [ ] If this contribution is large, please file an [Apache Individual Contributor License Agreement](http://www.apache.org/licenses/#clas). 20 | -------------------------------------------------------------------------------- /dep/build.sh: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | BASEDIR=$(dirname "$0") 16 | if [[ ! -d ${BASEDIR}/rocketmq_amd64/usr/local/include/rocketmq ]]; then 17 | mkdir -p ${BASEDIR}/rocketmq_amd64/usr/local/include/rocketmq 18 | fi 19 | 20 | if [[ ! -d ${BASEDIR}/rocketmq_amd64/usr/local/lib ]]; then 21 | mkdir -p ${BASEDIR}/rocketmq_amd64/usr/local/lib 22 | fi 23 | 24 | cp -R ${BASEDIR}/../include/* ${BASEDIR}/rocketmq_amd64/usr/local/include/rocketmq 25 | cp ${BASEDIR}/../bin/librocketmq.so ${BASEDIR}/rocketmq_amd64/usr/local/lib/ 26 | cp ${BASEDIR}/../bin/librocketmq.a ${BASEDIR}/rocketmq_amd64/usr/local/lib/ 27 | 28 | VERSION=`cat ${BASEDIR}/rocketmq_amd64/DEBIAN/control | grep Version | awk -F ':' '{print $2}'| sed 's/^ *//'` 29 | dpkg-deb --build ${BASEDIR}/rocketmq_amd64 rocketmq-client-cpp-${VERSION}.amd64.deb 30 | -------------------------------------------------------------------------------- /dep/rocketmq_amd64/DEBIAN/control: -------------------------------------------------------------------------------- 1 | Package: RocketMQ 2 | Version: 2.2.0 3 | Architecture: amd64 4 | Essential: no 5 | Priority: optional 6 | Depends: 7 | Maintainer: "Apache RocketMQ" 8 | Description: This package is C++ client of Apache RocketMQ for debian and its derivertives like Ubuntu. 9 | -------------------------------------------------------------------------------- /dep/rocketmq_amd64/DEBIAN/postinst: -------------------------------------------------------------------------------- 1 | #!/bin/sh 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 | ldconfig -------------------------------------------------------------------------------- /distribution/deploy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 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 | 18 | 19 | VERSION="2.2.0" 20 | PKG_NAME="rocketmq-client-cpp" 21 | CWD_DIR=$(cd "$(dirname "$0")"; pwd) 22 | DEPLOY_BUILD_HOME=${CWD_DIR}/${PKG_NAME} 23 | 24 | # ##==================================================================== 25 | #make 26 | # ##==================================================================== 27 | # # deploy 28 | rm -rf ${DEPLOY_BUILD_HOME} 29 | mkdir -p ${DEPLOY_BUILD_HOME}/lib 30 | cp -rf ${CWD_DIR}/../bin/*.a ${DEPLOY_BUILD_HOME}/lib/ 31 | if test "$(uname)" = "Linux"; then 32 | cp -rf ${CWD_DIR}/../bin/*.so ${DEPLOY_BUILD_HOME}/lib/ 33 | fi 34 | if test "$(uname)" = "Darwin"; then 35 | cp -rf ${CWD_DIR}/../bin/*.dylib ${DEPLOY_BUILD_HOME}/lib/ 36 | fi 37 | cp -rf ${CWD_DIR}/../include ${DEPLOY_BUILD_HOME}/ 38 | cp -rf ${CWD_DIR}/../example ${DEPLOY_BUILD_HOME}/ 39 | cp -rf ${CWD_DIR}/../README.md ${DEPLOY_BUILD_HOME}/ 40 | cp -rf ${CWD_DIR}/../LICENSE ${DEPLOY_BUILD_HOME}/LICENSE 41 | cp -rf ${CWD_DIR}/../NOTICE ${DEPLOY_BUILD_HOME}/NOTICE 42 | 43 | cd ${CWD_DIR} && tar -cvzf ./${PKG_NAME}-${VERSION}-bin-release.tar.gz ./${PKG_NAME} &> /dev/null 44 | rm -rf ${DEPLOY_BUILD_HOME} 45 | # # ##==================================================================== 46 | #make clean 47 | -------------------------------------------------------------------------------- /example/CBatchProducer.c: -------------------------------------------------------------------------------- 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 | #include 19 | #include 20 | #include "CBatchMessage.h" 21 | #include "CCommon.h" 22 | #include "CMessage.h" 23 | #include "CProducer.h" 24 | #include "CSendResult.h" 25 | 26 | void StartSendMessage(CProducer* producer) { 27 | int i = 0; 28 | int ret_code = 0; 29 | char body[128]; 30 | CBatchMessage* batchMessage = CreateBatchMessage("T_TestTopic"); 31 | 32 | for (i = 0; i < 10; i++) { 33 | CMessage* msg = CreateMessage("T_TestTopic"); 34 | SetMessageTags(msg, "Test_Tag"); 35 | SetMessageKeys(msg, "Test_Keys"); 36 | memset(body, 0, sizeof(body)); 37 | snprintf(body, sizeof(body), "new message body, index %d", i); 38 | SetMessageBody(msg, body); 39 | AddMessage(batchMessage, msg); 40 | } 41 | CSendResult result; 42 | ret_code = SendBatchMessage(producer, batchMessage, &result); 43 | printf("SendBatchMessage %s .....\n", ret_code == 0 ? "Success" : ret_code == 11 ? "FAILED" : " It is null value"); 44 | DestroyBatchMessage(batchMessage); 45 | } 46 | 47 | void CreateProducerAndStartSendMessage() { 48 | printf("Producer Initializing.....\n"); 49 | CProducer* producer = CreateProducer("Group_producer"); 50 | SetProducerNameServerAddress(producer, "127.0.0.1:9876"); 51 | StartProducer(producer); 52 | printf("Producer start.....\n"); 53 | StartSendMessage(producer); 54 | ShutdownProducer(producer); 55 | DestroyProducer(producer); 56 | printf("Producer Shutdown!\n"); 57 | } 58 | 59 | int main(int argc, char* argv[]) { 60 | printf("Send Batch.....\n"); 61 | CreateProducerAndStartSendMessage(); 62 | return 0; 63 | } 64 | -------------------------------------------------------------------------------- /example/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | project(example) 17 | 18 | set(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/bin) 19 | 20 | include_directories(${CMAKE_SOURCE_DIR}/include) 21 | include_directories(${Boost_INCLUDE_DIRS}) 22 | 23 | link_directories(${Boost_LIBRARY_DIRS}) 24 | link_directories(${LIBEVENT_LIBRARY}) 25 | link_directories(${JSONCPP_LIBRARY}) 26 | link_directories(${OPENSSL_LIBRARIES_DIR}) 27 | 28 | #if (BUILD_ROCKETMQ_SHARED) 29 | # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBOOST_ALL_DYN_LINK -shared ") 30 | #endif() 31 | 32 | file(GLOB files "*.c*") 33 | foreach(file ${files}) 34 | get_filename_component(basename ${file} NAME_WE) 35 | add_executable(${basename} ${file}) 36 | if(MSVC) 37 | if(CMAKE_CONFIGURATION_TYPES STREQUAL "Release") 38 | set_target_properties( ${basename} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:LIBCMT" ) 39 | else() 40 | set_target_properties( ${basename} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:LIBCMTD" ) 41 | endif() 42 | endif() 43 | 44 | if (MSVC) 45 | if (BUILD_ROCKETMQ_SHARED) 46 | target_link_libraries (${basename} rocketmq_shared ${deplibs} 47 | ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} ${LIBEVENT_LIBRARIES} ${JSONCPP_LIBRARIES}) 48 | else() 49 | target_link_libraries (${basename} rocketmq_static ${deplibs} 50 | ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} ${LIBEVENT_LIBRARIES} ${JSONCPP_LIBRARIES}) 51 | endif() 52 | else() 53 | if (BUILD_ROCKETMQ_SHARED) 54 | target_link_libraries (${basename} rocketmq_shared) 55 | else() 56 | target_link_libraries (${basename} rocketmq_static) 57 | endif() 58 | endif() 59 | 60 | endforeach() 61 | -------------------------------------------------------------------------------- /example/Producer.c: -------------------------------------------------------------------------------- 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 | #include 19 | #include "CCommon.h" 20 | #include "CMessage.h" 21 | #include "CProducer.h" 22 | #include "CSendResult.h" 23 | #ifdef _WIN32 24 | #include 25 | #else 26 | #include 27 | #include 28 | #endif 29 | 30 | void thread_sleep(unsigned int milliseconds) { 31 | #ifdef _WIN32 32 | Sleep(milliseconds); 33 | #else 34 | usleep(milliseconds * 1000); // suspend execution for microsecond intervals 35 | #endif 36 | } 37 | 38 | void StartSendMessage(CProducer* producer) { 39 | int i = 0; 40 | char body[256]; 41 | CMessage* msg = CreateMessage("T_TestTopic"); 42 | SetMessageTags(msg, "Test_Tag"); 43 | SetMessageKeys(msg, "Test_Keys"); 44 | CSendResult result; 45 | for (i = 0; i < 3; i++) { 46 | memset(body, 0, sizeof(body)); 47 | snprintf(body, sizeof(body), "new message body, index %d", i); 48 | SetMessageBody(msg, body); 49 | int status = SendMessageSync(producer, msg, &result); 50 | if (status == OK) { 51 | printf("send message[%d] result status:%d, msgId:%s\n", i, (int)result.sendStatus, result.msgId); 52 | } else { 53 | printf("send message[%d] failed !\n", i); 54 | } 55 | thread_sleep(1000); 56 | } 57 | DestroyMessage(msg); 58 | } 59 | 60 | int main(int argc, char* argv[]) { 61 | CProducer* producer = CreateProducer("Group_producer"); 62 | SetProducerNameServerAddress(producer, "127.0.0.1:9876"); 63 | StartProducer(producer); 64 | printf("Producer initialized. \n"); 65 | 66 | StartSendMessage(producer); 67 | 68 | ShutdownProducer(producer); 69 | DestroyProducer(producer); 70 | printf("Producer stopped !\n"); 71 | 72 | return 0; 73 | } 74 | -------------------------------------------------------------------------------- /example/PushConsumeMessage.c: -------------------------------------------------------------------------------- 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 | #include 19 | #include "CCommon.h" 20 | #include "CMessageExt.h" 21 | #include "CPushConsumer.h" 22 | #ifdef _WIN32 23 | #include 24 | #else 25 | #include 26 | #include 27 | #endif 28 | 29 | void thread_sleep(unsigned milliseconds) { 30 | #ifdef _WIN32 31 | Sleep(milliseconds); 32 | #else 33 | usleep(milliseconds * 1000); // takes microseconds 34 | #endif 35 | } 36 | 37 | int doConsumeMessage(struct CPushConsumer* consumer, CMessageExt* msgExt) { 38 | printf("Hello,doConsumeMessage by Application!\n"); 39 | printf("Msg Topic:%s\n", GetMessageTopic(msgExt)); 40 | printf("Msg Tags:%s\n", GetMessageTags(msgExt)); 41 | printf("Msg Keys:%s\n", GetMessageKeys(msgExt)); 42 | printf("Msg Body:%s\n", GetMessageBody(msgExt)); 43 | return E_CONSUME_SUCCESS; 44 | } 45 | 46 | int main(int argc, char* argv[]) { 47 | int i = 0; 48 | printf("PushConsumer Initializing....\n"); 49 | CPushConsumer* consumer = CreatePushConsumer("Group_Consumer_Test"); 50 | SetPushConsumerNameServerAddress(consumer, "172.17.0.2:9876"); 51 | Subscribe(consumer, "T_TestTopic", "*"); 52 | RegisterMessageCallback(consumer, doConsumeMessage); 53 | StartPushConsumer(consumer); 54 | printf("Push Consumer Start...\n"); 55 | for (i = 0; i < 10; i++) { 56 | printf("Now Running : %d S\n", i * 10); 57 | thread_sleep(10000); 58 | } 59 | ShutdownPushConsumer(consumer); 60 | DestroyPushConsumer(consumer); 61 | printf("PushConsumer Shutdown!\n"); 62 | return 0; 63 | } 64 | -------------------------------------------------------------------------------- /example/PushConsumerOrderly.c: -------------------------------------------------------------------------------- 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 | #ifndef WIN32 18 | #include 19 | #endif 20 | #include 21 | #include "CCommon.h" 22 | #include "CMessageExt.h" 23 | #include "CPushConsumer.h" 24 | 25 | int doConsumeMessage(struct CPushConsumer* consumer, CMessageExt* msgExt) { 26 | printf("Hello,doConsumeMessage by Application!\n"); 27 | printf("Msg Topic:%s\n", GetMessageTopic(msgExt)); 28 | printf("Msg Tags:%s\n", GetMessageTags(msgExt)); 29 | printf("Msg Keys:%s\n", GetMessageKeys(msgExt)); 30 | printf("Msg Body:%s\n", GetMessageBody(msgExt)); 31 | return E_CONSUME_SUCCESS; 32 | } 33 | 34 | int main(int argc, char* argv[]) { 35 | int i = 0; 36 | printf("PushConsumer Initializing....\n"); 37 | CPushConsumer* consumer = CreatePushConsumer("Group_Consumer_Test"); 38 | SetPushConsumerNameServerAddress(consumer, "127.0.0.1:9876"); 39 | Subscribe(consumer, "test", "*"); 40 | RegisterMessageCallbackOrderly(consumer, doConsumeMessage); 41 | StartPushConsumer(consumer); 42 | printf("Push Consumer Start...\n"); 43 | for (i = 0; i < 10; i++) { 44 | printf("Now Running : %d S\n", i * 10); 45 | sleep(10); 46 | } 47 | ShutdownPushConsumer(consumer); 48 | DestroyPushConsumer(consumer); 49 | printf("PushConsumer Shutdown!\n"); 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /example/README.md: -------------------------------------------------------------------------------- 1 | 1. AsyncProducer 2. OrderlyProducer 3. SyncProducer 2 | -------------------------------------------------------------------------------- /example/SendDelayMsg.cpp: -------------------------------------------------------------------------------- 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 | #include 18 | #include 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include "common.h" 28 | 29 | using namespace rocketmq; 30 | 31 | int main(int argc, char* argv[]) { 32 | RocketmqSendAndConsumerArgs info; 33 | if (!ParseArgs(argc, argv, &info)) { 34 | exit(-1); 35 | } 36 | PrintRocketmqSendAndConsumerArgs(info); 37 | DefaultMQProducer producer("please_rename_unique_group_name"); 38 | producer.setNamesrvAddr(info.namesrv); 39 | producer.setNamesrvDomain(info.namesrv_domain); 40 | producer.setGroupName(info.groupname); 41 | producer.setInstanceName(info.groupname); 42 | 43 | producer.setSendMsgTimeout(500); 44 | producer.setTcpTransportTryLockTimeout(1000); 45 | producer.setTcpTransportConnectTimeout(400); 46 | 47 | producer.start(); 48 | 49 | MQMessage msg(info.topic, // topic 50 | "*", // tag 51 | info.body); // body 52 | 53 | // messageDelayLevel=1s 5s 10s 30s 1m 2m 3m 4m 5m 6m 7m 8m 9m 10m 20m 30m 1h 54 | // 2h 55 | msg.setDelayTimeLevel(5); // 1m 56 | try { 57 | SendResult sendResult = producer.send(msg, info.SelectUnactiveBroker); 58 | } catch (const MQException& e) { 59 | std::cout << "send failed: " << std::endl; 60 | } 61 | 62 | producer.shutdown(); 63 | return 0; 64 | } 65 | -------------------------------------------------------------------------------- /format.sh: -------------------------------------------------------------------------------- 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 | 18 | 19 | TMPFILE=".clang_format_file.tmp" 20 | FORMAT="{BasedOnStyle: Chromium, ColumnLimit: 120, TabWidth: 2}" 21 | 22 | function Usage 23 | { 24 | echo "Usage: $0 want-format-file|want-format-dir ..." 25 | #echo "Currently only format a file or dir at a time" 26 | } 27 | 28 | #Setp1 check clang-format support 29 | if ! which clang-format &> /dev/null; then 30 | echo -e "\033[32m !!!!!!please install clang-format \033[0m" 31 | exit 1 32 | fi 33 | 34 | 35 | #Setp2 check weather incoming format file 36 | if [ ! $# -ge 1 ];then 37 | Usage 38 | exit 1 39 | fi 40 | 41 | for dest in "$@" 42 | do 43 | if [ ! -e $dest ]; then 44 | echo -e "\033[32m $dest not exists,please check this file weather exists \033[0m" 45 | fi 46 | done 47 | 48 | 49 | #Setp3 get filelist 50 | for dest in $* 51 | do 52 | if [ -f $dest ];then 53 | files="$files $dest" 54 | elif [ -d $dest ];then 55 | files="$files `ls $dest/*.cpp $dest/*.h $dest/*.cc 2>/dev/null`" 56 | else 57 | echo -e "\033[32m $dest sorry current $0 only support regular file or dir \033[0m" 58 | fi 59 | done 60 | 61 | #Setp4 use clang-format format dest file 62 | for file in $files 63 | do 64 | echo $file 65 | clang-format $file > $TMPFILE 66 | 67 | if [ -e $TMPFILE ];then 68 | filesize=`wc -c $TMPFILE |cut -d " " -f1` 69 | if [ $filesize -eq 0 ];then 70 | echo -e "\033[32m formt file error,May be because of the size of the source file is 0, or format program error \033[0m" 71 | exit 1 72 | fi 73 | fi 74 | 75 | #Setp4 replace source file 76 | mv -f $TMPFILE $file 77 | done 78 | -------------------------------------------------------------------------------- /include/Arg_helper.h: -------------------------------------------------------------------------------- 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 | #ifndef _ARG_HELPER_H_ 19 | #define _ARG_HELPER_H_ 20 | 21 | #include 22 | #include 23 | #include "RocketMQClient.h" 24 | 25 | namespace rocketmq { 26 | class ROCKETMQCLIENT_API Arg_helper { 27 | public: 28 | Arg_helper(int argc, char* argv[]); 29 | Arg_helper(std::string arg_str_); 30 | std::string get_option(int idx_) const; 31 | bool is_enable_option(std::string opt_) const; 32 | std::string get_option_value(std::string opt_) const; 33 | 34 | private: 35 | std::vector m_args; 36 | }; 37 | 38 | } // namespace rocketmq 39 | 40 | #endif // 21 | #include "MQMessageExt.h" 22 | #include "MQMessageQueue.h" 23 | 24 | namespace rocketmq { 25 | //& msgs) = 0; 39 | virtual MessageListenerType getMessageListenerType() { return messageListenerDefaultly; } 40 | }; 41 | 42 | class ROCKETMQCLIENT_API MessageListenerOrderly : public MQMessageListener { 43 | public: 44 | virtual ~MessageListenerOrderly() {} 45 | virtual ConsumeStatus consumeMessage(const std::vector& msgs) = 0; 46 | virtual MessageListenerType getMessageListenerType() { return messageListenerOrderly; } 47 | }; 48 | 49 | class ROCKETMQCLIENT_API MessageListenerConcurrently : public MQMessageListener { 50 | public: 51 | virtual ~MessageListenerConcurrently() {} 52 | virtual ConsumeStatus consumeMessage(const std::vector& msgs) = 0; 53 | virtual MessageListenerType getMessageListenerType() { return messageListenerConcurrently; } 54 | }; 55 | 56 | } // namespace rocketmq 57 | #endif 58 | -------------------------------------------------------------------------------- /include/MQMessageQueue.h: -------------------------------------------------------------------------------- 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 | #ifndef __MQMESSAGEQUEUE_H__ 18 | #define __MQMESSAGEQUEUE_H__ 19 | 20 | #include 21 | #include 22 | #include 23 | #include "RocketMQClient.h" 24 | 25 | namespace rocketmq { 26 | class ROCKETMQCLIENT_API MQMessageQueue { 27 | public: 28 | MQMessageQueue(); 29 | MQMessageQueue(const std::string& topic, const std::string& brokerName, int queueId); 30 | MQMessageQueue(const MQMessageQueue& other); 31 | MQMessageQueue& operator=(const MQMessageQueue& other); 32 | 33 | std::string getTopic() const; 34 | void setTopic(const std::string& topic); 35 | 36 | std::string getBrokerName() const; 37 | void setBrokerName(const std::string& brokerName); 38 | 39 | int getQueueId() const; 40 | void setQueueId(int queueId); 41 | 42 | bool operator==(const MQMessageQueue& mq) const; 43 | bool operator<(const MQMessageQueue& mq) const; 44 | int compareTo(const MQMessageQueue& mq) const; 45 | 46 | const std::string toString() const { 47 | std::stringstream ss; 48 | ss << "MessageQueue [topic=" << m_topic << ", brokerName=" << m_brokerName << ", queueId=" << m_queueId << "]"; 49 | 50 | return ss.str(); 51 | } 52 | 53 | private: 54 | std::string m_topic; 55 | std::string m_brokerName; 56 | int m_queueId; 57 | }; 58 | } // namespace rocketmq 59 | #endif 60 | -------------------------------------------------------------------------------- /include/MQSelector.h: -------------------------------------------------------------------------------- 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 | #ifndef _MQSELECTOR_H_ 18 | #define _MQSELECTOR_H_ 19 | #include "MQMessage.h" 20 | #include "MQMessageQueue.h" 21 | #include "RocketMQClient.h" 22 | 23 | namespace rocketmq { 24 | class ROCKETMQCLIENT_API MessageQueueSelector { 25 | public: 26 | virtual ~MessageQueueSelector() {} 27 | virtual MQMessageQueue select(const std::vector& mqs, const MQMessage& msg, void* arg) = 0; 28 | }; 29 | } // namespace rocketmq 30 | #endif 31 | -------------------------------------------------------------------------------- /include/MQueueListener.h: -------------------------------------------------------------------------------- 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 | #ifndef __MESSAGEQUEUELISTENER_H__ 18 | #define __MESSAGEQUEUELISTENER_H__ 19 | 20 | #include 21 | #include "RocketMQClient.h" 22 | 23 | namespace rocketmq { 24 | class ROCKETMQCLIENT_API MQueueListener { 25 | public: 26 | virtual ~MQueueListener() {} 27 | virtual void messageQueueChanged(const std::string& topic, 28 | std::vector& mqAll, 29 | std::vector& mqDivided) = 0; 30 | }; 31 | } // namespace rocketmq 32 | #endif 33 | -------------------------------------------------------------------------------- /include/PullResult.h: -------------------------------------------------------------------------------- 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 | #ifndef __PULLRESULT_H__ 18 | #define __PULLRESULT_H__ 19 | 20 | #include 21 | #include "MQMessageExt.h" 22 | #include "RocketMQClient.h" 23 | 24 | namespace rocketmq { 25 | enum PullStatus { 26 | FOUND, 27 | NO_NEW_MSG, 28 | NO_MATCHED_MSG, 29 | OFFSET_ILLEGAL, 30 | BROKER_TIMEOUT // indicate pull request timeout or received NULL response 31 | }; 32 | 33 | static const char* EnumStrings[] = {"FOUND", "NO_NEW_MSG", "NO_MATCHED_MSG", "OFFSET_ILLEGAL", "BROKER_TIMEOUT"}; 34 | 35 | class ROCKETMQCLIENT_API PullResult { 36 | public: 37 | PullResult(); 38 | PullResult(PullStatus status); 39 | PullResult(PullStatus pullStatus, int64 nextBeginOffset, int64 minOffset, int64 maxOffset); 40 | 41 | PullResult(PullStatus pullStatus, 42 | int64 nextBeginOffset, 43 | int64 minOffset, 44 | int64 maxOffset, 45 | const std::vector& src); 46 | 47 | virtual ~PullResult(); 48 | 49 | std::string toString() { 50 | std::stringstream ss; 51 | ss << "PullResult [ pullStatus=" << EnumStrings[pullStatus] << ", nextBeginOffset=" << nextBeginOffset 52 | << ", minOffset=" << minOffset << ", maxOffset=" << maxOffset << ", msgFoundList=" << msgFoundList.size() 53 | << " ]"; 54 | return ss.str(); 55 | } 56 | 57 | public: 58 | PullStatus pullStatus; 59 | int64 nextBeginOffset; 60 | int64 minOffset; 61 | int64 maxOffset; 62 | std::vector msgFoundList; 63 | }; 64 | } // namespace rocketmq 65 | #endif 66 | -------------------------------------------------------------------------------- /include/RocketMQClient.h: -------------------------------------------------------------------------------- 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 | #ifndef __ROCKETMQCLIENT_H__ 18 | #define __ROCKETMQCLIENT_H__ 19 | 20 | #ifdef WIN32 21 | #ifdef ROCKETMQCLIENT_EXPORTS 22 | #ifdef _WINDLL 23 | #define ROCKETMQCLIENT_API __declspec(dllexport) 24 | #else 25 | #define ROCKETMQCLIENT_API 26 | #endif 27 | #else 28 | #ifdef ROCKETMQCLIENT_IMPORT 29 | #define ROCKETMQCLIENT_API __declspec(dllimport) 30 | #else 31 | #define ROCKETMQCLIENT_API 32 | #endif 33 | #endif 34 | #else 35 | #define ROCKETMQCLIENT_API 36 | #endif 37 | 38 | /** A platform-independent 8-bit signed integer type. */ 39 | typedef signed char int8; 40 | /** A platform-independent 8-bit unsigned integer type. */ 41 | typedef unsigned char uint8; 42 | /** A platform-independent 16-bit signed integer type. */ 43 | typedef signed short int16; 44 | /** A platform-independent 16-bit unsigned integer type. */ 45 | typedef unsigned short uint16; 46 | /** A platform-independent 32-bit signed integer type. */ 47 | typedef signed int int32; 48 | /** A platform-independent 32-bit unsigned integer type. */ 49 | typedef unsigned int uint32; 50 | /** A platform-independent 64-bit integer type. */ 51 | typedef long long int64; 52 | /** A platform-independent 64-bit unsigned integer type. */ 53 | typedef unsigned long long uint64; 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /include/TransactionListener.h: -------------------------------------------------------------------------------- 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 | #ifndef __TRANSACTIONLISTENER_H__ 19 | #define __TRANSACTIONLISTENER_H__ 20 | 21 | #include "MQMessage.h" 22 | #include "MQMessageExt.h" 23 | #include "TransactionSendResult.h" 24 | 25 | namespace rocketmq { 26 | class ROCKETMQCLIENT_API TransactionListener { 27 | public: 28 | virtual ~TransactionListener() {} 29 | /** 30 | * When send transactional prepare(half) message succeed, this method will be invoked to execute local transaction. 31 | * 32 | * @param msg Half(prepare) message 33 | * @param arg Custom business parameter 34 | * @return Transaction state 35 | */ 36 | virtual LocalTransactionState executeLocalTransaction(const MQMessage& msg, void* arg) = 0; 37 | 38 | /** 39 | * When no response to prepare(half) message. broker will send check message to check the transaction status, and this 40 | * method will be invoked to get local transaction status. 41 | * 42 | * @param msg Check message 43 | * @return Transaction state 44 | */ 45 | virtual LocalTransactionState checkLocalTransaction(const MQMessageExt& msg) = 0; 46 | }; 47 | } // namespace rocketmq 48 | #endif 49 | -------------------------------------------------------------------------------- /include/TransactionSendResult.h: -------------------------------------------------------------------------------- 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 | #ifndef __TRANSACTIONSENDRESULT_H__ 19 | #define __TRANSACTIONSENDRESULT_H__ 20 | 21 | #include "SendResult.h" 22 | 23 | namespace rocketmq { 24 | 25 | enum LocalTransactionState { COMMIT_MESSAGE, ROLLBACK_MESSAGE, UNKNOWN }; 26 | 27 | class ROCKETMQCLIENT_API TransactionSendResult : public SendResult { 28 | public: 29 | TransactionSendResult() {} 30 | 31 | TransactionSendResult(const SendStatus& sendStatus, 32 | const std::string& msgId, 33 | const std::string& offsetMsgId, 34 | const MQMessageQueue& messageQueue, 35 | int64 queueOffset) 36 | : SendResult(sendStatus, msgId, offsetMsgId, messageQueue, queueOffset) {} 37 | 38 | LocalTransactionState getLocalTransactionState() { return m_localTransactionState; } 39 | 40 | void setLocalTransactionState(LocalTransactionState localTransactionState) { 41 | m_localTransactionState = localTransactionState; 42 | } 43 | 44 | private: 45 | LocalTransactionState m_localTransactionState; 46 | }; 47 | } // namespace rocketmq 48 | #endif -------------------------------------------------------------------------------- /libs/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | add_subdirectory(signature) 17 | -------------------------------------------------------------------------------- /libs/signature/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | project(signature) 17 | 18 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) 19 | set(LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/lib) 20 | 21 | aux_source_directory(src/ DIR_LIB_SRCS) 22 | 23 | add_library(Signature STATIC ${DIR_LIB_SRCS}) 24 | target_link_libraries(Signature ${deplibs}) 25 | set_target_properties(Signature PROPERTIES OUTPUT_NAME "Signature") 26 | 27 | # install 28 | install(TARGETS Signature DESTINATION lib) 29 | #install (DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ DESTINATION include/rocketmq) 30 | -------------------------------------------------------------------------------- /libs/signature/include/base64.h: -------------------------------------------------------------------------------- 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 | #ifndef BASE64_H 19 | #define BASE64_H 20 | 21 | /* Get size_t. */ 22 | #include 23 | 24 | /* Get bool. */ 25 | #include 26 | 27 | #ifdef __cplusplus 28 | namespace rocketmqSignature { 29 | #endif 30 | 31 | /* This uses that the expression (n+(k-1))/k means the smallest 32 | integer >= n/k, i.e., the ceiling of n/k. */ 33 | #define BASE64_LENGTH(inlen) ((((inlen) + 2) / 3) * 4) 34 | 35 | extern bool isbase64(char ch); 36 | 37 | extern void base64_encode(const char* in, size_t inlen, char* out, size_t outlen); 38 | 39 | extern size_t base64_encode_alloc(const char* in, size_t inlen, char** out); 40 | 41 | extern bool base64_decode(const char* in, size_t inlen, char* out, size_t* outlen); 42 | 43 | extern bool base64_decode_alloc(const char* in, size_t inlen, char** out, size_t* outlen); 44 | 45 | #ifdef __cplusplus 46 | } 47 | #endif 48 | 49 | #endif /* BASE64_H */ 50 | -------------------------------------------------------------------------------- /libs/signature/include/hmac.h: -------------------------------------------------------------------------------- 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 | #ifndef _HMAC_HMAC_H 19 | #define _HMAC_HMAC_H 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | #include 26 | 27 | #ifndef SHA1_DIGEST_LEN 28 | #define SHA1_DIGEST_LEN 20 29 | #endif 30 | 31 | #ifndef SHA256_DIGEST_LEN 32 | #define SHA256_DIGEST_LEN 32 33 | #endif 34 | 35 | #ifndef SHA512_DIGEST_LEN 36 | #define SHA512_DIGEST_LEN 64 37 | #endif 38 | 39 | /* 40 | * hmac_sha1: 41 | * hmac_sha256: 42 | * hmac_sha512: 43 | * Calculate Hashed Message Authentication Code with sha1/256/512 algorithm 44 | * Caution: ret_buf should provide enough space for HMAC result. 45 | * 46 | * @key [in]: the secure-key string 47 | * @key_len [in]: the length of secure-key 48 | * @data [in]: data string could be calculated. 49 | * @data_len [in]: the length of data. length is needed because strlen could not take effect. 50 | * @ret_buf [out]: HMAC result stored in ret_buf. 51 | */ 52 | 53 | #ifdef __cplusplus 54 | namespace rocketmqSignature { 55 | 56 | #endif 57 | 58 | extern int hmac_sha1(const void* key, size_t key_len, const void* data, size_t data_len, void* ret_buf); 59 | extern int hmac_sha256(const void* key, size_t key_len, const void* data, size_t data_len, void* ret_buf); 60 | extern int hmac_sha512(const void* key, size_t key_len, const void* data, size_t data_len, void* ret_buf); 61 | 62 | #ifdef __cplusplus 63 | } 64 | #endif 65 | 66 | #ifdef __cplusplus 67 | } 68 | #endif 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /libs/signature/include/param_list.h: -------------------------------------------------------------------------------- 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 | #ifndef PARAM_LIST_H 19 | #define PARAM_LIST_H 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | #ifdef __cplusplus 26 | namespace rocketmqSignature { 27 | #endif 28 | 29 | typedef struct _spas_param_node { 30 | char* name; 31 | char* value; 32 | struct _spas_param_node* pnext; 33 | } SPAS_PARAM_NODE; 34 | 35 | typedef struct _spas_param_list { 36 | SPAS_PARAM_NODE* phead; 37 | unsigned int length; /* count of nodes */ 38 | unsigned int size; /* total size of string presentation */ 39 | } SPAS_PARAM_LIST; 40 | 41 | extern SPAS_PARAM_LIST* create_param_list(void); 42 | extern int add_param_to_list(SPAS_PARAM_LIST* list, const char* name, const char* value); 43 | extern void free_param_list(SPAS_PARAM_LIST* list); 44 | extern char* param_list_to_str(const SPAS_PARAM_LIST* list); 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | 50 | #ifdef __cplusplus 51 | } 52 | #endif 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /package_rocketmq.mri: -------------------------------------------------------------------------------- 1 | create librocketmq.a 2 | addlib ../bin/lib/libboost_chrono.a 3 | addlib ../bin/lib/libboost_date_time.a 4 | addlib ../bin/lib/libboost_filesystem.a 5 | addlib ../bin/lib/libboost_iostreams.a 6 | addlib ../bin/lib/libboost_locale.a 7 | addlib ../bin/lib/libboost_log.a 8 | addlib ../bin/lib/libboost_log_setup.a 9 | addlib ../bin/lib/libboost_regex.a 10 | addlib ../bin/lib/libboost_serialization.a 11 | addlib ../bin/lib/libboost_system.a 12 | addlib ../bin/lib/libboost_thread.a 13 | addlib ../bin/lib/libboost_wserialization.a 14 | addlib ../bin/lib/libssl.a 15 | addlib ../bin/lib/libcrypto.a 16 | addlib ../bin/lib/libevent.a 17 | addlib ../bin/lib/libevent_core.a 18 | addlib ../bin/lib/libevent_extra.a 19 | addlib ../bin/lib/libevent_pthreads.a 20 | addlib ../bin/lib/libevent_openssl.a 21 | addlib ../bin/lib/libjsoncpp.a 22 | addlib ../bin/lib/libSignature.a 23 | addlib ../bin/librocketmq.a 24 | save 25 | end 26 | -------------------------------------------------------------------------------- /rpm/build.sh: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | BASEDIR=$(dirname "$0") 16 | if [[ ! -d ${BASEDIR}/rocketmq_x64/CENTOS/ ]]; then 17 | echo "Can not find SPEC FILE" 18 | exit 1 19 | fi 20 | if [[ ! -d /root/rpmbuild/SOURCES/rocketmq/include ]]; then 21 | mkdir -p /root/rpmbuild/SOURCES/rocketmq 22 | mkdir -p /root/rpmbuild/SOURCES/rocketmq/include 23 | mkdir -p /root/rpmbuild/SOURCES/rocketmq/bin 24 | mkdir -p /root/rpmbuild/SPECS/ 25 | fi 26 | cp -R ${BASEDIR}/../include/* /root/rpmbuild/SOURCES/rocketmq/include 27 | cp ${BASEDIR}/../bin/librocketmq.so /root/rpmbuild/SOURCES/rocketmq/bin 28 | cp ${BASEDIR}/../bin/librocketmq.a /root/rpmbuild/SOURCES/rocketmq/bin 29 | 30 | cp ${BASEDIR}/rocketmq_x64/CENTOS/rocketmq-client-cpp.spec /root/rpmbuild/SPECS/ 31 | rpmbuild -bb /root/rpmbuild/SPECS/rocketmq-client-cpp.spec 32 | 33 | cp /root/rpmbuild/RPMS/x86_64/*.rpm ${BASEDIR}/rocketmq_x64 34 | -------------------------------------------------------------------------------- /rpm/rocketmq_x64/CENTOS/rocketmq-client-cpp.spec: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | Summary: A C++ Client of Apache RocketMQ 17 | 18 | Name: rocketmq-client-cpp 19 | Version: 2.2.0 20 | Release: centos 21 | Group: Apache 22 | License: APLv2 23 | Source: https://github.com/apache/rocketmq-client-cpp 24 | URL: http://rocketmq.apache.org/ 25 | Distribution: Linux 26 | 27 | %define _prefix /usr/local 28 | 29 | AutoReqProv: no 30 | 31 | %description 32 | A C++ Client of Apache RocketMQ 33 | 34 | %prep 35 | 36 | pwd 37 | 38 | cat /etc/redhat-release|sed -r 's/.* ([0-9]+)\..*/\1/' 39 | 40 | OS_VERSION=`cat /etc/redhat-release|sed -r 's/.* ([0-9]+)\..*/\1/'` 41 | 42 | echo "OS_VERSION=${OS_VERSION}" 43 | 44 | 45 | %build 46 | 47 | %install 48 | # create dirs 49 | mkdir -p $RPM_BUILD_ROOT%{_prefix} 50 | 51 | # create dirs 52 | mkdir -p $RPM_BUILD_ROOT%{_prefix}/lib 53 | mkdir -p $RPM_BUILD_ROOT%{_prefix}/include/rocketmq 54 | 55 | # copy files 56 | cp -f ${RPM_SOURCE_DIR}/rocketmq/bin/librocketmq.so $RPM_BUILD_ROOT%{_prefix}/lib 57 | cp -f ${RPM_SOURCE_DIR}/rocketmq/bin/librocketmq.a $RPM_BUILD_ROOT%{_prefix}/lib 58 | cp -rf ${RPM_SOURCE_DIR}/rocketmq/include/* $RPM_BUILD_ROOT%{_prefix}/include/rocketmq 59 | 60 | %post 61 | # As '/usr/local/lib' is not included in dynamic libraries on CentOS, it should be made explicit to dlopen() 62 | echo "/usr/local/lib" > /etc/ld.so.conf.d/librocketmq.x86_64.conf 63 | /sbin/ldconfig 64 | 65 | # package information 66 | %files 67 | # set file attribute here 68 | %defattr(-, root, root, 0755) 69 | %{_prefix}/lib 70 | %{_prefix}/include 71 | 72 | %define debug_package %{nil} 73 | %define __os_install_post %{nil} 74 | -------------------------------------------------------------------------------- /src/MQClientManager.h: -------------------------------------------------------------------------------- 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 | #ifndef __MQCLIENTMANAGER_H__ 18 | #define __MQCLIENTMANAGER_H__ 19 | 20 | #include 21 | #include 22 | #include "Logging.h" 23 | #include "MQClientFactory.h" 24 | 25 | namespace rocketmq { 26 | // FTMAP; 46 | FTMAP m_factoryTable; 47 | }; 48 | 49 | // v; 31 | UtilAll::Split(v, arg_str_, " "); 32 | m_args.insert(m_args.end(), v.begin(), v.end()); 33 | } 34 | 35 | string Arg_helper::get_option(int idx_) const { 36 | if ((size_t)idx_ >= m_args.size()) { 37 | return ""; 38 | } 39 | return m_args[idx_]; 40 | } 41 | 42 | bool Arg_helper::is_enable_option(string opt_) const { 43 | for (size_t i = 0; i < m_args.size(); ++i) { 44 | if (opt_ == m_args[i]) { 45 | return true; 46 | } 47 | } 48 | return false; 49 | } 50 | 51 | string Arg_helper::get_option_value(string opt_) const { 52 | string ret = ""; 53 | for (size_t i = 0; i < m_args.size(); ++i) { 54 | if (opt_ == m_args[i]) { 55 | size_t value_idx = ++i; 56 | if (value_idx >= m_args.size()) { 57 | return ret; 58 | } 59 | ret = m_args[value_idx]; 60 | return ret; 61 | } 62 | } 63 | return ret; 64 | } 65 | 66 | // 22 | #include "MQClientException.h" 23 | #include "SubscriptionData.h" 24 | #include "UtilAll.h" 25 | namespace rocketmq { 26 | //setSubString(SUB_ALL); 35 | } else { 36 | vector out; 37 | UtilAll::Split(out, subString, "||"); 38 | 39 | if (out.empty()) { 40 | THROW_MQEXCEPTION(MQClientException, "FilterAPI subString split error", -1); 41 | } 42 | 43 | for (size_t i = 0; i < out.size(); i++) { 44 | string tag = out[i]; 45 | if (!tag.empty()) { 46 | UtilAll::Trim(tag); 47 | if (!tag.empty()) { 48 | subscriptionData->putTagsSet(tag); 49 | subscriptionData->putCodeSet(tag); 50 | } 51 | } 52 | } 53 | } 54 | 55 | return subscriptionData; 56 | } 57 | }; 58 | 59 | // 21 | #include 22 | 23 | namespace rocketmq { 24 | 25 | class MQClientErrorContainer { 26 | public: 27 | static void setErr(const std::string& str); 28 | static const std::string& getErr(); 29 | 30 | private: 31 | static thread_local std::string t_err; 32 | }; 33 | 34 | } // namespace rocketmq 35 | 36 | #endif // __MQ_CLIENT_ERROR_CONTAINER_H__ 37 | -------------------------------------------------------------------------------- /src/common/MQVersion.cpp: -------------------------------------------------------------------------------- 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 | #include "MQVersion.h" 18 | 19 | namespace rocketmq { 20 | int MQVersion::s_CurrentVersion = MQVersion::V4_6_0; 21 | std::string MQVersion::s_CurrentLanguage = "CPP"; 22 | 23 | //= HIGHER_VERSION) { 30 | currentVersion = HIGHER_VERSION; 31 | } 32 | return RocketMQCPPClientVersion[currentVersion]; 33 | } 34 | // 19 | #include 20 | #include "Logging.h" 21 | #include "NameSpaceUtil.h" 22 | 23 | using namespace std; 24 | namespace rocketmq { 25 | 26 | void MessageAccessor::withNameSpace(MQMessage& msg, const string& nameSpace) { 27 | if (!nameSpace.empty()) { 28 | string originTopic = msg.getTopic(); 29 | string newTopic = nameSpace + NAMESPACE_SPLIT_FLAG + originTopic; 30 | msg.setTopic(newTopic); 31 | } 32 | } 33 | 34 | void MessageAccessor::withoutNameSpaceSingle(MQMessageExt& msg, const string& nameSpace) { 35 | if (!nameSpace.empty()) { 36 | string originTopic = msg.getTopic(); 37 | auto index = originTopic.find(nameSpace); 38 | if (index != string::npos) { 39 | string newTopic = 40 | originTopic.substr(index + nameSpace.length() + NAMESPACE_SPLIT_FLAG.length(), originTopic.length()); 41 | msg.setTopic(newTopic); 42 | LOG_DEBUG("Find Name Space Prefix in MessageID[%s], OriginTopic[%s], NewTopic[%s]", msg.getMsgId().c_str(), 43 | originTopic.c_str(), newTopic.c_str()); 44 | } 45 | } 46 | } 47 | void MessageAccessor::withoutNameSpace(vector& msgs, const string& nameSpace) { 48 | if (!nameSpace.empty()) { 49 | // for_each(msgs.cbegin(), msgs.cend(), bind2nd(&MessageAccessor::withoutNameSpaceSingle, nameSpace)); 50 | for (auto iter = msgs.begin(); iter != msgs.end(); iter++) { 51 | withoutNameSpaceSingle(*iter, nameSpace); 52 | } 53 | } 54 | } 55 | // 21 | #include 22 | #include "MQMessage.h" 23 | #include "MQMessageExt.h" 24 | namespace rocketmq { 25 | //& msgs, const std::string& nameSpace); 31 | }; 32 | 33 | // 22 | 23 | using namespace std; 24 | 25 | static const string ENDPOINT_PREFIX = "http://"; 26 | static const unsigned int ENDPOINT_PREFIX_LENGTH = ENDPOINT_PREFIX.length(); 27 | static const string NAMESPACE_PREFIX = "MQ_INST_"; 28 | static const int NAMESPACE_PREFIX_LENGTH = NAMESPACE_PREFIX.length(); 29 | static const string NAMESPACE_SPLIT_FLAG = "%"; 30 | 31 | namespace rocketmq { 32 | class NameSpaceUtil { 33 | public: 34 | static bool isEndPointURL(const string& nameServerAddr); 35 | 36 | static string formatNameServerURL(const string& nameServerAddr); 37 | 38 | static string getNameSpaceFromNsURL(const string& nameServerAddr); 39 | 40 | static bool checkNameSpaceExistInNsURL(const string& nameServerAddr); 41 | 42 | static bool checkNameSpaceExistInNameServer(const string& nameServerAddr); 43 | 44 | static string withNameSpace(const string& source, const string& ns); 45 | 46 | static string withoutNameSpace(const string& source, const string& ns); 47 | 48 | static bool hasNameSpace(const string& source, const string& ns); 49 | }; 50 | 51 | } // namespace rocketmq 52 | #endif //__NAMESPACEUTIL_H__ 53 | -------------------------------------------------------------------------------- /src/common/NamesrvConfig.h: -------------------------------------------------------------------------------- 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 | #ifndef __NAMESRVCONFIG_H__ 18 | #define __NAMESRVCONFIG_H__ 19 | 20 | #include 21 | #include 22 | #include "UtilAll.h" 23 | 24 | namespace rocketmq { 25 | // 21 | 22 | namespace rocketmq { 23 | // 21 | 22 | namespace rocketmq { 23 | //groupName = groupName; 28 | consumeEnable = true; 29 | consumeFromMinEnable = true; 30 | consumeBroadcastEnable = true; 31 | retryQueueNums = 1; 32 | retryMaxTimes = 5; 33 | brokerId = MASTER_ID; 34 | whichBrokerWhenConsumeSlowly = 1; 35 | } 36 | 37 | string groupName; 38 | bool consumeEnable; 39 | bool consumeFromMinEnable; 40 | bool consumeBroadcastEnable; 41 | int retryQueueNums; 42 | int retryMaxTimes; 43 | int brokerId; 44 | int whichBrokerWhenConsumeSlowly; 45 | }; 46 | 47 | // 21 | #include 22 | #include 23 | #include 24 | #include "Logging.h" 25 | #include "UtilAll.h" 26 | 27 | namespace rocketmq { 28 | class TopAddressing { 29 | public: 30 | TopAddressing(const std::string& unitName); 31 | virtual ~TopAddressing(); 32 | 33 | public: 34 | virtual string fetchNSAddr(const string& NSDomain); 35 | 36 | private: 37 | string clearNewLine(const string& str); 38 | void updateNameServerAddressList(const string& adds); 39 | int IsIPAddr(const char* sValue); 40 | 41 | private: 42 | boost::mutex m_addrLock; 43 | list m_addrs; 44 | string m_unitName; 45 | }; 46 | } // namespace rocketmq 47 | #endif 48 | -------------------------------------------------------------------------------- /src/common/TopicConfig.h: -------------------------------------------------------------------------------- 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 | #ifndef __TOPICCONFIG_H__ 18 | #define __TOPICCONFIG_H__ 19 | 20 | #include 21 | #include "TopicFilterType.h" 22 | #include "UtilAll.h" 23 | namespace rocketmq { 24 | // 21 | #include "MQClientException.h" 22 | #include "MQMessage.h" 23 | #include "UtilAll.h" 24 | namespace rocketmq { 25 | // 19 | #include 20 | #include "UtilAll.h" 21 | 22 | namespace rocketmq { 23 | const char* VirtualEnvUtil::VIRTUAL_APPGROUP_PREFIX = "%%PROJECT_%s%%"; 24 | 25 | // 21 | namespace rocketmq { 22 | // 8 | #include 9 | 10 | namespace rocketmq { 11 | 12 | BigEndianReader::BigEndianReader(const char* buf, size_t len) : ptr_(buf), end_(ptr_ + len) {} 13 | 14 | bool BigEndianReader::Skip(size_t len) { 15 | if (ptr_ + len > end_) 16 | return false; 17 | ptr_ += len; 18 | return true; 19 | } 20 | 21 | bool BigEndianReader::ReadBytes(void* out, size_t len) { 22 | if (ptr_ + len > end_) 23 | return false; 24 | memcpy(out, ptr_, len); 25 | ptr_ += len; 26 | return true; 27 | } 28 | 29 | template 30 | bool BigEndianReader::Read(T* value) { 31 | if (ptr_ + sizeof(T) > end_) 32 | return false; 33 | ReadBigEndian(ptr_, value); 34 | ptr_ += sizeof(T); 35 | return true; 36 | } 37 | 38 | bool BigEndianReader::ReadU8(uint8_t* value) { 39 | return Read(value); 40 | } 41 | 42 | bool BigEndianReader::ReadU16(uint16_t* value) { 43 | return Read(value); 44 | } 45 | 46 | bool BigEndianReader::ReadU32(uint32_t* value) { 47 | return Read(value); 48 | } 49 | 50 | bool BigEndianReader::ReadU64(uint64_t* value) { 51 | return Read(value); 52 | } 53 | 54 | BigEndianWriter::BigEndianWriter(char* buf, size_t len) : ptr_(buf), end_(ptr_ + len) {} 55 | 56 | bool BigEndianWriter::Skip(size_t len) { 57 | if (ptr_ + len > end_) 58 | return false; 59 | ptr_ += len; 60 | return true; 61 | } 62 | 63 | bool BigEndianWriter::WriteBytes(const void* buf, size_t len) { 64 | if (ptr_ + len > end_) 65 | return false; 66 | memcpy(ptr_, buf, len); 67 | ptr_ += len; 68 | return true; 69 | } 70 | 71 | template 72 | bool BigEndianWriter::Write(T value) { 73 | if (ptr_ + sizeof(T) > end_) 74 | return false; 75 | WriteBigEndian(ptr_, value); 76 | ptr_ += sizeof(T); 77 | return true; 78 | } 79 | 80 | bool BigEndianWriter::WriteU8(uint8_t value) { 81 | return Write(value); 82 | } 83 | 84 | bool BigEndianWriter::WriteU16(uint16_t value) { 85 | return Write(value); 86 | } 87 | 88 | bool BigEndianWriter::WriteU32(uint32_t value) { 89 | return Write(value); 90 | } 91 | 92 | bool BigEndianWriter::WriteU64(uint64_t value) { 93 | return Write(value); 94 | } 95 | 96 | } // namespace rocketmq 97 | -------------------------------------------------------------------------------- /src/common/noncopyable.h: -------------------------------------------------------------------------------- 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 | #ifndef __NONCOPYABLE_H__ 18 | #define __NONCOPYABLE_H__ 19 | 20 | namespace rocketmq { 21 | 22 | class noncopyable { 23 | protected: 24 | noncopyable() = default; 25 | ~noncopyable() = default; 26 | 27 | noncopyable(const noncopyable&) = delete; 28 | noncopyable& operator=(const noncopyable&) = delete; 29 | }; 30 | 31 | } // namespace rocketmq 32 | 33 | #endif //__NONCOPYABLE_H__ 34 | -------------------------------------------------------------------------------- /src/common/sync_http_client.h: -------------------------------------------------------------------------------- 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 | #ifndef ROCKETMQ_CLIENT4CPP__SYNC_HTTP_CLIENT_H_ 18 | #define ROCKETMQ_CLIENT4CPP__SYNC_HTTP_CLIENT_H_ 19 | 20 | #include 21 | 22 | namespace rocketmq { 23 | class Url; 24 | 25 | extern bool SyncfetchNsAddr(const Url& url_s, std::string& body); 26 | 27 | } // namespace rocketmq 28 | 29 | #endif // ROCKETMQ_CLIENT4CPP__SYNC_HTTP_CLIENT_H_ 30 | -------------------------------------------------------------------------------- /src/common/url.cpp: -------------------------------------------------------------------------------- 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 | #include "url.h" 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | namespace rocketmq { 25 | 26 | Url::Url(const std::string& url_s) { 27 | parse(url_s); 28 | } 29 | 30 | void Url::parse(const std::string& url_s) { 31 | const std::string prot_end("://"); 32 | auto prot_i = std::search(url_s.begin(), url_s.end(), prot_end.begin(), prot_end.end()); 33 | protocol_.reserve(std::distance(url_s.begin(), prot_i)); 34 | std::transform(url_s.begin(), prot_i, std::back_inserter(protocol_), 35 | std::ptr_fun(tolower)); // protocol is icase 36 | 37 | if (prot_i == url_s.end()) 38 | return; 39 | 40 | std::advance(prot_i, prot_end.length()); 41 | 42 | auto path_i = find(prot_i, url_s.end(), ':'); 43 | std::string::const_iterator path_end_i; 44 | if (path_i == url_s.end()) { 45 | // not include port, use default port 46 | port_ = "80"; 47 | path_i = std::find(prot_i, url_s.end(), '/'); 48 | path_end_i = path_i; 49 | } else { 50 | auto port_i = find(path_i + 1, url_s.end(), '/'); 51 | port_.insert(port_.begin(), path_i + 1, port_i); 52 | path_end_i = path_i + port_.length() + 1; 53 | } 54 | 55 | host_.reserve(distance(prot_i, path_i)); 56 | std::transform(prot_i, path_i, std::back_inserter(host_), std::ptr_fun(tolower)); // host is icase} 57 | 58 | auto query_i = find(path_end_i, url_s.end(), '?'); 59 | path_.assign(path_end_i, query_i); 60 | if (query_i != url_s.end()) 61 | ++query_i; 62 | query_.assign(query_i, url_s.end()); 63 | } 64 | 65 | } // namespace rocketmq 66 | -------------------------------------------------------------------------------- /src/common/url.h: -------------------------------------------------------------------------------- 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 | #ifndef ROCKETMQ_CLIENT4CPP_URL_HH_ 18 | #define ROCKETMQ_CLIENT4CPP_URL_HH_ 19 | 20 | #include 21 | 22 | namespace rocketmq { 23 | class Url { 24 | public: 25 | Url(const std::string& url_s); // omitted copy, ==, accessors, ... 26 | 27 | private: 28 | void parse(const std::string& url_s); 29 | 30 | public: 31 | std::string protocol_; 32 | std::string host_; 33 | std::string port_; 34 | std::string path_; 35 | std::string query_; 36 | }; 37 | } // namespace rocketmq 38 | #endif // ROCKETMQ_CLIENT4CPP_URL_HH_ 39 | -------------------------------------------------------------------------------- /src/consumer/ConsumeMessageHookImpl.h: -------------------------------------------------------------------------------- 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 | #ifndef __ROCKETMQ_CONSUME_MESSAGE_RPC_HOOK_IMPL_H__ 18 | #define __ROCKETMQ_CONSUME_MESSAGE_RPC_HOOK_IMPL_H__ 19 | 20 | #include 21 | #include "ConsumeMessageContext.h" 22 | #include "ConsumeMessageHook.h" 23 | namespace rocketmq { 24 | class ConsumeMessageHookImpl : public ConsumeMessageHook { 25 | public: 26 | virtual ~ConsumeMessageHookImpl() {} 27 | virtual std::string getHookName(); 28 | virtual void executeHookBefore(ConsumeMessageContext* context); 29 | virtual void executeHookAfter(ConsumeMessageContext* context); 30 | }; 31 | } // namespace rocketmq 32 | #endif -------------------------------------------------------------------------------- /src/consumer/FindBrokerResult.h: -------------------------------------------------------------------------------- 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 | #ifndef __FINDBROKERRESULT_H__ 19 | #define __FINDBROKERRESULT_H__ 20 | 21 | namespace rocketmq { 22 | //& src) 34 | : pullStatus(pullStatus), nextBeginOffset(nextBeginOffset), minOffset(minOffset), maxOffset(maxOffset) { 35 | msgFoundList.reserve(src.size()); 36 | for (size_t i = 0; i < src.size(); i++) { 37 | msgFoundList.push_back(src[i]); 38 | } 39 | } 40 | 41 | PullResult::~PullResult() { 42 | msgFoundList.clear(); 43 | } 44 | 45 | //(messageBinary)) {} 47 | 48 | PullResultExt(PullStatus pullStatus, 49 | int64 nextBeginOffset, 50 | int64 minOffset, 51 | int64 maxOffset, 52 | int suggestWhichBrokerId) 53 | : PullResult(pullStatus, nextBeginOffset, minOffset, maxOffset), suggestWhichBrokerId(suggestWhichBrokerId) {} 54 | 55 | virtual ~PullResultExt() {} 56 | 57 | public: 58 | int suggestWhichBrokerId; 59 | MemoryBlock msgMemBlock; 60 | }; 61 | 62 | } // namespace rocketmq 63 | -------------------------------------------------------------------------------- /src/consumer/SubscriptionData.h: -------------------------------------------------------------------------------- 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 | #ifndef __SUBSCRIPTIONDATA_H__ 18 | #define __SUBSCRIPTIONDATA_H__ 19 | 20 | #include 21 | #include "UtilAll.h" 22 | #include "json/json.h" 23 | 24 | namespace rocketmq { 25 | //& getTagsSet(); 44 | 45 | void putCodeSet(const string& tag); 46 | 47 | bool operator==(const SubscriptionData& other) const; 48 | bool operator<(const SubscriptionData& other) const; 49 | 50 | Json::Value toJson() const; 51 | 52 | private: 53 | string m_topic; 54 | string m_subString; 55 | int64 m_subVersion; 56 | vector m_tagSet; 57 | vector m_codeSet; 58 | }; 59 | // 19 | #include "windows.h" 20 | 21 | BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { 22 | switch (ul_reason_for_call) { 23 | case DLL_PROCESS_ATTACH: 24 | break; 25 | case DLL_THREAD_ATTACH: 26 | break; 27 | case DLL_THREAD_DETACH: 28 | break; 29 | case DLL_PROCESS_DETACH: 30 | break; 31 | } 32 | return TRUE; 33 | } 34 | -------------------------------------------------------------------------------- /src/extern/CBatchMessage.cpp: -------------------------------------------------------------------------------- 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 | #include 19 | 20 | #include "CBatchMessage.h" 21 | #include "CCommon.h" 22 | #include "CMessage.h" 23 | #include "MQMessage.h" 24 | 25 | using std::vector; 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | using namespace rocketmq; 32 | 33 | CBatchMessage* CreateBatchMessage() { 34 | vector* msgs = new vector(); 35 | return (CBatchMessage*)msgs; 36 | } 37 | 38 | int AddMessage(CBatchMessage* batchMsg, CMessage* msg) { 39 | if (msg == NULL) { 40 | return NULL_POINTER; 41 | } 42 | if (batchMsg == NULL) { 43 | return NULL_POINTER; 44 | } 45 | MQMessage* message = (MQMessage*)msg; 46 | ((vector*)batchMsg)->push_back(*message); 47 | return OK; 48 | } 49 | int DestroyBatchMessage(CBatchMessage* batchMsg) { 50 | if (batchMsg == NULL) { 51 | return NULL_POINTER; 52 | } 53 | delete (vector*)batchMsg; 54 | return OK; 55 | } 56 | 57 | #ifdef __cplusplus 58 | }; 59 | #endif 60 | -------------------------------------------------------------------------------- /src/extern/CErrorMessage.cpp: -------------------------------------------------------------------------------- 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 | #include "CErrorMessage.h" 19 | #include "CCommon.h" 20 | #include "MQClientErrorContainer.h" 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | using namespace rocketmq; 26 | 27 | const char* GetLatestErrorMessage() { 28 | return MQClientErrorContainer::getErr().c_str(); 29 | } 30 | 31 | #ifdef __cplusplus 32 | }; 33 | #endif -------------------------------------------------------------------------------- /src/extern/CSendResult.cpp: -------------------------------------------------------------------------------- 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 | #include "CSendResult.h" 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | #ifdef __cplusplus 25 | } 26 | #endif 27 | -------------------------------------------------------------------------------- /src/include/BatchMessage.h: -------------------------------------------------------------------------------- 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 | #ifndef __BATCHMESSAGE_H__ 19 | #define __BATCHMESSAGE_H__ 20 | #include 21 | #include "MQMessage.h" 22 | namespace rocketmq { 23 | class BatchMessage : public MQMessage { 24 | public: 25 | static std::string encode(std::vector& msgs); 26 | static std::string encode(MQMessage& message); 27 | }; 28 | } // namespace rocketmq 29 | #endif -------------------------------------------------------------------------------- /src/include/QueryResult.h: -------------------------------------------------------------------------------- 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 | #ifndef __QUERYRESULT_H__ 18 | #define __QUERYRESULT_H__ 19 | 20 | #include "MQMessageExt.h" 21 | #include "RocketMQClient.h" 22 | 23 | namespace rocketmq { 24 | //& messageList) { 28 | m_indexLastUpdateTimestamp = indexLastUpdateTimestamp; 29 | m_messageList = messageList; 30 | } 31 | 32 | uint64 getIndexLastUpdateTimestamp() { return m_indexLastUpdateTimestamp; } 33 | 34 | std::vector& getMessageList() { return m_messageList; } 35 | 36 | private: 37 | uint64 m_indexLastUpdateTimestamp; 38 | std::vector m_messageList; 39 | }; 40 | //& mqvec); 34 | 35 | static void decodes(const MemoryBlock* mem, vector& mqvec, bool readBody); 36 | 37 | static string messageProperties2String(const map& properties); 38 | static void string2messageProperties(const string& propertiesString, map& properties); 39 | 40 | private: 41 | static MQMessageExt* decode(MemoryInputStream& byteBuffer); 42 | static MQMessageExt* decode(MemoryInputStream& byteBuffer, bool readBody); 43 | 44 | public: 45 | static const char NAME_VALUE_SEPARATOR; 46 | static const char PROPERTY_SEPARATOR; 47 | static const int MSG_ID_LENGTH; 48 | static int MessageMagicCodePostion; 49 | static int MessageFlagPostion; 50 | static int MessagePhysicOffsetPostion; 51 | static int MessageStoreTimestampPostion; 52 | }; 53 | } //m_address = id.m_address; 34 | this->m_offset = id.m_offset; 35 | return *this; 36 | } 37 | 38 | sockaddr getAddress() const { return m_address; } 39 | 40 | void setAddress(sockaddr address) { m_address = address; } 41 | 42 | int64 getOffset() const { return m_offset; } 43 | 44 | void setOffset(int64 offset) { m_offset = offset; } 45 | 46 | private: 47 | sockaddr m_address; 48 | int64 m_offset; 49 | }; 50 | 51 | } // namespace rocketmq 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /src/producer/SendMessageHookImpl.h: -------------------------------------------------------------------------------- 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 | #ifndef __ROCKETMQ_SEND_MESSAGE_RPC_HOOK_IMPL_H__ 18 | #define __ROCKETMQ_SEND_MESSAGE_RPC_HOOK_IMPL_H__ 19 | 20 | #include 21 | #include "SendMessageContext.h" 22 | #include "SendMessageHook.h" 23 | namespace rocketmq { 24 | class SendMessageHookImpl : public SendMessageHook { 25 | public: 26 | virtual ~SendMessageHookImpl() {} 27 | virtual std::string getHookName(); 28 | virtual void executeHookBefore(SendMessageContext* context); 29 | virtual void executeHookAfter(SendMessageContext* context); 30 | }; 31 | } // namespace rocketmq 32 | #endif -------------------------------------------------------------------------------- /src/producer/StringIdMaker.h: -------------------------------------------------------------------------------- 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 | #ifndef __STRINGID_MAKER_H__ 18 | #define __STRINGID_MAKER_H__ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | namespace rocketmq { 26 | 27 | class StringIdMaker { 28 | private: 29 | StringIdMaker(); 30 | ~StringIdMaker(); 31 | 32 | public: 33 | static StringIdMaker& getInstance() { 34 | // After c++11, the initialization occurs exactly once 35 | static StringIdMaker singleton_; 36 | return singleton_; 37 | } 38 | 39 | /* ID format: 40 | * ip: 4 bytes 41 | * pid: 2 bytes 42 | * random: 4 bytes 43 | * time: 4 bytes 44 | * auto num: 2 bytes 45 | */ 46 | std::string createUniqID(); 47 | 48 | private: 49 | void setStartTime(uint64_t millis); 50 | 51 | static uint32_t getIP(); 52 | static void hexdump(unsigned char* buffer, char* out_buff, std::size_t index); 53 | 54 | private: 55 | uint64_t mStartTime; 56 | uint64_t mNextStartTime; 57 | std::atomic mCounter; 58 | 59 | char kFixString[21]; 60 | 61 | static const char sHexAlphabet[16]; 62 | }; 63 | 64 | } // namespace rocketmq 65 | #endif 66 | -------------------------------------------------------------------------------- /src/protocol/KVTable.h: -------------------------------------------------------------------------------- 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 | #ifndef __KVTABLE_H__ 19 | #define __KVTABLE_H__ 20 | #include 21 | #include 22 | #include "RemotingSerializable.h" 23 | 24 | using std::map; 25 | using std::string; 26 | 27 | namespace rocketmq { 28 | //& getTable() { return m_table; } 36 | 37 | void setTable(const map& table) { m_table = table; } 38 | 39 | private: 40 | map m_table; 41 | }; 42 | } // namespace rocketmq 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /src/protocol/MessageQueue.h: -------------------------------------------------------------------------------- 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 | #ifndef __MESSAGEQUEUE_H__ 18 | #define __MESSAGEQUEUE_H__ 19 | 20 | #include 21 | #include "json/json.h" 22 | 23 | namespace rocketmq { 24 | // 20 | #include 21 | #include "dataBlock.h" 22 | 23 | namespace rocketmq { 24 | // m_topicList; 31 | }; 32 | // StatsServerManager::getConsumeStatServer() { 32 | return getConsumeStatServer(serverName); 33 | } 34 | std::shared_ptr StatsServerManager::getConsumeStatServer(std::string serverName) { 35 | std::map>::iterator it = m_consumeStatusServers.find(serverName); 36 | if (it != m_consumeStatusServers.end()) { 37 | return it->second; 38 | } else { 39 | std::shared_ptr server = std::make_shared(); 40 | m_consumeStatusServers[serverName] = server; 41 | return server; 42 | } 43 | } 44 | void StatsServerManager::removeConsumeStatServer(std::string serverName) { 45 | std::map>::iterator it = m_consumeStatusServers.find(serverName); 46 | if (it != m_consumeStatusServers.end()) { 47 | m_consumeStatusServers.erase(it); 48 | } 49 | } 50 | 51 | StatsServerManager* StatsServerManager::getInstance() { 52 | static StatsServerManager instance; 53 | return &instance; 54 | } 55 | } // namespace rocketmq 56 | -------------------------------------------------------------------------------- /src/status/StatsServerManager.h: -------------------------------------------------------------------------------- 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 | #ifndef __CONSUMER_STATUS_SERVICE_MANAGER_H__ 19 | #define __CONSUMER_STATUS_SERVICE_MANAGER_H__ 20 | 21 | #include 22 | #include 23 | #include 24 | #include "ConsumeStats.h" 25 | #include "RocketMQClient.h" 26 | #include "ServiceState.h" 27 | #include "StatsServer.h" 28 | 29 | namespace rocketmq { 30 | class StatsServerManager { 31 | public: 32 | virtual ~StatsServerManager(); 33 | // void start(); 34 | // void shutdown(); 35 | std::shared_ptr getConsumeStatServer(); 36 | std::shared_ptr getConsumeStatServer(std::string serverName); 37 | void removeConsumeStatServer(std::string serverName); 38 | 39 | static StatsServerManager* getInstance(); 40 | 41 | private: 42 | StatsServerManager(); 43 | 44 | public: 45 | std::string serverName; 46 | 47 | private: 48 | std::map> m_consumeStatusServers; 49 | }; 50 | 51 | } // namespace rocketmq 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /src/thread/disruptor/event_publisher.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011, François Saint-Jacques 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // * Redistributions of source code must retain the above copyright 7 | // notice, this list of conditions and the following disclaimer. 8 | // * Redistributions in binary form must reproduce the above copyright 9 | // notice, this list of conditions and the following disclaimer in the 10 | // documentation and/or other materials provided with the distribution. 11 | // * Neither the name of the disruptor-- nor the 12 | // names of its contributors may be used to endorse or promote products 13 | // derived from this software without specific prior written permission. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 16 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | // DISCLAIMED. IN NO EVENT SHALL FRANÇOIS SAINT-JACQUES BE LIABLE FOR ANY 19 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | 26 | #ifndef DISRUPTOR_EVENT_PUBLISHER_H_ // NOLINT 27 | #define DISRUPTOR_EVENT_PUBLISHER_H_ // NOLINT 28 | 29 | #include "ring_buffer.h" 30 | 31 | namespace rocketmq { 32 | 33 | template 34 | class EventPublisher { 35 | public: 36 | EventPublisher(RingBuffer* ring_buffer) : ring_buffer_(ring_buffer) {} 37 | 38 | void PublishEvent(EventTranslatorInterface* translator) { 39 | int64_t sequence = ring_buffer_->Next(); 40 | translator->TranslateTo(sequence, ring_buffer_->Get(sequence)); 41 | ring_buffer_->Publish(sequence); 42 | } 43 | 44 | private: 45 | RingBuffer* ring_buffer_; 46 | }; 47 | 48 | }; // namespace rocketmq 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /src/thread/disruptor/exceptions.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011, François Saint-Jacques 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // * Redistributions of source code must retain the above copyright 7 | // notice, this list of conditions and the following disclaimer. 8 | // * Redistributions in binary form must reproduce the above copyright 9 | // notice, this list of conditions and the following disclaimer in the 10 | // documentation and/or other materials provided with the distribution. 11 | // * Neither the name of the disruptor-- nor the 12 | // names of its contributors may be used to endorse or promote products 13 | // derived from this software without specific prior written permission. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 16 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | // DISCLAIMED. IN NO EVENT SHALL FRANÇOIS SAINT-JACQUES BE LIABLE FOR ANY 19 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | 26 | #ifndef DISRUPTOR_EXCEPTIONS_H_ // NOLINT 27 | #define DISRUPTOR_EXCEPTIONS_H_ // NOLINT 28 | 29 | #include 30 | 31 | namespace rocketmq { 32 | 33 | class AlertException : public std::exception { 34 | }; 35 | 36 | }; // namespace rocketmq 37 | 38 | #endif // DISRUPTOR_EXCEPTIONS_H_ NOLINT 39 | -------------------------------------------------------------------------------- /src/thread/disruptor/utils.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011, François Saint-Jacques 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // * Redistributions of source code must retain the above copyright 7 | // notice, this list of conditions and the following disclaimer. 8 | // * Redistributions in binary form must reproduce the above copyright 9 | // notice, this list of conditions and the following disclaimer in the 10 | // documentation and/or other materials provided with the distribution. 11 | // * Neither the name of the disruptor-- nor the 12 | // names of its contributors may be used to endorse or promote products 13 | // derived from this software without specific prior written permission. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 16 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | // DISCLAIMED. IN NO EVENT SHALL FRANÇOIS SAINT-JACQUES BE LIABLE FOR ANY 19 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | 26 | #ifndef DISRUPTOR_UTILS_H_ // NOLINT 27 | #define DISRUPTOR_UTILS_H_ // NOLINT 28 | 29 | // From Google C++ Standard, modified to use C++11 deleted functions. 30 | // A macro to disallow the copy constructor and operator= functions. 31 | #define DISALLOW_COPY_AND_ASSIGN(TypeName) \ 32 | TypeName(const TypeName&) delete \ 33 | void operator=(const TypeName&) delete; 34 | 35 | #endif // DISRUPTOR_UTILS_H_ NOLINT 36 | -------------------------------------------------------------------------------- /src/trace/ConsumeMessageHook.h: -------------------------------------------------------------------------------- 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 | #ifndef __ROCKETMQ_COUNSUME_MESSAGE_RPC_HOOK_H__ 18 | #define __ROCKETMQ_COUNSUME_MESSAGE_RPC_HOOK_H__ 19 | 20 | #include 21 | #include "ConsumeMessageContext.h" 22 | namespace rocketmq { 23 | class ConsumeMessageHook { 24 | public: 25 | virtual ~ConsumeMessageHook() {} 26 | virtual std::string getHookName() = 0; 27 | virtual void executeHookBefore(ConsumeMessageContext* context) = 0; 28 | virtual void executeHookAfter(ConsumeMessageContext* context) = 0; 29 | }; 30 | } // namespace rocketmq 31 | #endif -------------------------------------------------------------------------------- /src/trace/SendMessageHook.h: -------------------------------------------------------------------------------- 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 | #ifndef __ROCKETMQ_SEND_MESSAGE_RPC_HOOK_H__ 18 | #define __ROCKETMQ_SEND_MESSAGE_RPC_HOOK_H__ 19 | 20 | #include 21 | #include "SendMessageContext.h" 22 | namespace rocketmq { 23 | class SendMessageHook { 24 | public: 25 | virtual ~SendMessageHook() {} 26 | virtual std::string getHookName() = 0; 27 | virtual void executeHookBefore(SendMessageContext* context) = 0; 28 | virtual void executeHookAfter(SendMessageContext* context) = 0; 29 | }; 30 | } // namespace rocketmq 31 | #endif -------------------------------------------------------------------------------- /src/trace/TraceConstant.cpp: -------------------------------------------------------------------------------- 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 | #include "TraceConstant.h" 19 | #include 20 | 21 | namespace rocketmq { 22 | std::string TraceConstant::GROUP_NAME = "_INNER_TRACE_PRODUCER"; 23 | std::string TraceConstant::TRACE_TOPIC = "rmq_sys_TRACE_DATA_"; 24 | std::string TraceConstant::DEFAULT_REDION = "DEFAULT_REGION"; 25 | char TraceConstant::CONTENT_SPLITOR = 1; 26 | char TraceConstant::FIELD_SPLITOR = 2; 27 | std::string TraceConstant::TRACE_TYPE_PUB = "Pub"; 28 | std::string TraceConstant::TRACE_TYPE_BEFORE = "SubBefore"; 29 | std::string TraceConstant::TRACE_TYPE_AFTER = "SubAfter"; 30 | } // namespace rocketmq 31 | -------------------------------------------------------------------------------- /src/trace/TraceConstant.h: -------------------------------------------------------------------------------- 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 | #ifndef __ROCKETMQ_TRACE_CONTANT_H_ 19 | #define __ROCKETMQ_TRACE_CONTANT_H_ 20 | 21 | #include 22 | 23 | namespace rocketmq { 24 | class TraceConstant { 25 | public: 26 | static std::string GROUP_NAME; 27 | static std::string TRACE_TOPIC; 28 | static std::string DEFAULT_REDION; 29 | static char CONTENT_SPLITOR; 30 | static char FIELD_SPLITOR; 31 | static std::string TRACE_TYPE_PUB; 32 | static std::string TRACE_TYPE_BEFORE; 33 | static std::string TRACE_TYPE_AFTER; 34 | }; 35 | enum TraceMessageType { 36 | TRACE_NORMAL_MSG = 0, 37 | TRACE_TRANS_HALF_MSG, 38 | TRACE_TRANS_COMMIT_MSG, 39 | TRACE_DELAY_MSG, 40 | }; 41 | enum TraceType { 42 | Pub, // for send message 43 | SubBefore, // for consume message before 44 | SubAfter, // for consum message after 45 | }; 46 | } // namespace rocketmq 47 | #endif // 48 | -------------------------------------------------------------------------------- /src/trace/TraceTransferBean.cpp: -------------------------------------------------------------------------------- 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 | #include "TraceTransferBean.h" 19 | #include 20 | #include 21 | 22 | namespace rocketmq { 23 | std::string TraceTransferBean::getTransData() { 24 | return m_transData; 25 | } 26 | 27 | void TraceTransferBean::setTransData(const std::string& transData) { 28 | m_transData = transData; 29 | } 30 | 31 | std::vector TraceTransferBean::getTransKey() { 32 | return m_transKey; 33 | } 34 | 35 | void TraceTransferBean::setTransKey(const std::string& transkey) { 36 | m_transKey.push_back(transkey); 37 | } 38 | } // namespace rocketmq -------------------------------------------------------------------------------- /src/trace/TraceTransferBean.h: -------------------------------------------------------------------------------- 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 | #ifndef __ROCKETMQ_TRACE_TRANSFER_BEAN_H__ 19 | #define __ROCKETMQ_TRACE_TRANSFER_BEAN_H__ 20 | 21 | #include 22 | #include 23 | 24 | namespace rocketmq { 25 | class TraceTransferBean { 26 | public: 27 | std::string getTransData(); 28 | 29 | void setTransData(const std::string& transData); 30 | 31 | std::vector getTransKey(); 32 | 33 | void setTransKey(const std::string& transkey); 34 | 35 | private: 36 | std::string m_transData; 37 | std::vector m_transKey; 38 | }; 39 | } // namespace rocketmq 40 | #endif -------------------------------------------------------------------------------- /src/trace/TraceUtil.h: -------------------------------------------------------------------------------- 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 | #ifndef __ROCKETMQ_TRACE_UTIL_H_ 19 | #define __ROCKETMQ_TRACE_UTIL_H_ 20 | 21 | #include 22 | #include "TraceConstant.h" 23 | #include "TraceContext.h" 24 | #include "TraceTransferBean.h" 25 | 26 | namespace rocketmq { 27 | class TraceUtil { 28 | public: 29 | static std::string CovertTraceTypeToString(TraceType type); 30 | static TraceTransferBean CovertTraceContextToTransferBean(TraceContext* ctx); 31 | }; 32 | } // namespace rocketmq 33 | #endif // 34 | -------------------------------------------------------------------------------- /src/transport/SocketUtil.h: -------------------------------------------------------------------------------- 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 | #ifndef __SOCKETUTIL_H__ 18 | #define __SOCKETUTIL_H__ 19 | 20 | #ifdef WIN32 21 | #ifndef WIN32_LEAN_AND_MEAN 22 | #define WIN32_LEAN_AND_MEAN 23 | #endif 24 | #include 25 | #include 26 | #include 27 | #pragma comment(lib, "ws2_32.lib") 28 | #else 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #endif 44 | 45 | #include "UtilAll.h" 46 | 47 | namespace rocketmq { 48 | // 18 | #include 19 | 20 | #include "gmock/gmock.h" 21 | #include "gtest/gtest.h" 22 | 23 | #include "MQClientManager.h" 24 | 25 | using namespace std; 26 | using namespace rocketmq; 27 | using rocketmq::MQClientFactory; 28 | using rocketmq::MQClientManager; 29 | using ::testing::InitGoogleMock; 30 | using ::testing::InitGoogleTest; 31 | using testing::Return; 32 | 33 | TEST(MQClientManagerTest, getClientFactory) { 34 | string clientId = "testClientId"; 35 | string unitName = "central"; 36 | MQClientFactory* factory = MQClientManager::getInstance()->getMQClientFactory(clientId, 1, 1000, 3000, unitName, true, 37 | DEFAULT_SSL_PROPERTY_FILE); 38 | MQClientFactory* factory2 = MQClientManager::getInstance()->getMQClientFactory(clientId, 1, 1000, 3000, unitName, 39 | true, DEFAULT_SSL_PROPERTY_FILE); 40 | EXPECT_EQ(factory, factory2); 41 | factory->shutdown(); 42 | 43 | MQClientManager::getInstance()->removeClientFactory(clientId); 44 | } 45 | TEST(MQClientManagerTest, removeClientFactory) { 46 | string clientId = "testClientId"; 47 | MQClientManager::getInstance()->removeClientFactory(clientId); 48 | } 49 | int main(int argc, char* argv[]) { 50 | InitGoogleMock(&argc, argv); 51 | return RUN_ALL_TESTS(); 52 | } 53 | -------------------------------------------------------------------------------- /test/src/common/ClientRPCHookTest.cpp: -------------------------------------------------------------------------------- 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 | #include "gmock/gmock.h" 18 | #include "gtest/gtest.h" 19 | 20 | #include "ClientRPCHook.h" 21 | #include "CommandHeader.h" 22 | #include "RemotingCommand.h" 23 | #include "SessionCredentials.h" 24 | 25 | using ::testing::InitGoogleMock; 26 | using ::testing::InitGoogleTest; 27 | using testing::Return; 28 | 29 | using rocketmq::RemotingCommand; 30 | using rocketmq::SendMessageRequestHeader; 31 | using rocketmq::SessionCredentials; 32 | 33 | using rocketmq::ClientRPCHook; 34 | 35 | TEST(clientRPCHook, doBeforeRequest) { 36 | SessionCredentials sessionCredentials; 37 | sessionCredentials.setAccessKey("accessKey"); 38 | sessionCredentials.setSecretKey("secretKey"); 39 | sessionCredentials.setAuthChannel("onsChannel"); 40 | 41 | ClientRPCHook clientRPCHook(sessionCredentials); 42 | 43 | RemotingCommand remotingCommand; 44 | clientRPCHook.doBeforeRequest("127.0.0.1:9876", remotingCommand); 45 | 46 | SendMessageRequestHeader* sendMessageRequestHeader = new SendMessageRequestHeader(); 47 | RemotingCommand headeRremotingCommand(17, sendMessageRequestHeader); 48 | clientRPCHook.doBeforeRequest("127.0.0.1:9876", headeRremotingCommand); 49 | 50 | headeRremotingCommand.setMsgBody("1231231"); 51 | clientRPCHook.doBeforeRequest("127.0.0.1:9876", headeRremotingCommand); 52 | } 53 | 54 | int main(int argc, char* argv[]) { 55 | InitGoogleMock(&argc, argv); 56 | testing::GTEST_FLAG(throw_on_failure) = true; 57 | testing::GTEST_FLAG(filter) = "clientRPCHook.doBeforeRequest"; 58 | int itestts = RUN_ALL_TESTS(); 59 | return itestts; 60 | } 61 | -------------------------------------------------------------------------------- /test/src/common/MQVersionTest.cpp: -------------------------------------------------------------------------------- 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 | #include "gmock/gmock.h" 18 | #include "gtest/gtest.h" 19 | 20 | #include "MQVersion.h" 21 | 22 | using ::testing::InitGoogleMock; 23 | using ::testing::InitGoogleTest; 24 | using testing::Return; 25 | 26 | using rocketmq::MQVersion; 27 | using rocketmq::RocketMQCPPClientVersion; 28 | 29 | TEST(MQVersionTest, Version2String) { 30 | for (int v = MQVersion::V3_0_0_SNAPSHOT; v <= MQVersion::HIGHER_VERSION; v++) { 31 | EXPECT_STREQ(MQVersion::GetVersionDesc(v), RocketMQCPPClientVersion[v]); 32 | } 33 | EXPECT_STREQ(MQVersion::GetVersionDesc(-100), MQVersion::GetVersionDesc(MQVersion::V3_0_0_SNAPSHOT)); 34 | EXPECT_STREQ(MQVersion::GetVersionDesc(MQVersion::V4_6_0), "V4_6_0"); 35 | EXPECT_STREQ(MQVersion::GetVersionDesc(MQVersion::HIGHER_VERSION + 100), 36 | MQVersion::GetVersionDesc(MQVersion::HIGHER_VERSION)); 37 | } 38 | 39 | int main(int argc, char* argv[]) { 40 | InitGoogleMock(&argc, argv); 41 | testing::GTEST_FLAG(throw_on_failure) = true; 42 | testing::GTEST_FLAG(filter) = "MQVersionTest.*"; 43 | int itestts = RUN_ALL_TESTS(); 44 | return itestts; 45 | } 46 | -------------------------------------------------------------------------------- /test/src/common/NamesrvConfigTest.cpp: -------------------------------------------------------------------------------- 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 | #include 19 | 20 | #include "gmock/gmock.h" 21 | #include "gtest/gtest.h" 22 | 23 | #include "NamesrvConfig.h" 24 | 25 | using std::string; 26 | 27 | using ::testing::InitGoogleMock; 28 | using ::testing::InitGoogleTest; 29 | using testing::Return; 30 | 31 | using rocketmq::NamesrvConfig; 32 | 33 | TEST(namesrvConfig, init) { 34 | NamesrvConfig namesrvConfig; 35 | 36 | const string home = "/home/rocketmq"; 37 | namesrvConfig.setRocketmqHome(home); 38 | EXPECT_EQ(namesrvConfig.getRocketmqHome(), "/home/rocketmq"); 39 | 40 | namesrvConfig.setKvConfigPath("/home/rocketmq"); 41 | EXPECT_EQ(namesrvConfig.getKvConfigPath(), "/home/rocketmq"); 42 | } 43 | 44 | int main(int argc, char* argv[]) { 45 | InitGoogleMock(&argc, argv); 46 | testing::GTEST_FLAG(throw_on_failure) = true; 47 | testing::GTEST_FLAG(filter) = "namesrvConfig.init"; 48 | int itestts = RUN_ALL_TESTS(); 49 | return itestts; 50 | } 51 | -------------------------------------------------------------------------------- /test/src/common/PermNametTest.cpp: -------------------------------------------------------------------------------- 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 | #include "gmock/gmock.h" 18 | #include "gtest/gtest.h" 19 | 20 | #include "PermName.h" 21 | 22 | using ::testing::InitGoogleMock; 23 | using ::testing::InitGoogleTest; 24 | using testing::Return; 25 | 26 | using rocketmq::PermName; 27 | 28 | TEST(permName, perm2String) { 29 | EXPECT_EQ(PermName::perm2String(0), "---"); 30 | EXPECT_EQ(PermName::perm2String(1), "--X"); 31 | EXPECT_EQ(PermName::perm2String(2), "-W"); 32 | EXPECT_EQ(PermName::perm2String(3), "-WX"); 33 | EXPECT_EQ(PermName::perm2String(4), "R--"); 34 | EXPECT_EQ(PermName::perm2String(5), "R-X"); 35 | EXPECT_EQ(PermName::perm2String(6), "RW"); 36 | EXPECT_EQ(PermName::perm2String(7), "RWX"); 37 | EXPECT_EQ(PermName::perm2String(8), "---"); 38 | } 39 | 40 | int main(int argc, char* argv[]) { 41 | InitGoogleMock(&argc, argv); 42 | testing::GTEST_FLAG(throw_on_failure) = true; 43 | testing::GTEST_FLAG(filter) = "permName.perm2String"; 44 | int itestts = RUN_ALL_TESTS(); 45 | return itestts; 46 | } 47 | -------------------------------------------------------------------------------- /test/src/common/UrlTest.cpp: -------------------------------------------------------------------------------- 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 | #include 19 | #include 20 | #include "CCommon.h" 21 | #include "CMQException.h" 22 | #include "CMessage.h" 23 | #include "CProducer.h" 24 | #include "CSendResult.h" 25 | #include "TopicConfig.h" 26 | #include "gmock/gmock.h" 27 | #include "gtest/gtest.h" 28 | #include "url.h" 29 | 30 | #include 31 | 32 | #include 33 | #include "CCommon.h" 34 | #include "CMQException.h" 35 | #include "CMessage.h" 36 | #include "CProducer.h" 37 | #include "CSendResult.h" 38 | 39 | using namespace std; 40 | using rocketmq::TopicConfig; 41 | using rocketmq::Url; 42 | using ::testing::InitGoogleMock; 43 | using ::testing::InitGoogleTest; 44 | using testing::Return; 45 | 46 | class MockTopicConfig : public TopicConfig { 47 | public: 48 | MOCK_METHOD0(getReadQueueNums, int()); 49 | }; 50 | 51 | TEST(Url, Url) { 52 | Url url_s("172.17.0.2:9876"); 53 | EXPECT_EQ(url_s.protocol_, "172.17.0.2:9876"); 54 | 55 | Url url_z("https://www.aliyun.com/RocketMQ?5.0"); 56 | EXPECT_EQ(url_z.protocol_, "https"); 57 | EXPECT_EQ(url_z.host_, "www.aliyun.com"); 58 | EXPECT_EQ(url_z.port_, "80"); 59 | EXPECT_EQ(url_z.path_, "/RocketMQ"); 60 | EXPECT_EQ(url_z.query_, "5.0"); 61 | 62 | Url url_path("https://www.aliyun.com:9876/RocketMQ?5.0"); 63 | EXPECT_EQ(url_path.port_, "9876"); 64 | MockTopicConfig topicConfig; 65 | EXPECT_CALL(topicConfig, getReadQueueNums()).WillRepeatedly(Return(-1)); 66 | int nums = topicConfig.getReadQueueNums(); 67 | cout << nums << endl; 68 | } 69 | 70 | int main(int argc, char* argv[]) { 71 | InitGoogleMock(&argc, argv); 72 | testing::GTEST_FLAG(filter) = "Url.Url"; 73 | int itestts = RUN_ALL_TESTS(); 74 | ; 75 | return itestts; 76 | } 77 | -------------------------------------------------------------------------------- /test/src/message/MQMessageIdTest.cpp: -------------------------------------------------------------------------------- 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 | #include 18 | 19 | #include "MQMessageId.h" 20 | #include "gmock/gmock.h" 21 | #include "gtest/gtest.h" 22 | 23 | using namespace std; 24 | using ::testing::InitGoogleMock; 25 | using ::testing::InitGoogleTest; 26 | using testing::Return; 27 | 28 | using rocketmq::MQMessageId; 29 | 30 | TEST(messageId, id) { 31 | int host; 32 | int port; 33 | sockaddr addr = rocketmq::IPPort2socketAddress(inet_addr("127.0.0.1"), 10091); 34 | MQMessageId id(addr, 1024); 35 | 36 | rocketmq::socketAddress2IPPort(id.getAddress(), host, port); 37 | EXPECT_EQ(host, inet_addr("127.0.0.1")); 38 | EXPECT_EQ(port, 10091); 39 | EXPECT_EQ(id.getOffset(), 1024); 40 | 41 | id.setAddress(rocketmq::IPPort2socketAddress(inet_addr("127.0.0.2"), 10092)); 42 | id.setOffset(2048); 43 | 44 | rocketmq::socketAddress2IPPort(id.getAddress(), host, port); 45 | EXPECT_EQ(host, inet_addr("127.0.0.2")); 46 | EXPECT_EQ(port, 10092); 47 | EXPECT_EQ(id.getOffset(), 2048); 48 | 49 | MQMessageId id2 = id; 50 | EXPECT_EQ(id2.getOffset(), 2048); 51 | } 52 | 53 | int main(int argc, char* argv[]) { 54 | InitGoogleMock(&argc, argv); 55 | 56 | testing::GTEST_FLAG(filter) = "messageId.*"; 57 | int itestts = RUN_ALL_TESTS(); 58 | return itestts; 59 | } 60 | -------------------------------------------------------------------------------- /test/src/producer/StringIdMakerTest.cpp: -------------------------------------------------------------------------------- 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 | #include 18 | #include 19 | 20 | #include "gmock/gmock.h" 21 | #include "gtest/gtest.h" 22 | 23 | #include "StringIdMaker.h" 24 | 25 | using namespace std; 26 | using namespace rocketmq; 27 | using ::testing::InitGoogleMock; 28 | using ::testing::InitGoogleTest; 29 | using testing::Return; 30 | 31 | TEST(StringIdMakerTest, get_unique_id) { 32 | string unique_id = StringIdMaker::getInstance().createUniqID(); 33 | cout << "unique_id: " << unique_id << endl; 34 | EXPECT_EQ(unique_id.size(), 32); 35 | } 36 | 37 | int main(int argc, char* argv[]) { 38 | InitGoogleMock(&argc, argv); 39 | return RUN_ALL_TESTS(); 40 | } 41 | -------------------------------------------------------------------------------- /test/src/protocol/KVTableTest.cpp: -------------------------------------------------------------------------------- 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 | #include 18 | #include 19 | 20 | #include "gmock/gmock.h" 21 | #include "gtest/gtest.h" 22 | 23 | #include "KVTable.h" 24 | 25 | using std::map; 26 | using std::string; 27 | 28 | using ::testing::InitGoogleMock; 29 | using ::testing::InitGoogleTest; 30 | using testing::Return; 31 | 32 | using rocketmq::KVTable; 33 | 34 | TEST(KVTable, init) { 35 | KVTable table; 36 | 37 | EXPECT_EQ(table.getTable().size(), 0); 38 | 39 | map maps; 40 | maps["string"] = "string"; 41 | table.setTable(maps); 42 | EXPECT_EQ(table.getTable().size(), 1); 43 | } 44 | 45 | int main(int argc, char* argv[]) { 46 | InitGoogleMock(&argc, argv); 47 | testing::GTEST_FLAG(throw_on_failure) = true; 48 | testing::GTEST_FLAG(filter) = "KVTable.*"; 49 | int itestts = RUN_ALL_TESTS(); 50 | return itestts; 51 | } 52 | -------------------------------------------------------------------------------- /test/src/transport/SocketUtilTest.cpp: -------------------------------------------------------------------------------- 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 | #include "gmock/gmock.h" 18 | #include "gtest/gtest.h" 19 | 20 | #include "SocketUtil.h" 21 | 22 | using ::testing::InitGoogleMock; 23 | using ::testing::InitGoogleTest; 24 | using testing::Return; 25 | 26 | TEST(socketUtil, init) { 27 | sockaddr addr = rocketmq::IPPort2socketAddress(inet_addr("127.0.0.1"), 10091); 28 | 29 | EXPECT_EQ(rocketmq::socketAddress2IPPort(addr), "1.0.0.127:10091"); 30 | 31 | int host; 32 | int port; 33 | 34 | rocketmq::socketAddress2IPPort(addr, host, port); 35 | EXPECT_EQ(host, inet_addr("127.0.0.1")); 36 | EXPECT_EQ(port, 10091); 37 | 38 | EXPECT_EQ(rocketmq::socketAddress2String(addr), "1.0.0.127"); 39 | } 40 | 41 | int main(int argc, char* argv[]) { 42 | InitGoogleMock(&argc, argv); 43 | testing::GTEST_FLAG(throw_on_failure) = true; 44 | testing::GTEST_FLAG(filter) = "socketUtil.init"; 45 | int itestts = RUN_ALL_TESTS(); 46 | return itestts; 47 | } 48 | --------------------------------------------------------------------------------