├── example ├── README.md ├── PushConsumerOrderly.c ├── SendDelayMsg.cpp ├── PushConsumeMessage.c ├── CBatchProducer.c ├── Producer.c └── CMakeLists.txt ├── .clang-format ├── .gitignore ├── NOTICE ├── CONTRIBUTING.md ├── .asf.yaml ├── dep ├── rocketmq_amd64 │ └── DEBIAN │ │ ├── control │ │ └── postinst └── build.sh ├── libs ├── CMakeLists.txt └── signature │ ├── CMakeLists.txt │ └── include │ ├── base64.h │ ├── param_list.h │ └── hmac.h ├── package_rocketmq.mri ├── src ├── extern │ ├── CSendResult.cpp │ ├── CErrorMessage.cpp │ └── CBatchMessage.cpp ├── include │ ├── MQAdmin.h │ ├── BatchMessage.h │ └── QueryResult.h ├── common │ ├── sync_http_client.h │ ├── MQClientErrorContainer.cpp │ ├── ServiceState.h │ ├── noncopyable.h │ ├── CommunicationMode.h │ ├── MQClientErrorContainer.h │ ├── TopicFilterType.h │ ├── url.h │ ├── AsyncArg.h │ ├── PermName.h │ ├── VirtualEnvUtil.h │ ├── MQVersion.cpp │ ├── MessageSysFlag.h │ ├── MessageAccessor.h │ ├── TopAddressing.h │ ├── MessageSysFlag.cpp │ ├── PullSysFlag.h │ ├── Validators.h │ ├── ClientRPCHook.h │ ├── SubscriptionGroupConfig.h │ ├── PermName.cpp │ ├── NamesrvConfig.h │ ├── NameSpaceUtil.h │ ├── VirtualEnvUtil.cpp │ ├── TopicConfig.h │ ├── Arg_helper.cpp │ ├── FilterAPI.h │ ├── big_endian.cpp │ ├── PullSysFlag.cpp │ ├── MessageAccessor.cpp │ └── url.cpp ├── client │ └── DefaultMQAdmin.h ├── dllmain.cpp ├── consumer │ ├── FindBrokerResult.h │ ├── ConsumeMessageHookImpl.h │ ├── SubscriptionData.h │ ├── PullResult.cpp │ └── PullResultExt.h ├── trace │ ├── TraceUtil.h │ ├── SendMessageHook.h │ ├── ConsumeMessageHook.h │ ├── TraceTransferBean.cpp │ ├── TraceTransferBean.h │ ├── TraceConstant.cpp │ └── TraceConstant.h ├── protocol │ ├── RemotingSerializable.h │ ├── TopicList.h │ ├── KVTable.h │ └── MessageQueue.h ├── status │ ├── ConsumeStats.h │ ├── ConsumeStats.cpp │ ├── StatsItem.h │ ├── StatsServerManager.h │ └── StatsServerManager.cpp ├── producer │ ├── SendMessageHookImpl.h │ └── StringIdMaker.h ├── message │ ├── MQMessageId.h │ └── MQDecoder.h ├── thread │ └── disruptor │ │ ├── exceptions.h │ │ ├── utils.h │ │ └── event_publisher.h ├── MQClientManager.h └── transport │ └── SocketUtil.h ├── include ├── CErrorMessage.h ├── MQClient.h ├── CTransactionStatus.h ├── CMessageQueue.h ├── MQSelector.h ├── CBatchMessage.h ├── CMQException.h ├── MQueueListener.h ├── CSendResult.h ├── Arg_helper.h ├── CPullResult.h ├── TransactionSendResult.h ├── TransactionListener.h ├── RocketMQClient.h ├── MQMessageQueue.h ├── ConsumeType.h ├── AsyncCallback.h ├── CMessage.h ├── CMessageExt.h ├── PullResult.h └── MQMessageListener.h ├── .travis └── check-git-clang-format.sh ├── PULL_REQUEST_TEMPLATE.md ├── test └── src │ ├── producer │ └── StringIdMakerTest.cpp │ ├── protocol │ └── KVTableTest.cpp │ ├── transport │ └── SocketUtilTest.cpp │ ├── common │ ├── NamesrvConfigTest.cpp │ ├── PermNametTest.cpp │ ├── MQVersionTest.cpp │ └── ClientRPCHookTest.cpp │ ├── message │ └── MQMessageIdTest.cpp │ └── MQClientManagerTest.cpp ├── rpm ├── build.sh └── rocketmq_x64 │ └── CENTOS │ └── rocketmq-client-cpp.spec ├── distribution └── deploy.sh ├── .github └── ISSUE_TEMPLATE │ └── issue_template.md ├── format.sh └── .travis.yml /example/README.md: -------------------------------------------------------------------------------- 1 | 1. AsyncProducer 2. OrderlyProducer 3. SyncProducer 2 | -------------------------------------------------------------------------------- /.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: Chromium 2 | ColumnLimit: 120 3 | TabWidth: 2 4 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/MQAdmin.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 DEFAULTMQADMIN_H__ 19 | #define DEFAULTMQADMIN_H__ 20 | #include "DefaultMQClient.h" 21 | 22 | namespace rocketmq { 23 | class MQAdmin : public DefaultMQClient { 24 | public: 25 | virtual ~MQAdmin() {} 26 | }; 27 | } // namespace rocketmq 28 | #endif // DEFAULTMQADMIN_H__ -------------------------------------------------------------------------------- /include/CErrorMessage.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 __CERROR_MESSAGE_H__ 19 | #define __CERROR_MESSAGE_H__ 20 | 21 | #include "CCommon.h" 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | ROCKETMQCLIENT_API const char* GetLatestErrorMessage(); // Return the last error message 28 | 29 | #ifdef __cplusplus 30 | } 31 | #endif 32 | #endif //__CERROR_MESSAGE_H__ 33 | -------------------------------------------------------------------------------- /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/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/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 -------------------------------------------------------------------------------- /include/MQClient.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 __MQADMIN_H__ 19 | #define __MQADMIN_H__ 20 | 21 | namespace rocketmq { 22 | 23 | enum elogLevel { 24 | eLOG_LEVEL_FATAL = 1, 25 | eLOG_LEVEL_ERROR = 2, 26 | eLOG_LEVEL_WARN = 3, 27 | eLOG_LEVEL_INFO = 4, 28 | eLOG_LEVEL_DEBUG = 5, 29 | eLOG_LEVEL_TRACE = 6, 30 | eLOG_LEVEL_LEVEL_NUM = 7 31 | }; 32 | 33 | } // namespace rocketmq 34 | #endif 35 | -------------------------------------------------------------------------------- /src/common/MQClientErrorContainer.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 "MQClientErrorContainer.h" 18 | 19 | namespace rocketmq { 20 | 21 | thread_local std::string MQClientErrorContainer::t_err; 22 | 23 | void MQClientErrorContainer::setErr(const std::string& str) { 24 | t_err = str; 25 | } 26 | 27 | const std::string& MQClientErrorContainer::getErr() { 28 | return t_err; 29 | } 30 | 31 | } // namespace rocketmq 32 | -------------------------------------------------------------------------------- /src/common/ServiceState.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 __SERVICESTATE_H__ 18 | #define __SERVICESTATE_H__ 19 | namespace rocketmq { 20 | // 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 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | //& mqs, const MQMessage& msg, void* arg) = 0; 28 | }; 29 | } // namespace rocketmq 30 | #endif 31 | -------------------------------------------------------------------------------- /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/common/MQClientErrorContainer.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 __MQ_CLIENT_ERROR_CONTAINER_H__ 18 | #define __MQ_CLIENT_ERROR_CONTAINER_H__ 19 | 20 | #include 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/TopicFilterType.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 __TOPICFILTERTYPE_H__ 18 | #define __TOPICFILTERTYPE_H__ 19 | 20 | namespace rocketmq { 21 | // 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/protocol/RemotingSerializable.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 __REMOTINGSERIALIZABLE_H__ 18 | #define __REMOTINGSERIALIZABLE_H__ 19 | #include "json/json.h" 20 | 21 | namespace rocketmq { 22 | // 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/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/status/ConsumeStats.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_H__ 19 | #define __CONSUMER_STATUS_H__ 20 | 21 | #include "UtilAll.h" 22 | #include "json/json.h" 23 | 24 | namespace rocketmq { 25 | class ConsumeStats { 26 | public: 27 | ConsumeStats(); 28 | virtual ~ConsumeStats() {} 29 | Json::Value toJson() const; 30 | 31 | public: 32 | double pullRT; 33 | double pullTPS; 34 | double consumeRT; 35 | double consumeOKTPS; 36 | double consumeFailedTPS; 37 | uint64 consumeFailedMsgs; 38 | }; 39 | 40 | } // namespace rocketmq 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /include/CBatchMessage.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 __C_BATCHMESSAGE_H__ 19 | #define __C_BATCHMESSAGE_H__ 20 | #include "CCommon.h" 21 | #include "CMessage.h" 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | typedef struct CBatchMessage CBatchMessage; 28 | 29 | ROCKETMQCLIENT_API CBatchMessage* CreateBatchMessage(); 30 | ROCKETMQCLIENT_API int AddMessage(CBatchMessage* batchMsg, CMessage* msg); 31 | ROCKETMQCLIENT_API int DestroyBatchMessage(CBatchMessage* batchMsg); 32 | 33 | #ifdef __cplusplus 34 | } 35 | #endif 36 | #endif //__C_BATCHMESSAGE_H__ 37 | -------------------------------------------------------------------------------- /src/protocol/TopicList.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 __TOPICLIST_H__ 18 | #define __TOPICLIST_H__ 19 | #include 20 | #include 21 | #include "dataBlock.h" 22 | 23 | namespace rocketmq { 24 | // m_topicList; 31 | }; 32 | // 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 | -------------------------------------------------------------------------------- /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/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 -------------------------------------------------------------------------------- /include/CSendResult.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 __C_SEND_RESULT_H__ 19 | #define __C_SEND_RESULT_H__ 20 | 21 | #include "CCommon.h" 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | typedef enum E_CSendStatus_ { 27 | E_SEND_OK = 0, 28 | E_SEND_FLUSH_DISK_TIMEOUT = 1, 29 | E_SEND_FLUSH_SLAVE_TIMEOUT = 2, 30 | E_SEND_SLAVE_NOT_AVAILABLE = 3 31 | } CSendStatus; 32 | 33 | typedef struct _SendResult_ { 34 | CSendStatus sendStatus; 35 | char msgId[MAX_MESSAGE_ID_LENGTH]; 36 | long long offset; 37 | } CSendResult; 38 | 39 | #ifdef __cplusplus 40 | } 41 | #endif 42 | #endif //__C_PRODUCER_H__ 43 | -------------------------------------------------------------------------------- /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/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 -------------------------------------------------------------------------------- /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 // 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 | -------------------------------------------------------------------------------- /src/common/PermName.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 __PERMNAME_H__ 18 | #define __PERMNAME_H__ 19 | 20 | #include 21 | 22 | namespace rocketmq { 23 | // 21 | namespace rocketmq { 22 | //= HIGHER_VERSION) { 30 | currentVersion = HIGHER_VERSION; 31 | } 32 | return RocketMQCPPClientVersion[currentVersion]; 33 | } 34 | // 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 | -------------------------------------------------------------------------------- /include/CPullResult.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 __C_PULL_RESULT_H__ 19 | #define __C_PULL_RESULT_H__ 20 | 21 | #include "CCommon.h" 22 | #include "CMessageExt.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | typedef enum E_CPullStatus { 28 | E_FOUND, 29 | E_NO_NEW_MSG, 30 | E_NO_MATCHED_MSG, 31 | E_OFFSET_ILLEGAL, 32 | E_BROKER_TIMEOUT // indicate pull request timeout or received NULL response 33 | } CPullStatus; 34 | 35 | typedef struct _CPullResult_ { 36 | CPullStatus pullStatus; 37 | long long nextBeginOffset; 38 | long long minOffset; 39 | long long maxOffset; 40 | CMessageExt** msgFoundList; 41 | int size; 42 | void* pData; 43 | } CPullResult; 44 | 45 | #ifdef __cplusplus 46 | } 47 | #endif 48 | #endif //__C_PULL_RESULT_H__ 49 | -------------------------------------------------------------------------------- /src/common/MessageAccessor.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 __MESSAGE_ACCESSOR_H__ 18 | #define __MESSAGE_ACCESSOR_H__ 19 | 20 | #include 21 | #include 22 | #include "MQMessage.h" 23 | #include "MQMessageExt.h" 24 | namespace rocketmq { 25 | //& msgs, const std::string& nameSpace); 31 | }; 32 | 33 | // 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/MessageSysFlag.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 "MessageSysFlag.h" 18 | 19 | namespace rocketmq { 20 | int MessageSysFlag::CompressedFlag = (0x1 << 0); 21 | int MessageSysFlag::MultiTagsFlag = (0x1 << 1); 22 | 23 | int MessageSysFlag::TransactionNotType = (0x0 << 2); 24 | int MessageSysFlag::TransactionPreparedType = (0x1 << 2); 25 | int MessageSysFlag::TransactionCommitType = (0x2 << 2); 26 | int MessageSysFlag::TransactionRollbackType = (0x3 << 2); 27 | 28 | int MessageSysFlag::getTransactionValue(int flag) { 29 | return flag & TransactionRollbackType; 30 | } 31 | 32 | int MessageSysFlag::resetTransactionValue(int flag, int type) { 33 | return (flag & (~TransactionRollbackType)) | type; 34 | } 35 | 36 | // 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 | -------------------------------------------------------------------------------- /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/common/PullSysFlag.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 __PULLSYSFLAG_H__ 18 | #define __PULLSYSFLAG_H__ 19 | namespace rocketmq { 20 | // 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 | -------------------------------------------------------------------------------- /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 | // 21 | #include "MQClientException.h" 22 | #include "MQMessage.h" 23 | #include "UtilAll.h" 24 | namespace rocketmq { 25 | // 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 | -------------------------------------------------------------------------------- /src/common/ClientRPCHook.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 __CLIENTRPCHOOK_H__ 19 | #define __CLIENTRPCHOOK_H__ 20 | 21 | #include "RemotingCommand.h" 22 | #include "SessionCredentials.h" 23 | namespace rocketmq { 24 | class RPCHook { 25 | public: 26 | RPCHook() {} 27 | virtual ~RPCHook() {} 28 | virtual void doBeforeRequest(const string& remoteAddr, RemotingCommand& request) = 0; 29 | virtual void doAfterResponse(RemotingCommand& request, RemotingCommand& response) = 0; 30 | }; 31 | 32 | class ClientRPCHook : public RPCHook { 33 | private: 34 | SessionCredentials sessionCredentials; 35 | 36 | public: 37 | ClientRPCHook(const SessionCredentials& session_credentials) : sessionCredentials(session_credentials) {} 38 | virtual ~ClientRPCHook() {} 39 | 40 | virtual void doBeforeRequest(const string& remoteAddr, RemotingCommand& request); 41 | 42 | virtual void doAfterResponse(RemotingCommand& request, RemotingCommand& response) {} 43 | }; 44 | } // namespace rocketmq 45 | #endif 46 | -------------------------------------------------------------------------------- /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/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/message/MQMessageId.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 __MESSAGEID_H__ 18 | #define __MESSAGEID_H__ 19 | 20 | #include "SocketUtil.h" 21 | #include "UtilAll.h" 22 | 23 | namespace rocketmq { 24 | //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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /src/common/SubscriptionGroupConfig.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 __SUBSCRIPTIONGROUPCONFIG_H__ 18 | #define __SUBSCRIPTIONGROUPCONFIG_H__ 19 | 20 | #include 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 "UtilAll.h" 23 | 24 | namespace rocketmq { 25 | // 30 | 31 | namespace rocketmq { 32 | 33 | class AlertException : public std::exception { 34 | }; 35 | 36 | }; // namespace rocketmq 37 | 38 | #endif // DISRUPTOR_EXCEPTIONS_H_ NOLINT 39 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /src/common/NameSpaceUtil.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 __NAMESPACEUTIL_H__ 19 | #define __NAMESPACEUTIL_H__ 20 | 21 | #include 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/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /src/common/VirtualEnvUtil.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 "VirtualEnvUtil.h" 18 | #include 19 | #include 20 | #include "UtilAll.h" 21 | 22 | namespace rocketmq { 23 | const char* VirtualEnvUtil::VIRTUAL_APPGROUP_PREFIX = "%%PROJECT_%s%%"; 24 | 25 | // 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 | -------------------------------------------------------------------------------- /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 | // 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 | // 21 | #include "json/json.h" 22 | 23 | namespace rocketmq { 24 | // 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 | //& 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 | // 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 | -------------------------------------------------------------------------------- /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 | // 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 | // 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 | -------------------------------------------------------------------------------- /test/src/MQClientManagerTest.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 "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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /src/common/FilterAPI.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 __FILTERAPI_H__ 19 | #define __FILTERAPI_H__ 20 | 21 | #include 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 | //& 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 | } // 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 | -------------------------------------------------------------------------------- /include/ConsumeType.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 __CONSUMETYPE_H__ 19 | #define __CONSUMETYPE_H__ 20 | 21 | namespace rocketmq { 22 | // 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 | -------------------------------------------------------------------------------- /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/common/big_endian.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright 2014 The Chromium Authors. All rights reserved. 3 | // Use of this source code is governed by a BSD-style license that can be 4 | // found in the LICENSE file. 5 | 6 | #include "big_endian.h" 7 | #include 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 | -------------------------------------------------------------------------------- /include/CMessageExt.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 __C_MESSAGE_EXT_H__ 19 | #define __C_MESSAGE_EXT_H__ 20 | 21 | #include "CCommon.h" 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | // typedef struct _CMessageExt_ _CMessageExt; 28 | typedef struct CMessageExt CMessageExt; 29 | 30 | ROCKETMQCLIENT_API const char* GetMessageTopic(CMessageExt* msgExt); 31 | ROCKETMQCLIENT_API const char* GetMessageTags(CMessageExt* msgExt); 32 | ROCKETMQCLIENT_API const char* GetMessageKeys(CMessageExt* msgExt); 33 | ROCKETMQCLIENT_API const char* GetMessageBody(CMessageExt* msgExt); 34 | ROCKETMQCLIENT_API int GetMessageBodyLength(CMessageExt* msgExt); 35 | ROCKETMQCLIENT_API const char* GetMessageProperty(CMessageExt* msgExt, const char* key); 36 | ROCKETMQCLIENT_API const char* GetMessageId(CMessageExt* msgExt); 37 | ROCKETMQCLIENT_API int GetMessageDelayTimeLevel(CMessageExt* msgExt); 38 | ROCKETMQCLIENT_API int GetMessageQueueId(CMessageExt* msgExt); 39 | ROCKETMQCLIENT_API int GetMessageReconsumeTimes(CMessageExt* msgExt); 40 | ROCKETMQCLIENT_API int GetMessageStoreSize(CMessageExt* msgExt); 41 | ROCKETMQCLIENT_API long long GetMessageBornTimestamp(CMessageExt* msgExt); 42 | ROCKETMQCLIENT_API long long GetMessageStoreTimestamp(CMessageExt* msgExt); 43 | ROCKETMQCLIENT_API long long GetMessageQueueOffset(CMessageExt* msgExt); 44 | ROCKETMQCLIENT_API long long GetMessageCommitLogOffset(CMessageExt* msgExt); 45 | ROCKETMQCLIENT_API long long GetMessagePreparedTransactionOffset(CMessageExt* msgExt); 46 | 47 | #ifdef __cplusplus 48 | } 49 | #endif 50 | #endif //__C_MESSAGE_EXT_H__ 51 | -------------------------------------------------------------------------------- /src/common/PullSysFlag.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 "PullSysFlag.h" 18 | 19 | namespace rocketmq { 20 | // 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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /src/common/MessageAccessor.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 "MessageAccessor.h" 18 | #include 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 | // 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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /include/MQMessageListener.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 __MESSAGELISTENER_H__ 18 | #define __MESSAGELISTENER_H__ 19 | 20 | #include 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 | -------------------------------------------------------------------------------- /src/consumer/PullResultExt.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 | #include "PullResult.h" 18 | #include "UtilAll.h" 19 | #include "dataBlock.h" 20 | 21 | namespace rocketmq { 22 | /** 23 | * use internal only 24 | */ 25 | //(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 | -------------------------------------------------------------------------------- /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 | --------------------------------------------------------------------------------