You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by li...@apache.org on 2017/09/04 05:04:59 UTC
[13/14] incubator-rocketmq-externals git commit: upload rocketmq-cpp
code
http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/70ce5c77/rocketmq-cpp/include/DefaultMQPushConsumer.h
----------------------------------------------------------------------
diff --git a/rocketmq-cpp/include/DefaultMQPushConsumer.h b/rocketmq-cpp/include/DefaultMQPushConsumer.h
new file mode 100755
index 0000000..9a39484
--- /dev/null
+++ b/rocketmq-cpp/include/DefaultMQPushConsumer.h
@@ -0,0 +1,160 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __DEFAULTMQPUSHCONSUMER_H__
+#define __DEFAULTMQPUSHCONSUMER_H__
+
+#include <boost/asio.hpp>
+#include <boost/asio/io_service.hpp>
+#include <boost/bind.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
+#include <boost/scoped_ptr.hpp>
+#include <boost/thread/thread.hpp>
+#include <string>
+#include "AsyncCallback.h"
+#include "MQConsumer.h"
+#include "MQMessageListener.h"
+#include "MQMessageQueue.h"
+
+namespace rocketmq {
+
+class Rebalance;
+class SubscriptionData;
+class OffsetStore;
+class PullAPIWrapper;
+class PullRequest;
+class ConsumeMsgService;
+class TaskQueue;
+class TaskThread;
+class AsyncPullCallback;
+class ConsumerRunningInfo;
+//<!***************************************************************************
+class ROCKETMQCLIENT_API DefaultMQPushConsumer : public MQConsumer {
+ public:
+ DefaultMQPushConsumer(const std::string& groupname);
+ void boost_asio_work();
+ virtual ~DefaultMQPushConsumer();
+
+ //<!begin mqadmin;
+ virtual void start();
+ virtual void shutdown();
+ //<!end mqadmin;
+
+ //<!begin MQConsumer
+ virtual void sendMessageBack(MQMessageExt& msg, int delayLevel);
+ virtual void fetchSubscribeMessageQueues(const std::string& topic,
+ std::vector<MQMessageQueue>& mqs);
+ virtual void doRebalance();
+ virtual void persistConsumerOffset();
+ virtual void persistConsumerOffsetByResetOffset();
+ virtual void updateTopicSubscribeInfo(const std::string& topic,
+ std::vector<MQMessageQueue>& info);
+ virtual ConsumeType getConsumeType();
+ virtual ConsumeFromWhere getConsumeFromWhere();
+ void setConsumeFromWhere(ConsumeFromWhere consumeFromWhere);
+ virtual void getSubscriptions(std::vector<SubscriptionData>&);
+ virtual void updateConsumeOffset(const MQMessageQueue& mq, int64 offset);
+ virtual void removeConsumeOffset(const MQMessageQueue& mq);
+ virtual PullResult pull(const MQMessageQueue& mq, const std::string& subExpression,
+ int64 offset, int maxNums) {
+ return PullResult();
+ }
+ virtual void pull(const MQMessageQueue& mq, const std::string& subExpression,
+ int64 offset, int maxNums,
+ PullCallback* pPullCallback) {}
+ virtual ConsumerRunningInfo* getConsumerRunningInfo();
+ //<!end MQConsumer;
+
+ void registerMessageListener(MQMessageListener* pMessageListener);
+ MessageListenerType getMessageListenerType();
+ void subscribe(const std::string& topic, const std::string& subExpression);
+
+ OffsetStore* getOffsetStore() const;
+ virtual Rebalance* getRebalance() const;
+ ConsumeMsgService* getConsumerMsgService() const;
+
+ virtual void producePullMsgTask(PullRequest*);
+ void triggerNextPullRequest(boost::asio::deadline_timer* t,
+ PullRequest* request);
+ void runPullMsgQueue(TaskQueue* pTaskQueue);
+ void pullMessage(PullRequest* pullrequest); // sync pullMsg
+ void pullMessageAsync(PullRequest* pullrequest); // async pullMsg
+ void setAsyncPull(bool asyncFlag);
+ AsyncPullCallback* getAsyncPullCallBack(PullRequest* request,
+ MQMessageQueue msgQueue);
+ void shutdownAsyncPullCallBack();
+
+ /*
+ for orderly consume, set the pull num of message size by each pullMsg,
+ default value is 1;
+ */
+ void setConsumeMessageBatchMaxSize(int consumeMessageBatchMaxSize);
+ int getConsumeMessageBatchMaxSize() const;
+
+ /*
+ set consuming thread count, default value is cpu cores
+ */
+ void setConsumeThreadCount(int threadCount);
+ int getConsumeThreadCount() const;
+
+ /*
+ set pullMsg thread count, default value is cpu cores
+ */
+ void setPullMsgThreadPoolCount(int threadCount);
+ int getPullMsgThreadPoolCount() const;
+
+ /*
+ set max cache msg size perQueue in memory if consumer could not consume msgs
+ immediately
+ default maxCacheMsgSize perQueue is 1000, set range is:1~65535
+ */
+ void setMaxCacheMsgSizePerQueue(int maxCacheSize);
+ int getMaxCacheMsgSizePerQueue() const;
+
+ private:
+ void checkConfig();
+ void copySubscription();
+ void updateTopicSubscribeInfoWhenSubscriptionChanged();
+
+ private:
+ uint64_t m_startTime;
+ ConsumeFromWhere m_consumeFromWhere;
+ std::map<std::string, std::string> m_subTopics;
+ int m_consumeThreadCount;
+ OffsetStore* m_pOffsetStore;
+ Rebalance* m_pRebalance;
+ PullAPIWrapper* m_pPullAPIWrapper;
+ ConsumeMsgService* m_consumerServeice;
+ MQMessageListener* m_pMessageListener;
+ int m_consumeMessageBatchMaxSize;
+ int m_maxMsgCacheSize;
+ boost::asio::io_service m_async_ioService;
+ boost::scoped_ptr<boost::thread> m_async_service_thread;
+
+ typedef std::map<MQMessageQueue, AsyncPullCallback*> PullMAP;
+ PullMAP m_PullCallback;
+ bool m_asyncPull;
+ int m_asyncPullTimeout;
+ int m_pullMsgThreadPoolNum;
+
+ private:
+ TaskQueue* m_pullmsgQueue;
+ std::unique_ptr<boost::thread> m_pullmsgThread;
+};
+//<!***************************************************************************
+} //<!end namespace;
+#endif
http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/70ce5c77/rocketmq-cpp/include/MQClient.h
----------------------------------------------------------------------
diff --git a/rocketmq-cpp/include/MQClient.h b/rocketmq-cpp/include/MQClient.h
new file mode 100755
index 0000000..b3a1ba8
--- /dev/null
+++ b/rocketmq-cpp/include/MQClient.h
@@ -0,0 +1,203 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __MQADMIN_H__
+#define __MQADMIN_H__
+#include <boost/asio.hpp>
+#include <boost/asio/io_service.hpp>
+#include <boost/bind.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
+#include <boost/thread/mutex.hpp>
+#include <boost/thread/thread.hpp>
+#include "MQMessageExt.h"
+#include "MQMessageQueue.h"
+#include "QueryResult.h"
+#include "RocketMQClient.h"
+#include "SessionCredentials.h"
+
+namespace rocketmq {
+class MQClientFactory;
+//<!***************************************************************************
+
+enum elogLevel {
+ eLOG_LEVEL_DISABLE = 0,
+ eLOG_LEVEL_FATAL = 1,
+ eLOG_LEVEL_ERROR = 2,
+ eLOG_LEVEL_WARN = 3,
+ eLOG_LEVEL_INFO = 4,
+ eLOG_LEVEL_DEBUG = 5,
+ eLOG_LEVEL_TRACE = 6,
+ eLOG_LEVEL_LEVEL_NUM = 7
+};
+
+class ROCKETMQCLIENT_API MQClient {
+ public:
+ MQClient();
+ virtual ~MQClient();
+
+ public:
+ // clientid=processId-ipAddr@instanceName;
+ std::string getMQClientId() const;
+ const std::string& getNamesrvAddr() const;
+ void setNamesrvAddr(const std::string& namesrvAddr);
+ const std::string& getNamesrvDomain() const;
+ void setNamesrvDomain(const std::string& namesrvDomain);
+ const std::string& getInstanceName() const;
+ void setInstanceName(const std::string& instanceName);
+ //<!groupName;
+ const std::string& getGroupName() const;
+ void setGroupName(const std::string& groupname);
+
+ /**
+ * no realization
+ */
+ void createTopic(const std::string& key, const std::string& newTopic, int queueNum);
+ /**
+ * search earliest msg store time for specified queue
+ *
+ * @param mq
+ * message queue
+ * @return earliest store time, ms
+ */
+ int64 earliestMsgStoreTime(const MQMessageQueue& mq);
+ /**
+ * search maxOffset of queue
+ *
+ * @param mq
+ * message queue
+ * @return minOffset of queue
+ */
+ int64 minOffset(const MQMessageQueue& mq);
+ /**
+ * search maxOffset of queue
+ * Note: maxOffset-1 is max offset that could get msg
+ * @param mq
+ * message queue
+ * @return maxOffset of queue
+ */
+ int64 maxOffset(const MQMessageQueue& mq);
+ /**
+ * get queue offset by timestamp
+ *
+ * @param mq
+ * mq queue
+ * @param timestamp
+ * timestamp with ms unit
+ * @return queue offset according to timestamp
+ */
+ int64 searchOffset(const MQMessageQueue& mq, uint64_t timestamp);
+ /**
+ * get whole msg info from broker by msgId
+ *
+ * @param msgId
+ * @return MQMessageExt
+ */
+ MQMessageExt* viewMessage(const std::string& msgId);
+ /**
+ * query message by topic and key
+ *
+ * @param topic
+ * topic name
+ * @param key
+ * topic key
+ * @param maxNum
+ * query num
+ * @param begin
+ * begin timestamp
+ * @param end
+ * end timestamp
+ * @return
+ * according to QueryResult
+ */
+ QueryResult queryMessage(const std::string& topic, const std::string& key, int maxNum,
+ int64 begin, int64 end);
+
+ std::vector<MQMessageQueue> getTopicMessageQueueInfo(const std::string& topic);
+
+ // log configuration interface, default LOG_LEVEL is LOG_LEVEL_INFO, default
+ // log file num is 3, each log size is 100M
+ void setMetaqLogLevel(elogLevel inputLevel);
+ void setMetaqLogFileSizeAndNum(int fileNum,
+ long perFileSize); // perFileSize is MB unit
+
+ /** set TcpTransport pull thread num, which dermine the num of threads to
+ distribute network data,
+ 1. its default value is CPU num, it must be setted before producer/consumer
+ start, minimum value is CPU num;
+ 2. this pullThread num must be tested on your environment to find the best
+ value for RT of sendMsg or delay time of consume msg before you change it;
+ 3. producer and consumer need different pullThread num, if set this num,
+ producer and consumer must set different instanceName.
+ 4. configuration suggestion:
+ 1>. minimum RT of sendMsg:
+ pullThreadNum = brokerNum*2
+ **/
+ void setTcpTransportPullThreadNum(int num);
+ const int getTcpTransportPullThreadNum() const;
+
+ /** timeout of tcp connect, it is same meaning for both producer and consumer;
+ 1. default value is 3000ms
+ 2. input parameter could only be milliSecond, suggestion value is
+ 1000-3000ms;
+ **/
+ void setTcpTransportConnectTimeout(uint64_t timeout); // ms
+ const uint64_t getTcpTransportConnectTimeout() const;
+
+ /** timeout of tryLock tcpTransport before sendMsg/pullMsg, if timeout,
+ returns NULL
+ 1. paremeter unit is ms, default value is 3000ms, the minimun value is
+ 1000ms
+ suggestion value is 3000ms;
+ 2. if configured with value smaller than 1000ms, the tryLockTimeout value
+ will be setted to 1000ms
+ **/
+ void setTcpTransportTryLockTimeout(uint64_t timeout); // ms
+ const uint64_t getTcpTransportTryLockTimeout() const;
+
+ void setUnitName(std::string unitName);
+ const std::string& getUnitName();
+
+ void setSessionCredentials(const std::string& input_accessKey,
+ const std::string& input_secretKey,
+ const std::string& input_onsChannel);
+ const SessionCredentials& getSessionCredentials() const;
+
+ protected:
+ virtual void start();
+ virtual void shutdown();
+ MQClientFactory* getFactory() const;
+ virtual bool isServiceStateOk();
+
+ protected:
+ std::string m_namesrvAddr;
+ std::string m_namesrvDomain;
+ std::string m_instanceName;
+ //<! the name is globle only
+ std::string m_GroupName;
+ //<!factory;
+ MQClientFactory* m_clientFactory;
+ int m_serviceState;
+ int m_pullThreadNum;
+ uint64_t m_tcpConnectTimeout; // ms
+ uint64_t m_tcpTransportTryLockTimeout; // s
+
+ std::string m_unitName;
+ SessionCredentials m_SessionCredentials;
+};
+//<!***************************************************************************
+} //<!end namespace;
+#endif
http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/70ce5c77/rocketmq-cpp/include/MQClientException.h
----------------------------------------------------------------------
diff --git a/rocketmq-cpp/include/MQClientException.h b/rocketmq-cpp/include/MQClientException.h
new file mode 100755
index 0000000..9b64197
--- /dev/null
+++ b/rocketmq-cpp/include/MQClientException.h
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __MQCLIENTEXCEPTION_H__
+#define __MQCLIENTEXCEPTION_H__
+
+#include <exception>
+#include <ostream>
+#include <sstream>
+#include <string>
+#include "RocketMQClient.h"
+
+namespace rocketmq {
+//<!***************************************************************************
+class ROCKETMQCLIENT_API MQException : public std::exception {
+ public:
+ MQException(const std::string& msg, int error, const char* file,
+ int line) throw()
+ : m_error(error), m_line(line), m_file(file) {
+ try {
+ std::stringstream ss;
+ ss << "msg: " << msg << ",error:" << error << ",in file <" << file
+ << "> line:" << line;
+ m_msg = ss.str();
+ } catch (...) {
+ }
+ }
+
+ MQException(const std::string& msg, int error, const char* file,
+ const char* type, int line) throw()
+ : m_error(error), m_line(line), m_file(file), m_type(type) {
+ try {
+ std::stringstream ss;
+ ss << "msg: " << msg << ",error:" << error << ",in file <" << file
+ << "> line:" << line;
+ m_msg = ss.str();
+ } catch (...) {
+ }
+ }
+
+ virtual ~MQException() throw() {}
+
+ const char* what() const throw() { return m_msg.c_str(); }
+
+ int GetError() const throw() { return m_error; }
+
+ virtual const char* GetType() const throw() { return m_type.c_str(); }
+
+ protected:
+ int m_error;
+ int m_line;
+ std::string m_msg;
+ std::string m_file;
+ std::string m_type;
+};
+
+inline std::ostream& operator<<(std::ostream& os, const MQException& e) {
+ os << "Type: " << e.GetType() << " , " << e.what();
+ return os;
+}
+
+#define DEFINE_MQCLIENTEXCEPTION(name) \
+ class ROCKETMQCLIENT_API name : public MQException { \
+ public: \
+ name(const std::string& msg, int error, const char* file, \
+ int line) throw() \
+ : MQException(msg, error, file, #name, line) {} \
+ virtual const char* GetType() const throw() { return m_type.c_str(); } \
+ };
+
+DEFINE_MQCLIENTEXCEPTION(MQClientException)
+DEFINE_MQCLIENTEXCEPTION(MQBrokerException)
+DEFINE_MQCLIENTEXCEPTION(InterruptedException)
+DEFINE_MQCLIENTEXCEPTION(RemotingException)
+DEFINE_MQCLIENTEXCEPTION(UnknownHostException)
+
+#define THROW_MQEXCEPTION(e, msg, err) throw e(msg, err, __FILE__, __LINE__)
+#define NEW_MQEXCEPTION(e, msg, err) e(msg, err, __FILE__, __LINE__)
+
+//<!***************************************************************************
+} //<!end namespace;
+#endif
http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/70ce5c77/rocketmq-cpp/include/MQConsumer.h
----------------------------------------------------------------------
diff --git a/rocketmq-cpp/include/MQConsumer.h b/rocketmq-cpp/include/MQConsumer.h
new file mode 100755
index 0000000..89763a8
--- /dev/null
+++ b/rocketmq-cpp/include/MQConsumer.h
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __MQCONSUMER_H__
+#define __MQCONSUMER_H__
+
+#include <string>
+#include "AsyncCallback.h"
+#include "ConsumeType.h"
+#include "MQClient.h"
+#include "RocketMQClient.h"
+
+namespace rocketmq {
+class SubscriptionData;
+class PullRequest;
+class Rebalance;
+class ConsumerRunningInfo;
+//<!************************************************************************
+class ROCKETMQCLIENT_API MQConsumer : public MQClient {
+ public:
+ virtual ~MQConsumer() {}
+ virtual void sendMessageBack(MQMessageExt& msg, int delayLevel) = 0;
+ virtual void fetchSubscribeMessageQueues(const std::string& topic,
+ std::vector<MQMessageQueue>& mqs) = 0;
+ virtual void doRebalance() = 0;
+ virtual void persistConsumerOffset() = 0;
+ virtual void persistConsumerOffsetByResetOffset() = 0;
+ virtual void updateTopicSubscribeInfo(const std::string& topic,
+ std::vector<MQMessageQueue>& info) = 0;
+ virtual void updateConsumeOffset(const MQMessageQueue& mq,
+ int64 offset) = 0;
+ virtual void removeConsumeOffset(const MQMessageQueue& mq) = 0;
+ virtual ConsumeType getConsumeType() = 0;
+ virtual ConsumeFromWhere getConsumeFromWhere() = 0;
+ virtual void getSubscriptions(std::vector<SubscriptionData>&) = 0;
+ virtual void producePullMsgTask(PullRequest*) = 0;
+ virtual Rebalance* getRebalance() const = 0;
+ virtual PullResult pull(const MQMessageQueue& mq, const std::string& subExpression,
+ int64 offset, int maxNums) = 0;
+ virtual void pull(const MQMessageQueue& mq, const std::string& subExpression,
+ int64 offset, int maxNums,
+ PullCallback* pPullCallback) = 0;
+ virtual ConsumerRunningInfo* getConsumerRunningInfo() = 0;
+
+ public:
+ MessageModel getMessageModel() const { return m_messageModel; }
+ void setMessageModel(MessageModel messageModel) {
+ m_messageModel = messageModel;
+ }
+
+ protected:
+ MessageModel m_messageModel;
+};
+
+//<!***************************************************************************
+} //<!end namespace;
+#endif
http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/70ce5c77/rocketmq-cpp/include/MQMessage.h
----------------------------------------------------------------------
diff --git a/rocketmq-cpp/include/MQMessage.h b/rocketmq-cpp/include/MQMessage.h
new file mode 100755
index 0000000..fc18ac9
--- /dev/null
+++ b/rocketmq-cpp/include/MQMessage.h
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __MESSAGE_H__
+#define __MESSAGE_H__
+
+#include <map>
+#include <sstream>
+#include <string>
+#include <vector>
+#include "RocketMQClient.h"
+
+namespace rocketmq {
+//<!***************************************************************************
+class ROCKETMQCLIENT_API MQMessage {
+ public:
+ MQMessage();
+ MQMessage(const std::string& topic, const std::string& body);
+ MQMessage(const std::string& topic, const std::string& tags, const std::string& body);
+ MQMessage(const std::string& topic, const std::string& tags, const std::string& keys,
+ const std::string& body);
+ MQMessage(const std::string& topic, const std::string& tags, const std::string& keys,
+ const int flag, const std::string& body, bool waitStoreMsgOK);
+
+ virtual ~MQMessage();
+ MQMessage(const MQMessage& other);
+ MQMessage& operator=(const MQMessage& other);
+
+ void setProperty(const std::string& name, const std::string& value);
+ std::string getProperty(const std::string& name) const;
+
+ std::string getTopic() const;
+ void setTopic(const std::string& topic);
+ void setTopic(const char* body, int len);
+
+ std::string getTags() const;
+ void setTags(const std::string& tags);
+
+ std::string getKeys() const;
+ void setKeys(const std::string& keys);
+ void setKeys(const std::vector<std::string>& keys);
+
+ int getDelayTimeLevel() const;
+ void setDelayTimeLevel(int level);
+
+ bool isWaitStoreMsgOK();
+ void setWaitStoreMsgOK(bool waitStoreMsgOK);
+
+ int getFlag() const;
+ void setFlag(int flag);
+
+ std::string getBody() const;
+ void setBody(const char* body, int len);
+ void setBody(const std::string& body);
+
+ std::map<std::string, std::string> getProperties() const;
+ void setProperties(std::map<std::string, std::string>& properties);
+
+ const std::string toString() const {
+ std::stringstream ss;
+ ss << "Message [topic=" << m_topic << ", flag=" << m_flag
+ << ", tag=" << getTags() << "]";
+ return ss.str();
+ }
+
+ protected:
+ void Init(const std::string& topic, const std::string& tags, const std::string& keys,
+ const int flag, const std::string& body, bool waitStoreMsgOK);
+
+ public:
+ static const std::string PROPERTY_KEYS;
+ static const std::string PROPERTY_TAGS;
+ static const std::string PROPERTY_WAIT_STORE_MSG_OK;
+ static const std::string PROPERTY_DELAY_TIME_LEVEL;
+ static const std::string PROPERTY_RETRY_TOPIC;
+ static const std::string PROPERTY_REAL_TOPIC;
+ static const std::string PROPERTY_REAL_QUEUE_ID;
+ static const std::string PROPERTY_TRANSACTION_PREPARED;
+ static const std::string PROPERTY_PRODUCER_GROUP;
+ static const std::string PROPERTY_MIN_OFFSET;
+ static const std::string PROPERTY_MAX_OFFSET;
+ static const std::string KEY_SEPARATOR;
+
+ private:
+ std::string m_topic;
+ int m_flag;
+ std::string m_body;
+ std::map<std::string, std::string> m_properties;
+};
+//<!***************************************************************************
+} //<!end namespace;
+#endif
http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/70ce5c77/rocketmq-cpp/include/MQMessageExt.h
----------------------------------------------------------------------
diff --git a/rocketmq-cpp/include/MQMessageExt.h b/rocketmq-cpp/include/MQMessageExt.h
new file mode 100755
index 0000000..cf911e3
--- /dev/null
+++ b/rocketmq-cpp/include/MQMessageExt.h
@@ -0,0 +1,117 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __MESSAGEEXT_H__
+#define __MESSAGEEXT_H__
+
+#ifdef WIN32
+#include <Windows.h>
+#include <Winsock2.h>
+#else
+#include <sys/socket.h>
+#endif
+
+#include "MQMessage.h"
+#include "RocketMQClient.h"
+
+namespace rocketmq {
+//<!message extend class, which was generated on broker;
+//<!***************************************************************************
+class ROCKETMQCLIENT_API MQMessageExt : public MQMessage {
+ public:
+ MQMessageExt();
+ MQMessageExt(int queueId, int64 bornTimestamp, sockaddr bornHost,
+ int64 storeTimestamp, sockaddr storeHost, std::string msgId);
+
+ virtual ~MQMessageExt();
+
+ static int parseTopicFilterType(int sysFlag);
+
+ int getQueueId() const;
+ void setQueueId(int queueId);
+
+ int64 getBornTimestamp() const;
+ void setBornTimestamp(int64 bornTimestamp);
+
+ sockaddr getBornHost() const;
+ std::string getBornHostString() const;
+ std::string getBornHostNameString() const;
+ void setBornHost(const sockaddr& bornHost);
+
+ int64 getStoreTimestamp() const;
+ void setStoreTimestamp(int64 storeTimestamp);
+
+ sockaddr getStoreHost() const;
+ std::string getStoreHostString() const;
+ void setStoreHost(const sockaddr& storeHost);
+
+ const std::string& getMsgId() const;
+ void setMsgId(const std::string& msgId);
+
+ int getSysFlag() const;
+ void setSysFlag(int sysFlag);
+
+ int getBodyCRC() const;
+ void setBodyCRC(int bodyCRC);
+
+ int64 getQueueOffset() const;
+ void setQueueOffset(int64 queueOffset);
+
+ int64 getCommitLogOffset() const;
+ void setCommitLogOffset(int64 physicOffset);
+
+ int getStoreSize() const;
+ void setStoreSize(int storeSize);
+
+ int getReconsumeTimes() const;
+ void setReconsumeTimes(int reconsumeTimes);
+
+ int64 getPreparedTransactionOffset() const;
+ void setPreparedTransactionOffset(int64 preparedTransactionOffset);
+
+ std::string toString() const {
+ std::stringstream ss;
+ ss << "MessageExt [queueId=" << m_queueId << ", storeSize=" << m_storeSize
+ << ", queueOffset=" << m_queueOffset << ", sysFlag=" << m_sysFlag
+ << ", bornTimestamp=" << m_bornTimestamp
+ << ", bornHost=" << getBornHostString()
+ << ", storeTimestamp=" << m_storeTimestamp
+ << ", storeHost=" << getStoreHostString() << ", msgId=" << m_msgId
+ << ", commitLogOffset=" << m_commitLogOffset << ", bodyCRC=" << m_bodyCRC
+ << ", reconsumeTimes=" << m_reconsumeTimes
+ << ", preparedTransactionOffset=" << m_preparedTransactionOffset << ", "
+ << MQMessage::toString() << "]";
+ return ss.str();
+ }
+
+ private:
+ int64 m_queueOffset;
+ int64 m_commitLogOffset;
+ int64 m_bornTimestamp;
+ int64 m_storeTimestamp;
+ int64 m_preparedTransactionOffset;
+ int m_queueId;
+ int m_storeSize;
+ int m_sysFlag;
+ int m_bodyCRC;
+ int m_reconsumeTimes;
+ sockaddr m_bornHost;
+ sockaddr m_storeHost;
+ std::string m_msgId;
+};
+//<!***************************************************************************
+} //<!end namespace;
+#endif
http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/70ce5c77/rocketmq-cpp/include/MQMessageListener.h
----------------------------------------------------------------------
diff --git a/rocketmq-cpp/include/MQMessageListener.h b/rocketmq-cpp/include/MQMessageListener.h
new file mode 100755
index 0000000..63bd74d
--- /dev/null
+++ b/rocketmq-cpp/include/MQMessageListener.h
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __MESSAGELISTENER_H__
+#define __MESSAGELISTENER_H__
+
+#include <limits.h>
+#include "MQMessageExt.h"
+#include "MQMessageQueue.h"
+
+namespace rocketmq {
+//<!***************************************************************************
+enum ConsumeStatus {
+ //consume success, msg will be cleard from memory
+ CONSUME_SUCCESS,
+ //consume fail, but will be re-consume by call messageLisenter again
+ RECONSUME_LATER
+};
+
+/*enum ConsumeOrderlyStatus
+{*/
+/**
+ * Success consumption
+ */
+// SUCCESS,
+/**
+ * Rollback consumption(only for binlog consumption)
+ */
+// ROLLBACK,
+/**
+ * Commit offset(only for binlog consumption)
+ */
+// COMMIT,
+/**
+ * Suspend current queue a moment
+ */
+// SUSPEND_CURRENT_QUEUE_A_MOMENT
+/*};*/
+
+enum MessageListenerType {
+ messageListenerDefaultly = 0,
+ messageListenerOrderly = 1,
+ messageListenerConcurrently = 2
+};
+
+//<!***************************************************************************
+class ROCKETMQCLIENT_API MQMessageListener {
+ public:
+ virtual ~MQMessageListener() {}
+ virtual ConsumeStatus consumeMessage(const std::vector<MQMessageExt>& msgs) = 0;
+ virtual MessageListenerType getMessageListenerType() {
+ return messageListenerDefaultly;
+ }
+};
+
+class ROCKETMQCLIENT_API MessageListenerOrderly : public MQMessageListener {
+ public:
+ virtual ~MessageListenerOrderly() {}
+ virtual ConsumeStatus consumeMessage(const std::vector<MQMessageExt>& msgs) = 0;
+ virtual MessageListenerType getMessageListenerType() {
+ return messageListenerOrderly;
+ }
+};
+
+class ROCKETMQCLIENT_API MessageListenerConcurrently
+ : public MQMessageListener {
+ public:
+ virtual ~MessageListenerConcurrently() {}
+ virtual ConsumeStatus consumeMessage(const std::vector<MQMessageExt>& msgs) = 0;
+ virtual MessageListenerType getMessageListenerType() {
+ return messageListenerConcurrently;
+ }
+};
+
+//<!***************************************************************************
+} //<!end namespace;
+#endif
http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/70ce5c77/rocketmq-cpp/include/MQMessageQueue.h
----------------------------------------------------------------------
diff --git a/rocketmq-cpp/include/MQMessageQueue.h b/rocketmq-cpp/include/MQMessageQueue.h
new file mode 100755
index 0000000..bb1c4ae
--- /dev/null
+++ b/rocketmq-cpp/include/MQMessageQueue.h
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __MQMESSAGEQUEUE_H__
+#define __MQMESSAGEQUEUE_H__
+
+#include <iomanip>
+#include <sstream>
+#include <string>
+#include "RocketMQClient.h"
+
+namespace rocketmq {
+//<!************************************************************************/
+//<!* MQ(T,B,ID);
+//<!************************************************************************/
+class ROCKETMQCLIENT_API MQMessageQueue {
+ public:
+ MQMessageQueue();
+ MQMessageQueue(const std::string& topic, const std::string& brokerName, int queueId);
+ MQMessageQueue(const MQMessageQueue& other);
+ MQMessageQueue& operator=(const MQMessageQueue& other);
+
+ std::string getTopic() const;
+ void setTopic(const std::string& topic);
+
+ std::string getBrokerName() const;
+ void setBrokerName(const std::string& brokerName);
+
+ int getQueueId() const;
+ void setQueueId(int queueId);
+
+ bool operator==(const MQMessageQueue& mq) const;
+ bool operator<(const MQMessageQueue& mq) const;
+ int compareTo(const MQMessageQueue& mq) const;
+
+ const std::string toString() const {
+ std::stringstream ss;
+ ss << "MessageQueue [topic=" << m_topic << ", brokerName=" << m_brokerName
+ << ", queueId=" << m_queueId << "]";
+
+ return ss.str();
+ }
+
+ private:
+ std::string m_topic;
+ std::string m_brokerName;
+ int m_queueId;
+};
+//<!***************************************************************************
+} //<!end namespace;
+#endif
http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/70ce5c77/rocketmq-cpp/include/MQProducer.h
----------------------------------------------------------------------
diff --git a/rocketmq-cpp/include/MQProducer.h b/rocketmq-cpp/include/MQProducer.h
new file mode 100755
index 0000000..e5df9ee
--- /dev/null
+++ b/rocketmq-cpp/include/MQProducer.h
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __MQPRODUCER_H__
+#define __MQPRODUCER_H__
+
+#include "AsyncCallback.h"
+#include "MQClient.h"
+#include "MQMessageQueue.h"
+#include "MQSelector.h"
+#include "RocketMQClient.h"
+#include "SendResult.h"
+
+namespace rocketmq {
+//<!***************************************************************************
+class ROCKETMQCLIENT_API MQProducer : public MQClient {
+ public:
+ MQProducer() {}
+ virtual ~MQProducer() {}
+ // if setted bActiveBroker, will search brokers with best service state
+ // firstly, then search brokers that had been sent failed by last time;
+ virtual SendResult send(MQMessage& msg, bool bSelectActiveBroker = false) = 0;
+ virtual SendResult send(MQMessage& msg, const MQMessageQueue& mq) = 0;
+ // strict order msg, if send failed on seleted MessageQueue, throw exception
+ // to up layer
+ virtual SendResult send(MQMessage& msg, MessageQueueSelector* selector,
+ void* arg) = 0;
+ // non-strict order msg, if send failed on seleted MessageQueue, will auto
+ // retry others Broker queues with autoRetryTimes;
+ // if setted bActiveBroker, if send failed on seleted MessageQueue, , and then
+ // search brokers with best service state, lastly will search brokers that had
+ // been sent failed by last time;
+ virtual SendResult send(MQMessage& msg, MessageQueueSelector* selector,
+ void* arg, int autoRetryTimes,
+ bool bActiveBroker = false) = 0;
+ virtual void send(MQMessage& msg, SendCallback* sendCallback,
+ bool bSelectActiveBroker = false) = 0;
+ virtual void send(MQMessage& msg, const MQMessageQueue& mq,
+ SendCallback* sendCallback) = 0;
+ virtual void send(MQMessage& msg, MessageQueueSelector* selector, void* arg,
+ SendCallback* sendCallback) = 0;
+ virtual void sendOneway(MQMessage& msg, bool bSelectActiveBroker = false) = 0;
+ virtual void sendOneway(MQMessage& msg, const MQMessageQueue& mq) = 0;
+ virtual void sendOneway(MQMessage& msg, MessageQueueSelector* selector,
+ void* arg) = 0;
+};
+//<!***************************************************************************
+} //<!end namespace;
+#endif
http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/70ce5c77/rocketmq-cpp/include/MQSelector.h
----------------------------------------------------------------------
diff --git a/rocketmq-cpp/include/MQSelector.h b/rocketmq-cpp/include/MQSelector.h
new file mode 100755
index 0000000..77309b8
--- /dev/null
+++ b/rocketmq-cpp/include/MQSelector.h
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef _MQSELECTOR_H_
+#define _MQSELECTOR_H_
+#include "MQMessage.h"
+#include "MQMessageQueue.h"
+#include "RocketMQClient.h"
+
+namespace rocketmq {
+//<!***************************************************************************
+class ROCKETMQCLIENT_API MessageQueueSelector {
+ public:
+ virtual ~MessageQueueSelector() {}
+ virtual MQMessageQueue select(const std::vector<MQMessageQueue>& mqs,
+ const MQMessage& msg, void* arg) = 0;
+};
+//<!***************************************************************************
+} //<!end namespace;
+#endif //<! _MQSELECTOR_H_
http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/70ce5c77/rocketmq-cpp/include/MQueueListener.h
----------------------------------------------------------------------
diff --git a/rocketmq-cpp/include/MQueueListener.h b/rocketmq-cpp/include/MQueueListener.h
new file mode 100755
index 0000000..5938ebf
--- /dev/null
+++ b/rocketmq-cpp/include/MQueueListener.h
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __MESSAGEQUEUELISTENER_H__
+#define __MESSAGEQUEUELISTENER_H__
+
+#include <vector>
+#include "RocketMQClient.h"
+
+namespace rocketmq {
+//<!***************************************************************************
+class ROCKETMQCLIENT_API MQueueListener {
+ public:
+ virtual ~MQueueListener() {}
+ virtual void messageQueueChanged(const std::string& topic,
+ std::vector<MQMessageQueue>& mqAll,
+ std::vector<MQMessageQueue>& mqDivided) = 0;
+};
+//<!***************************************************************************
+} //<!end namespace;
+#endif
http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/70ce5c77/rocketmq-cpp/include/PullResult.h
----------------------------------------------------------------------
diff --git a/rocketmq-cpp/include/PullResult.h b/rocketmq-cpp/include/PullResult.h
new file mode 100755
index 0000000..69a6aef
--- /dev/null
+++ b/rocketmq-cpp/include/PullResult.h
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __PULLRESULT_H__
+#define __PULLRESULT_H__
+
+#include <sstream>
+#include "MQMessageExt.h"
+#include "RocketMQClient.h"
+
+namespace rocketmq {
+//<!***************************************************************************
+enum PullStatus {
+ FOUND,
+ NO_NEW_MSG,
+ NO_MATCHED_MSG,
+ OFFSET_ILLEGAL,
+ BROKER_TIMEOUT // indicate pull request timeout or received NULL response
+};
+
+static const char* EnumStrings[] = {"FOUND", "NO_NEW_MSG", "NO_MATCHED_MSG",
+ "OFFSET_ILLEGAL", "BROKER_TIMEOUT"};
+
+//<!***************************************************************************
+class ROCKETMQCLIENT_API PullResult {
+ public:
+ PullResult();
+ PullResult(PullStatus status);
+ PullResult(PullStatus pullStatus, int64 nextBeginOffset,
+ int64 minOffset, int64 maxOffset);
+
+ PullResult(PullStatus pullStatus, int64 nextBeginOffset,
+ int64 minOffset, int64 maxOffset,
+ const std::vector<MQMessageExt>& src);
+
+ virtual ~PullResult();
+
+ std::string toString() {
+ std::stringstream ss;
+ ss << "PullResult [ pullStatus=" << EnumStrings[pullStatus]
+ << ", nextBeginOffset=" << nextBeginOffset << ", minOffset=" << minOffset
+ << ", maxOffset=" << maxOffset
+ << ", msgFoundList=" << msgFoundList.size() << " ]";
+ return ss.str();
+ }
+
+ public:
+ PullStatus pullStatus;
+ int64 nextBeginOffset;
+ int64 minOffset;
+ int64 maxOffset;
+ std::vector<MQMessageExt> msgFoundList;
+};
+//<!***************************************************************************
+} //<!end namespace;
+#endif
http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/70ce5c77/rocketmq-cpp/include/QueryResult.h
----------------------------------------------------------------------
diff --git a/rocketmq-cpp/include/QueryResult.h b/rocketmq-cpp/include/QueryResult.h
new file mode 100755
index 0000000..c9861a0
--- /dev/null
+++ b/rocketmq-cpp/include/QueryResult.h
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __QUERYRESULT_H__
+#define __QUERYRESULT_H__
+
+#include "MQMessageExt.h"
+#include "RocketMQClient.h"
+
+namespace rocketmq {
+//<!************************************************************************
+class ROCKETMQCLIENT_API QueryResult {
+ public:
+ QueryResult(uint64 indexLastUpdateTimestamp,
+ const std::vector<MQMessageExt*>& messageList) {
+ m_indexLastUpdateTimestamp = indexLastUpdateTimestamp;
+ m_messageList = messageList;
+ }
+
+ uint64 getIndexLastUpdateTimestamp() { return m_indexLastUpdateTimestamp; }
+
+ std::vector<MQMessageExt*>& getMessageList() { return m_messageList; }
+
+ private:
+ uint64 m_indexLastUpdateTimestamp;
+ std::vector<MQMessageExt*> m_messageList;
+};
+//<!***************************************************************************
+} //<!end namespace;
+#endif
http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/70ce5c77/rocketmq-cpp/include/RocketMQClient.h
----------------------------------------------------------------------
diff --git a/rocketmq-cpp/include/RocketMQClient.h b/rocketmq-cpp/include/RocketMQClient.h
new file mode 100755
index 0000000..93be2d6
--- /dev/null
+++ b/rocketmq-cpp/include/RocketMQClient.h
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __ROCKETMQCLIENT_H__
+#define __ROCKETMQCLIENT_H__
+
+#ifdef WIN32
+#ifdef ROCKETMQCLIENT_EXPORTS
+#define ROCKETMQCLIENT_API __declspec(dllexport)
+#else
+#define ROCKETMQCLIENT_API __declspec(dllimport)
+#endif
+#else
+#define ROCKETMQCLIENT_API
+#endif
+
+/** A platform-independent 8-bit signed integer type. */
+typedef signed char int8;
+/** A platform-independent 8-bit unsigned integer type. */
+typedef unsigned char uint8;
+/** A platform-independent 16-bit signed integer type. */
+typedef signed short int16;
+/** A platform-independent 16-bit unsigned integer type. */
+typedef unsigned short uint16;
+/** A platform-independent 32-bit signed integer type. */
+typedef signed int int32;
+/** A platform-independent 32-bit unsigned integer type. */
+typedef unsigned int uint32;
+/** A platform-independent 64-bit integer type. */
+typedef long long int64;
+/** A platform-independent 64-bit unsigned integer type. */
+typedef unsigned long long uint64;
+
+#endif
http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/70ce5c77/rocketmq-cpp/include/SendMessageHook.h
----------------------------------------------------------------------
diff --git a/rocketmq-cpp/include/SendMessageHook.h b/rocketmq-cpp/include/SendMessageHook.h
new file mode 100755
index 0000000..f5a4835
--- /dev/null
+++ b/rocketmq-cpp/include/SendMessageHook.h
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __SENDMESSAGEHOOK_H__
+#define __SENDMESSAGEHOOK_H__
+
+#include "MQClientException.h"
+#include "MQMessage.h"
+#include "RocketMQClient.h"
+
+namespace rocketmq {
+//<!***************************************************************************
+class ROCKETMQCLIENT_API SendMessageContext {
+ public:
+ string producerGroup;
+ MQMessage msg;
+ MQMessageQueue mq;
+ string brokerAddr;
+ int communicationMode;
+ SendResult sendResult;
+ MQException* pException;
+ void* pArg;
+};
+
+class ROCKETMQCLIENT_API SendMessageHook {
+ public:
+ virtual ~SendMessageHook() {}
+ virtual string hookName() = 0;
+ virtual void sendMessageBefore(const SendMessageContext& context) = 0;
+ virtual void sendMessageAfter(const SendMessageContext& context) = 0;
+};
+//<!***************************************************************************
+} //<!end namespace;
+#endif
http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/70ce5c77/rocketmq-cpp/include/SendResult.h
----------------------------------------------------------------------
diff --git a/rocketmq-cpp/include/SendResult.h b/rocketmq-cpp/include/SendResult.h
new file mode 100755
index 0000000..0f51854
--- /dev/null
+++ b/rocketmq-cpp/include/SendResult.h
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __SENDRESULT_H__
+#define __SENDRESULT_H__
+
+#include "MQMessageQueue.h"
+#include "RocketMQClient.h"
+
+namespace rocketmq {
+//<!***************************************************************************
+//<!all to Master;
+enum SendStatus {
+ SEND_OK,
+ SEND_FLUSH_DISK_TIMEOUT,
+ SEND_FLUSH_SLAVE_TIMEOUT,
+ SEND_SLAVE_NOT_AVAILABLE
+};
+
+//<!***************************************************************************
+class ROCKETMQCLIENT_API SendResult {
+ public:
+ SendResult();
+ SendResult(const SendStatus& sendStatus, const std::string& msgId,
+ const MQMessageQueue& messageQueue, int64 queueOffset);
+
+ virtual ~SendResult();
+ SendResult(const SendResult& other);
+ SendResult& operator=(const SendResult& other);
+
+ const std::string& getMsgId() const;
+ SendStatus getSendStatus() const;
+ MQMessageQueue getMessageQueue() const;
+ int64 getQueueOffset() const;
+
+ private:
+ SendStatus m_sendStatus;
+ std::string m_msgId;
+ MQMessageQueue m_messageQueue;
+ int64 m_queueOffset;
+};
+
+//<!***************************************************************************
+} //<!end namespace;
+#endif
http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/70ce5c77/rocketmq-cpp/include/SessionCredentials.h
----------------------------------------------------------------------
diff --git a/rocketmq-cpp/include/SessionCredentials.h b/rocketmq-cpp/include/SessionCredentials.h
new file mode 100755
index 0000000..d4a4de9
--- /dev/null
+++ b/rocketmq-cpp/include/SessionCredentials.h
@@ -0,0 +1,62 @@
+
+#ifndef __SESSIONCREDENTIALS_H__
+#define __SESSIONCREDENTIALS_H__
+
+#include "RocketMQClient.h"
+
+namespace rocketmq {
+
+class SessionCredentials {
+ public:
+ static const std::string AccessKey;
+ static const std::string SecretKey;
+ static const std::string Signature;
+ static const std::string SignatureMethod;
+ static const std::string ONSChannelKey;
+
+ SessionCredentials(std::string input_accessKey, std::string input_secretKey,
+ const std::string& input_authChannel)
+ : accessKey(input_accessKey),
+ secretKey(input_secretKey),
+ authChannel(input_authChannel) {}
+ SessionCredentials() : authChannel("ALIYUN") {}
+ ~SessionCredentials() {}
+
+ std::string getAccessKey() const { return accessKey; }
+
+ void setAccessKey(std::string input_accessKey) { accessKey = input_accessKey; }
+
+ std::string getSecretKey() const { return secretKey; }
+
+ void setSecretKey(std::string input_secretKey) { secretKey = input_secretKey; }
+
+ std::string getSignature() const { return signature; }
+
+ void setSignature(std::string input_signature) { signature = input_signature; }
+
+ std::string getSignatureMethod() const { return signatureMethod; }
+
+ void setSignatureMethod(std::string input_signatureMethod) {
+ signatureMethod = input_signatureMethod;
+ }
+
+ std::string getAuthChannel() const { return authChannel; }
+
+ void setAuthChannel(std::string input_channel) { authChannel = input_channel; }
+
+ bool isValid() const {
+ if (accessKey.empty() || secretKey.empty() || authChannel.empty())
+ return false;
+
+ return true;
+ }
+
+ private:
+ std::string accessKey;
+ std::string secretKey;
+ std::string signature;
+ std::string signatureMethod;
+ std::string authChannel;
+};
+}
+#endif
http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/70ce5c77/rocketmq-cpp/libs/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/rocketmq-cpp/libs/CMakeLists.txt b/rocketmq-cpp/libs/CMakeLists.txt
new file mode 100755
index 0000000..015951d
--- /dev/null
+++ b/rocketmq-cpp/libs/CMakeLists.txt
@@ -0,0 +1,16 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+add_subdirectory(signature)
http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/70ce5c77/rocketmq-cpp/libs/signature/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/rocketmq-cpp/libs/signature/CMakeLists.txt b/rocketmq-cpp/libs/signature/CMakeLists.txt
new file mode 100755
index 0000000..84ca0c5
--- /dev/null
+++ b/rocketmq-cpp/libs/signature/CMakeLists.txt
@@ -0,0 +1,25 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+project(signature)
+
+include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
+set(LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/lib)
+
+aux_source_directory(src/ DIR_LIB_SRCS)
+
+add_library(Signature STATIC ${DIR_LIB_SRCS})
+target_link_libraries(Signature ${deplibs})
+set_target_properties(Signature PROPERTIES OUTPUT_NAME "Signature")
http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/70ce5c77/rocketmq-cpp/libs/signature/Makefile
----------------------------------------------------------------------
diff --git a/rocketmq-cpp/libs/signature/Makefile b/rocketmq-cpp/libs/signature/Makefile
new file mode 100644
index 0000000..f3368cb
--- /dev/null
+++ b/rocketmq-cpp/libs/signature/Makefile
@@ -0,0 +1,63 @@
+##====================================================================
+# make release=0 debug版。
+# make release=1 release版。
+CXXFLAGS = -g -fPIC -Wno-deprecated -O3
+
+ifeq ($(shell uname -m),x86_64)
+ CXXFLAGS += -m64
+ BITS:= 64
+else
+ CXXFLAGS += -m32
+ BITS := 32
+endif
+
+ifeq ($(release),0)
+ CXXFLAGS += -DDEBUG
+ OUTCONFIG := debug
+else
+ CXXFLAGS += -DNDEBUG
+ OUTCONFIG := release
+endif
+
+##====================================================================
+TOPDIR := .
+TARGET := $(TOPDIR)/lib/libSignature.a
+
+CPP_SRCDIR := $(TOPDIR)/src
+CPP_SRC := $(foreach dir,$(CPP_SRCDIR), $(wildcard $(dir)/*.c))
+CPP_OBJS := $(patsubst %.c, %.o, $(CPP_SRC))
+VPATH := $(CPP_SRCDIR)
+
+LDLIBS :=
+LIBPATH :=
+CPPFLAGS := -I$(TOPDIR)/include $(addprefix -I,$(CPP_SRCDIR))
+
+CXX := g++
+AR := ar
+ARFLAGS := rcs
+##====================================================================
+all: build
+
+build:$(TARGET)
+
+
+$(TARGET):$(CPP_OBJS)
+ $(AR) $(ARFLAGS) $@ $^ $(LIBPATH) $(LDLIBS)
+
+%.o: %.c
+ $(CXX) -c $(CXXFLAGS) $(CPPFLAGS) -o $@ $<
+
+
+rebuild:clean build
+
+test:
+ @echo $(CPP_SRC)
+ @echo $(CPP_OBJS)
+
+clean:
+ $(RM) -rf $(CPP_OBJS)
+ $(RM) -rf $(TARGET)
+ $(RM) -rf tmp
+
+
+
http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/70ce5c77/rocketmq-cpp/libs/signature/include/base64.h
----------------------------------------------------------------------
diff --git a/rocketmq-cpp/libs/signature/include/base64.h b/rocketmq-cpp/libs/signature/include/base64.h
new file mode 100755
index 0000000..7b2b3b7
--- /dev/null
+++ b/rocketmq-cpp/libs/signature/include/base64.h
@@ -0,0 +1,54 @@
+/* base64.h -- Encode binary data using printable characters.
+ Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc.
+ Written by Simon Josefsson.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software Foundation,
+ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+
+#ifndef BASE64_H
+# define BASE64_H
+
+/* Get size_t. */
+# include <stddef.h>
+
+/* Get bool. */
+# include <stdbool.h>
+
+
+#ifdef __cplusplus
+namespace metaqSignature{
+#endif
+
+ /* This uses that the expression (n+(k-1))/k means the smallest
+ integer >= n/k, i.e., the ceiling of n/k. */
+# define BASE64_LENGTH(inlen) ((((inlen) + 2) / 3) * 4)
+
+extern bool isbase64(char ch);
+
+extern void base64_encode(const char *in, size_t inlen,
+ char *out, size_t outlen);
+
+extern size_t base64_encode_alloc(const char *in, size_t inlen, char **out);
+
+extern bool base64_decode(const char *in, size_t inlen,
+ char *out, size_t *outlen);
+
+extern bool base64_decode_alloc(const char *in, size_t inlen,
+ char **out, size_t *outlen);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* BASE64_H */
http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/70ce5c77/rocketmq-cpp/libs/signature/include/hmac.h
----------------------------------------------------------------------
diff --git a/rocketmq-cpp/libs/signature/include/hmac.h b/rocketmq-cpp/libs/signature/include/hmac.h
new file mode 100755
index 0000000..9ddd621
--- /dev/null
+++ b/rocketmq-cpp/libs/signature/include/hmac.h
@@ -0,0 +1,55 @@
+
+#ifndef _HMAC_HMAC_H
+#define _HMAC_HMAC_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <sys/types.h>
+
+#ifndef SHA1_DIGEST_LEN
+#define SHA1_DIGEST_LEN 20
+#endif
+
+#ifndef SHA256_DIGEST_LEN
+#define SHA256_DIGEST_LEN 32
+#endif
+
+#ifndef SHA512_DIGEST_LEN
+#define SHA512_DIGEST_LEN 64
+#endif
+
+/*
+ * hmac_sha1:
+ * hmac_sha256:
+ * hmac_sha512:
+ * Calculate Hashed Message Authentication Code with sha1/256/512 algorithm
+ * Caution: ret_buf should provide enough space for HMAC result.
+ *
+ * @key [in]: the secure-key string
+ * @key_len [in]: the length of secure-key
+ * @data [in]: data string could be calculated.
+ * @data_len [in]: the length of data. length is needed because strlen could not take effect.
+ * @ret_buf [out]: HMAC result stored in ret_buf.
+ */
+
+#ifdef __cplusplus
+namespace metaqSignature{
+
+#endif
+
+extern int hmac_sha1(const void *key, size_t key_len, const void *data, size_t data_len, void *ret_buf);
+extern int hmac_sha256(const void *key, size_t key_len, const void *data, size_t data_len, void *ret_buf);
+extern int hmac_sha512(const void *key, size_t key_len, const void *data, size_t data_len, void *ret_buf);
+
+#ifdef __cplusplus
+}
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/70ce5c77/rocketmq-cpp/libs/signature/include/param_list.h
----------------------------------------------------------------------
diff --git a/rocketmq-cpp/libs/signature/include/param_list.h b/rocketmq-cpp/libs/signature/include/param_list.h
new file mode 100755
index 0000000..0fd4e3d
--- /dev/null
+++ b/rocketmq-cpp/libs/signature/include/param_list.h
@@ -0,0 +1,39 @@
+#ifndef PARAM_LIST_H
+#define PARAM_LIST_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef __cplusplus
+namespace metaqSignature{
+#endif
+
+
+typedef struct _spas_param_node {
+ char *name;
+ char *value;
+ struct _spas_param_node *pnext;
+} SPAS_PARAM_NODE;
+
+typedef struct _spas_param_list {
+ SPAS_PARAM_NODE *phead;
+ unsigned int length; /* count of nodes */
+ unsigned int size; /* total size of string presentation */
+} SPAS_PARAM_LIST;
+
+extern SPAS_PARAM_LIST * create_param_list(void);
+extern int add_param_to_list(SPAS_PARAM_LIST *list, const char *name, const char *value);
+extern void free_param_list(SPAS_PARAM_LIST *list);
+extern char * param_list_to_str(const SPAS_PARAM_LIST *list);
+
+#ifdef __cplusplus
+}
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/70ce5c77/rocketmq-cpp/libs/signature/include/sha1.h
----------------------------------------------------------------------
diff --git a/rocketmq-cpp/libs/signature/include/sha1.h b/rocketmq-cpp/libs/signature/include/sha1.h
new file mode 100755
index 0000000..cfb718a
--- /dev/null
+++ b/rocketmq-cpp/libs/signature/include/sha1.h
@@ -0,0 +1,93 @@
+/* Declarations of functions and data types used for SHA1 sum
+ library functions.
+ Copyright (C) 2000, 2001, 2003, 2005, 2006, 2008
+ Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by the
+ Free Software Foundation; either version 2, or (at your option) any
+ later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software Foundation,
+ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+
+#ifndef SHA1_H
+# define SHA1_H 1
+
+# include <stdio.h>
+# include <stdint.h>
+
+#ifdef __cplusplus
+namespace metaqSignature {
+#endif
+
+#define SHA1_DIGEST_SIZE 20
+
+/* Structure to save state of computation between the single steps. */
+struct sha1_ctx
+{
+ uint32_t A;
+ uint32_t B;
+ uint32_t C;
+ uint32_t D;
+ uint32_t E;
+
+ uint32_t total[2];
+ uint32_t buflen;
+ uint32_t buffer[32];
+};
+
+
+/* Initialize structure containing state of computation. */
+extern void sha1_init_ctx (struct sha1_ctx *ctx);
+
+/* Starting with the result of former calls of this function (or the
+ initialization function update the context for the next LEN bytes
+ starting at BUFFER.
+ It is necessary that LEN is a multiple of 64!!! */
+extern void sha1_process_block (const void *buffer, size_t len,
+ struct sha1_ctx *ctx);
+
+/* Starting with the result of former calls of this function (or the
+ initialization function update the context for the next LEN bytes
+ starting at BUFFER.
+ It is NOT required that LEN is a multiple of 64. */
+extern void sha1_process_bytes (const void *buffer, size_t len,
+ struct sha1_ctx *ctx);
+
+/* Process the remaining bytes in the buffer and put result from CTX
+ in first 20 bytes following RESBUF. The result is always in little
+ endian byte order, so that a byte-wise output yields to the wanted
+ ASCII representation of the message digest. */
+extern void *sha1_finish_ctx (struct sha1_ctx *ctx, void *resbuf);
+
+
+/* Put result from CTX in first 20 bytes following RESBUF. The result is
+ always in little endian byte order, so that a byte-wise output yields
+ to the wanted ASCII representation of the message digest. */
+extern void *sha1_read_ctx (const struct sha1_ctx *ctx, void *resbuf);
+
+
+/* Compute SHA1 message digest for bytes read from STREAM. The
+ resulting message digest number will be written into the 20 bytes
+ beginning at RESBLOCK. */
+extern int sha1_stream (FILE *stream, void *resblock);
+
+
+/* Compute SHA1 message digest for LEN bytes beginning at BUFFER. The
+ result is always in little endian byte order, so that a byte-wise
+ output yields to the wanted ASCII representation of the message
+ digest. */
+extern void *sha1_buffer (const char *buffer, size_t len, void *resblock);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/70ce5c77/rocketmq-cpp/libs/signature/include/sha256.h
----------------------------------------------------------------------
diff --git a/rocketmq-cpp/libs/signature/include/sha256.h b/rocketmq-cpp/libs/signature/include/sha256.h
new file mode 100755
index 0000000..1756e84
--- /dev/null
+++ b/rocketmq-cpp/libs/signature/include/sha256.h
@@ -0,0 +1,91 @@
+/* Declarations of functions and data types used for SHA256 and SHA224 sum
+ library functions.
+ Copyright (C) 2005, 2006, 2008 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef SHA256_H
+# define SHA256_H 1
+
+# include <stdio.h>
+# include <stdint.h>
+
+#ifdef __cplusplus
+namespace metaqSignature{
+#endif
+
+/* Structure to save state of computation between the single steps. */
+struct sha256_ctx
+{
+ uint32_t state[8];
+
+ uint32_t total[2];
+ size_t buflen;
+ uint32_t buffer[32];
+};
+
+enum { SHA224_DIGEST_SIZE = 28 };
+enum { SHA256_DIGEST_SIZE = 32 };
+
+/* Initialize structure containing state of computation. */
+extern void sha256_init_ctx (struct sha256_ctx *ctx);
+extern void sha224_init_ctx (struct sha256_ctx *ctx);
+
+/* Starting with the result of former calls of this function (or the
+ initialization function update the context for the next LEN bytes
+ starting at BUFFER.
+ It is necessary that LEN is a multiple of 64!!! */
+extern void sha256_process_block (const void *buffer, size_t len,
+ struct sha256_ctx *ctx);
+
+/* Starting with the result of former calls of this function (or the
+ initialization function update the context for the next LEN bytes
+ starting at BUFFER.
+ It is NOT required that LEN is a multiple of 64. */
+extern void sha256_process_bytes (const void *buffer, size_t len,
+ struct sha256_ctx *ctx);
+
+/* Process the remaining bytes in the buffer and put result from CTX
+ in first 32 (28) bytes following RESBUF. The result is always in little
+ endian byte order, so that a byte-wise output yields to the wanted
+ ASCII representation of the message digest. */
+extern void *sha256_finish_ctx (struct sha256_ctx *ctx, void *resbuf);
+extern void *sha224_finish_ctx (struct sha256_ctx *ctx, void *resbuf);
+
+
+/* Put result from CTX in first 32 (28) bytes following RESBUF. The result is
+ always in little endian byte order, so that a byte-wise output yields
+ to the wanted ASCII representation of the message digest. */
+extern void *sha256_read_ctx (const struct sha256_ctx *ctx, void *resbuf);
+extern void *sha224_read_ctx (const struct sha256_ctx *ctx, void *resbuf);
+
+
+/* Compute SHA256 (SHA224) message digest for bytes read from STREAM. The
+ resulting message digest number will be written into the 32 (28) bytes
+ beginning at RESBLOCK. */
+extern int sha256_stream (FILE *stream, void *resblock);
+extern int sha224_stream (FILE *stream, void *resblock);
+
+/* Compute SHA256 (SHA224) message digest for LEN bytes beginning at BUFFER. The
+ result is always in little endian byte order, so that a byte-wise
+ output yields to the wanted ASCII representation of the message
+ digest. */
+extern void *sha256_buffer (const char *buffer, size_t len, void *resblock);
+extern void *sha224_buffer (const char *buffer, size_t len, void *resblock);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/70ce5c77/rocketmq-cpp/libs/signature/include/sha512.h
----------------------------------------------------------------------
diff --git a/rocketmq-cpp/libs/signature/include/sha512.h b/rocketmq-cpp/libs/signature/include/sha512.h
new file mode 100755
index 0000000..0b3b5e7
--- /dev/null
+++ b/rocketmq-cpp/libs/signature/include/sha512.h
@@ -0,0 +1,95 @@
+/* Declarations of functions and data types used for SHA512 and SHA384 sum
+ library functions.
+ Copyright (C) 2005, 2006, 2008 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef SHA512_H
+# define SHA512_H 1
+
+# include <stdio.h>
+
+# include "u64.h"
+
+#ifdef __cplusplus
+namespace metaqSignature{
+#endif
+
+/* Structure to save state of computation between the single steps. */
+struct sha512_ctx
+{
+ u64 state[8];
+
+ u64 total[2];
+ size_t buflen;
+ u64 buffer[32];
+};
+
+enum { SHA384_DIGEST_SIZE = 48 };
+enum { SHA512_DIGEST_SIZE = 64 };
+
+/* Initialize structure containing state of computation. */
+extern void sha512_init_ctx (struct sha512_ctx *ctx);
+extern void sha384_init_ctx (struct sha512_ctx *ctx);
+
+/* Starting with the result of former calls of this function (or the
+ initialization function update the context for the next LEN bytes
+ starting at BUFFER.
+ It is necessary that LEN is a multiple of 128!!! */
+extern void sha512_process_block (const void *buffer, size_t len,
+ struct sha512_ctx *ctx);
+
+/* Starting with the result of former calls of this function (or the
+ initialization function update the context for the next LEN bytes
+ starting at BUFFER.
+ It is NOT required that LEN is a multiple of 128. */
+extern void sha512_process_bytes (const void *buffer, size_t len,
+ struct sha512_ctx *ctx);
+
+/* Process the remaining bytes in the buffer and put result from CTX
+ in first 64 (48) bytes following RESBUF. The result is always in little
+ endian byte order, so that a byte-wise output yields to the wanted
+ ASCII representation of the message digest. */
+extern void *sha512_finish_ctx (struct sha512_ctx *ctx, void *resbuf);
+extern void *sha384_finish_ctx (struct sha512_ctx *ctx, void *resbuf);
+
+
+/* Put result from CTX in first 64 (48) bytes following RESBUF. The result is
+ always in little endian byte order, so that a byte-wise output yields
+ to the wanted ASCII representation of the message digest.
+
+ IMPORTANT: On some systems it is required that RESBUF is correctly
+ aligned for a 32 bits value. */
+extern void *sha512_read_ctx (const struct sha512_ctx *ctx, void *resbuf);
+extern void *sha384_read_ctx (const struct sha512_ctx *ctx, void *resbuf);
+
+
+/* Compute SHA512 (SHA384) message digest for bytes read from STREAM. The
+ resulting message digest number will be written into the 64 (48) bytes
+ beginning at RESBLOCK. */
+extern int sha512_stream (FILE *stream, void *resblock);
+extern int sha384_stream (FILE *stream, void *resblock);
+
+/* Compute SHA512 (SHA384) message digest for LEN bytes beginning at BUFFER. The
+ result is always in little endian byte order, so that a byte-wise
+ output yields to the wanted ASCII representation of the message
+ digest. */
+extern void *sha512_buffer (const char *buffer, size_t len, void *resblock);
+extern void *sha384_buffer (const char *buffer, size_t len, void *resblock);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/70ce5c77/rocketmq-cpp/libs/signature/include/spas_client.h
----------------------------------------------------------------------
diff --git a/rocketmq-cpp/libs/signature/include/spas_client.h b/rocketmq-cpp/libs/signature/include/spas_client.h
new file mode 100755
index 0000000..b8fa02c
--- /dev/null
+++ b/rocketmq-cpp/libs/signature/include/spas_client.h
@@ -0,0 +1,85 @@
+#ifndef SPAS_CLIENT_H
+#define SPAS_CLIENT_H
+
+#include "param_list.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef __cplusplus
+ namespace metaqSignature {
+#endif
+
+#define SPAS_MAX_KEY_LEN 128 /* max access_key/secret_key length */
+#define SPAS_MAX_PATH 256 /* max credential file path length */
+#define SPAS_ACCESS_KEY_TAG "accessKey" /* access_key tag in credential file */
+#define SPAS_SECRET_KEY_TAG "secretKey" /* secret_key tag in credential file */
+#define SPAS_CREDENTIAL_ENV "SPAS_CREDENTIAL" /* credential file environment variable */
+
+
+ typedef enum {
+ SIGN_HMACSHA1 = 0, /* HmacSHA1 */
+ SIGN_HMACSHA256 = 1, /* HmacSHA256 */
+ } SPAS_SIGN_ALGORITHM;
+
+ typedef enum {
+ NO_UPDATE = 0, /* do not update credential */
+ UPDATE_BY_ALARM = 1, /* update credential by SIGALRM */
+#ifdef SPAS_MT
+ UPDATE_BY_THREAD = 2, /* update credential by standalone thread */
+#endif
+ } CREDENTIAL_UPDATE_MODE;
+
+ typedef enum {
+ NO_ERROR = 0, /* success */
+ ERROR_INVALID_PARAM = -1, /* invalid parameter */
+ ERROR_NO_CREDENTIAL = -2, /* credential file not specified */
+ ERROR_FILE_OPEN = -3, /* file open failed */
+ ERROR_MEM_ALLOC = -4, /* memory allocation failed */
+ ERROR_MISSING_KEY = -5, /* missing access_key/secret_key */
+ ERROR_KEY_LENGTH = -6, /* key length exceed limit */
+ ERROR_UPDATE_CREDENTIAL = -7, /* update credential file failed */
+
+ } SPAS_ERROR_CODE;
+
+ typedef struct _spas_credential {
+ char access_key[SPAS_MAX_KEY_LEN];
+ char secret_key[SPAS_MAX_KEY_LEN];
+ } SPAS_CREDENTIAL;
+
+
+ extern int spas_load_credential(char *path, CREDENTIAL_UPDATE_MODE mode);
+ extern int spas_set_access_key(char *key);
+ extern int spas_set_secret_key(char *key);
+ extern char * spas_get_access_key(void);
+ extern char * spas_get_secret_key(void);
+ extern SPAS_CREDENTIAL * spas_get_credential(void);
+
+#ifdef SPAS_MT
+
+ extern int spas_load_thread_credential(char *path);
+ extern int spas_set_thread_access_key(char *key);
+ extern int spas_set_thread_secret_key(char *key);
+ extern char * spas_get_thread_access_key(void);
+ extern char * spas_get_thread_secret_key(void);
+
+#endif
+
+ extern char * spas_get_signature(const SPAS_PARAM_LIST *list, const char *key);
+ extern char * spas_get_signature2(const SPAS_PARAM_LIST *list, const char *key, SPAS_SIGN_ALGORITHM algorithm);
+ extern char * spas_sign(const char *data, size_t size, const char *key);
+ extern char * spas_sign2(const char *data, size_t size, const char *key, SPAS_SIGN_ALGORITHM algorithm);
+ extern void spas_mem_free(char *pSignature);
+ extern char * spas_get_version(void);
+
+#ifdef __cplusplus
+ }
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/70ce5c77/rocketmq-cpp/libs/signature/include/u64.h
----------------------------------------------------------------------
diff --git a/rocketmq-cpp/libs/signature/include/u64.h b/rocketmq-cpp/libs/signature/include/u64.h
new file mode 100644
index 0000000..34fd32b
--- /dev/null
+++ b/rocketmq-cpp/libs/signature/include/u64.h
@@ -0,0 +1,159 @@
+/* uint64_t-like operations that work even on hosts lacking uint64_t
+
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Paul Eggert. */
+
+#include <stddef.h>
+#include <stdint.h>
+
+/* Return X rotated left by N bits, where 0 < N < 64. */
+#define u64rol(x, n) u64or (u64shl (x, n), u64shr (x, 64 - n))
+
+#ifdef UINT64_MAX
+
+/* Native implementations are trivial. See below for comments on what
+ these operations do. */
+typedef uint64_t u64;
+# define u64hilo(hi, lo) ((u64) (((u64) (hi) << 32) + (lo)))
+# define u64init(hi, lo) u64hilo (hi, lo)
+# define u64lo(x) ((u64) (x))
+# define u64lt(x, y) ((x) < (y))
+# define u64and(x, y) ((x) & (y))
+# define u64or(x, y) ((x) | (y))
+# define u64xor(x, y) ((x) ^ (y))
+# define u64plus(x, y) ((x) + (y))
+# define u64shl(x, n) ((x) << (n))
+# define u64shr(x, n) ((x) >> (n))
+
+#else
+
+/* u64 is a 64-bit unsigned integer value.
+ u64init (HI, LO), is like u64hilo (HI, LO), but for use in
+ initializer contexts. */
+# ifdef WORDS_BIGENDIAN
+typedef struct { uint32_t hi, lo; } u64;
+# define u64init(hi, lo) { hi, lo }
+# else
+typedef struct { uint32_t lo, hi; } u64;
+# define u64init(hi, lo) { lo, hi }
+# endif
+
+/* Given the high and low-order 32-bit quantities HI and LO, return a u64
+ value representing (HI << 32) + LO. */
+static inline u64
+u64hilo (uint32_t hi, uint32_t lo)
+{
+ u64 r;
+ r.hi = hi;
+ r.lo = lo;
+ return r;
+}
+
+/* Return a u64 value representing LO. */
+static inline u64
+u64lo (uint32_t lo)
+{
+ u64 r;
+ r.hi = 0;
+ r.lo = lo;
+ return r;
+}
+
+/* Return X < Y. */
+static inline int
+u64lt (u64 x, u64 y)
+{
+ return x.hi < y.hi || (x.hi == y.hi && x.lo < y.lo);
+}
+
+/* Return X & Y. */
+static inline u64
+u64and (u64 x, u64 y)
+{
+ u64 r;
+ r.hi = x.hi & y.hi;
+ r.lo = x.lo & y.lo;
+ return r;
+}
+
+/* Return X | Y. */
+static inline u64
+u64or (u64 x, u64 y)
+{
+ u64 r;
+ r.hi = x.hi | y.hi;
+ r.lo = x.lo | y.lo;
+ return r;
+}
+
+/* Return X ^ Y. */
+static inline u64
+u64xor (u64 x, u64 y)
+{
+ u64 r;
+ r.hi = x.hi ^ y.hi;
+ r.lo = x.lo ^ y.lo;
+ return r;
+}
+
+/* Return X + Y. */
+static inline u64
+u64plus (u64 x, u64 y)
+{
+ u64 r;
+ r.lo = x.lo + y.lo;
+ r.hi = x.hi + y.hi + (r.lo < x.lo);
+ return r;
+}
+
+/* Return X << N. */
+static inline u64
+u64shl (u64 x, int n)
+{
+ u64 r;
+ if (n < 32)
+ {
+ r.hi = (x.hi << n) | (x.lo >> (32 - n));
+ r.lo = x.lo << n;
+ }
+ else
+ {
+ r.hi = x.lo << (n - 32);
+ r.lo = 0;
+ }
+ return r;
+}
+
+/* Return X >> N. */
+static inline u64
+u64shr (u64 x, int n)
+{
+ u64 r;
+ if (n < 32)
+ {
+ r.hi = x.hi >> n;
+ r.lo = (x.hi << (32 - n)) | (x.lo >> n);
+ }
+ else
+ {
+ r.hi = 0;
+ r.lo = x.hi >> (n - 32);
+ }
+ return r;
+}
+
+#endif
http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/70ce5c77/rocketmq-cpp/libs/signature/lib/.gitkeep
----------------------------------------------------------------------
diff --git a/rocketmq-cpp/libs/signature/lib/.gitkeep b/rocketmq-cpp/libs/signature/lib/.gitkeep
new file mode 100644
index 0000000..533bd5f
--- /dev/null
+++ b/rocketmq-cpp/libs/signature/lib/.gitkeep
@@ -0,0 +1 @@
+#keep
http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/70ce5c77/rocketmq-cpp/libs/signature/msvc13/Metaqsignature.sln
----------------------------------------------------------------------
diff --git a/rocketmq-cpp/libs/signature/msvc13/Metaqsignature.sln b/rocketmq-cpp/libs/signature/msvc13/Metaqsignature.sln
new file mode 100755
index 0000000..ea15e8e
--- /dev/null
+++ b/rocketmq-cpp/libs/signature/msvc13/Metaqsignature.sln
@@ -0,0 +1,22 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 2013
+VisualStudioVersion = 12.0.21005.1
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Metaqsignature", "Metaqsignature.vcxproj", "{F93E745C-232C-46A0-8D4B-91D3A53EE699}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Win32 = Debug|Win32
+ Release|Win32 = Release|Win32
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {F93E745C-232C-46A0-8D4B-91D3A53EE699}.Debug|Win32.ActiveCfg = Debug|Win32
+ {F93E745C-232C-46A0-8D4B-91D3A53EE699}.Debug|Win32.Build.0 = Debug|Win32
+ {F93E745C-232C-46A0-8D4B-91D3A53EE699}.Release|Win32.ActiveCfg = Release|Win32
+ {F93E745C-232C-46A0-8D4B-91D3A53EE699}.Release|Win32.Build.0 = Release|Win32
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal