ons 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.rspec +2 -0
- data/.rubocop.yml +7 -0
- data/.yardopts +3 -0
- data/Gemfile +4 -0
- data/README-zh_CN.md +80 -0
- data/README.md +36 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/rake +9 -0
- data/bin/setup +8 -0
- data/ext/ons/aliyun-mq-cpp-sdk/include/ons/Action.h +12 -0
- data/ext/ons/aliyun-mq-cpp-sdk/include/ons/ConsumeContext.h +15 -0
- data/ext/ons/aliyun-mq-cpp-sdk/include/ons/LocalTransactionChecker.h +16 -0
- data/ext/ons/aliyun-mq-cpp-sdk/include/ons/LocalTransactionExecuter.h +16 -0
- data/ext/ons/aliyun-mq-cpp-sdk/include/ons/Message.h +96 -0
- data/ext/ons/aliyun-mq-cpp-sdk/include/ons/MessageListener.h +20 -0
- data/ext/ons/aliyun-mq-cpp-sdk/include/ons/ONSChannel.h +17 -0
- data/ext/ons/aliyun-mq-cpp-sdk/include/ons/ONSClient.h +28 -0
- data/ext/ons/aliyun-mq-cpp-sdk/include/ons/ONSClientException.h +27 -0
- data/ext/ons/aliyun-mq-cpp-sdk/include/ons/ONSFactory.h +73 -0
- data/ext/ons/aliyun-mq-cpp-sdk/include/ons/Producer.h +29 -0
- data/ext/ons/aliyun-mq-cpp-sdk/include/ons/PushConsumer.h +22 -0
- data/ext/ons/aliyun-mq-cpp-sdk/include/ons/SendResultONS.h +22 -0
- data/ext/ons/aliyun-mq-cpp-sdk/include/ons/TransactionProducer.h +22 -0
- data/ext/ons/aliyun-mq-cpp-sdk/include/ons/TransactionStatus.h +15 -0
- data/ext/ons/aliyun-mq-cpp-sdk/lib/libonsclient4cpp.so +0 -0
- data/ext/ons/consumer.cpp +68 -0
- data/ext/ons/consumer.hpp +33 -0
- data/ext/ons/extconf.rb +44 -0
- data/ext/ons/listener.cpp +19 -0
- data/ext/ons/listener.hpp +25 -0
- data/ext/ons/lmfao.cpp +251 -0
- data/ext/ons/lmfao.hpp +101 -0
- data/ext/ons/ons.cpp +19 -0
- data/ext/ons/ons.hpp +7 -0
- data/ext/ons/producer.cpp +74 -0
- data/ext/ons/producer.hpp +30 -0
- data/lib/ons/consumer.rb +71 -0
- data/lib/ons/lmfao.rb +18 -0
- data/lib/ons/producer.rb +80 -0
- data/lib/ons/version.rb +3 -0
- data/lib/ons.rb +36 -0
- data/ons.gemspec +42 -0
- data/samples/consumer.rb +32 -0
- data/samples/producer.rb +35 -0
- metadata +218 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 80474fb3032832392ef7844f0eb062d11203fcd8
|
4
|
+
data.tar.gz: f4014c329ff734765715541a016631b1c00d73b5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2201e16dd77b6e767a706b1fc40e2fc644c3c0a31575f480d123aee995fd9d890aae3a43dd61f95cde34454fe13c1d287ef74a27dd5d8feace32b827f51982fb
|
7
|
+
data.tar.gz: d5970d7a6b0742bb2ade1ae031e6f9c903ad831f3d48c4e769c39acdb18ed9893977fbda76e8f1763d3438e8f17e0dbbc9991f12e692a54467feb3068a9b39df
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.yardopts
ADDED
data/Gemfile
ADDED
data/README-zh_CN.md
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
# Ons
|
2
|
+
|
3
|
+
阿里云 ONS 消息队列服务 Ruby SDK(非官方版本)
|
4
|
+
|
5
|
+
## 项目依赖
|
6
|
+
|
7
|
+
* Linux/Unix 系统
|
8
|
+
* Ruby 2.1.5 或以上版本
|
9
|
+
* Boost C++ 程序库
|
10
|
+
|
11
|
+
## 安装步骤
|
12
|
+
|
13
|
+
### 安装 Ruby 程序
|
14
|
+
|
15
|
+
```sh
|
16
|
+
$ rvm install 2.1.5
|
17
|
+
```
|
18
|
+
|
19
|
+
### 安装 Boost C++ 程序库
|
20
|
+
|
21
|
+
```sh
|
22
|
+
$ apt-get install libboost-all-dev
|
23
|
+
```
|
24
|
+
|
25
|
+
### 安装 ons
|
26
|
+
|
27
|
+
```sh
|
28
|
+
$ git clone https://github.com/souche/aliyun-ons-ruby-sdk.git
|
29
|
+
$ cd ons
|
30
|
+
$ ./bin/setup
|
31
|
+
$ ./bin/rake install
|
32
|
+
```
|
33
|
+
|
34
|
+
## 使用方式
|
35
|
+
|
36
|
+
### 环境准备
|
37
|
+
|
38
|
+
* 安装 ons rubygems。
|
39
|
+
* 代码里涉及到的 TOPIC、PRODUCER_ID、CONSUMER_ID,需要在 MQ 控制台上创建。 Message Tag 可以完全由应用自定义,具体创建过程可参考 [申请MQ资源](https://help.aliyun.com/document_detail/29536.html)。
|
40
|
+
* 使用 MQ 服务的应用程序需要部署在阿里云 ECS 上。
|
41
|
+
|
42
|
+
部分资料来自 [消息队列 > TCP 接入(专业) > C/C++ SDK 环境准备](https://help.aliyun.com/document_detail/29555.html)
|
43
|
+
|
44
|
+
### 生产者
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
producer = Ons::Producer.new('<ONS_ACCESS_KEY>', '<ONS_SECRET_KEY>', '<ONS_PRODUCER_ID>')
|
48
|
+
|
49
|
+
# 资源准备
|
50
|
+
producer.start
|
51
|
+
|
52
|
+
# 在 topic <ONS_TOPIC> 下发送消息
|
53
|
+
producer.send_message('<ONS_TOPIC>', 'tag', 'Hello, World!')
|
54
|
+
|
55
|
+
# 必须在程序退出前调用 shutdown 方法释放相关资源,否则可能出现栈错误
|
56
|
+
producer.shutdown
|
57
|
+
```
|
58
|
+
|
59
|
+
更多用法,请参考 {file:samples/producer.rb} 及 API 文档
|
60
|
+
|
61
|
+
### 消费者
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
consumer = Ons::Consumer.new('<ONS_ACCESS_KEY>', '<ONS_SECRET_KEY>', '<ONS_CONSUMER_ID>')
|
65
|
+
|
66
|
+
# 订阅 topic <ONS_TOPIC> 下的所有消息
|
67
|
+
# 注意,当消息达到时,会调用下述函数,此函数会被调度到单独线程中执行
|
68
|
+
consumer.subscribe('<ONS_TOPIC>', '*') { |message| p message }
|
69
|
+
|
70
|
+
# 资源准备
|
71
|
+
consumer.start
|
72
|
+
|
73
|
+
# 等待消息到达
|
74
|
+
sleep 32
|
75
|
+
|
76
|
+
# 必须在程序退出前调用 shutdown 方法释放相关资源,否则可能出现栈错误
|
77
|
+
consumer.shutdown
|
78
|
+
```
|
79
|
+
|
80
|
+
更多用法,请参考 {file:samples/consumer.rb} 及 API 文档
|
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# Ons
|
2
|
+
|
3
|
+
unoffical aliyun ONS sdk (ruby version)
|
4
|
+
|
5
|
+
## Requirements
|
6
|
+
|
7
|
+
* Linux/Unix
|
8
|
+
* Ruby 2.1.5 or later
|
9
|
+
* Boost C++ library
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
### install Ruby
|
14
|
+
|
15
|
+
```sh
|
16
|
+
$ rvm install 2.1.5
|
17
|
+
```
|
18
|
+
|
19
|
+
### install Boost C++ library
|
20
|
+
|
21
|
+
```sh
|
22
|
+
$ apt-get install libboost-all-dev
|
23
|
+
```
|
24
|
+
|
25
|
+
### install ons
|
26
|
+
|
27
|
+
```sh
|
28
|
+
$ git clone https://github.com/souche/aliyun-ons-ruby-sdk.git
|
29
|
+
$ cd ons
|
30
|
+
$ ./bin/setup
|
31
|
+
$ ./bin/rake install
|
32
|
+
```
|
33
|
+
|
34
|
+
## Usage
|
35
|
+
|
36
|
+
Please take a look at {file:samples/producer.rb} and {file:samples/consumer.rb}
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'ons'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start
|
data/bin/rake
ADDED
data/bin/setup
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
#ifndef __ACTION_H__
|
2
|
+
#define __ACTION_H__
|
3
|
+
|
4
|
+
//consuming result
|
5
|
+
enum Action{
|
6
|
+
//consume success, application could continue to consume next message
|
7
|
+
CommitMessage,
|
8
|
+
//consume fail, server will deliver this message later, application could continue to consume next message
|
9
|
+
ReconsumeLater
|
10
|
+
};
|
11
|
+
#endif
|
12
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
#ifndef __LOCALTRANSACTIONCHECKER_H__
|
2
|
+
#define __LOCALTRANSACTIONCHECKER_H__
|
3
|
+
|
4
|
+
#include "Message.h"
|
5
|
+
#include "TransactionStatus.h"
|
6
|
+
|
7
|
+
namespace ons{
|
8
|
+
class LocalTransactionChecker {
|
9
|
+
public:
|
10
|
+
virtual TransactionStatus check(Message& msg) =0;
|
11
|
+
virtual ~LocalTransactionChecker() {}
|
12
|
+
};
|
13
|
+
}
|
14
|
+
|
15
|
+
#endif
|
16
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
#ifndef __LOCALTRANSACTIONEXECUTER_H__
|
2
|
+
#define __LOCALTRANSACTIONEXECUTER_H__
|
3
|
+
|
4
|
+
#include "Message.h"
|
5
|
+
#include "TransactionStatus.h"
|
6
|
+
|
7
|
+
namespace ons{
|
8
|
+
class LocalTransactionExecuter{
|
9
|
+
public:
|
10
|
+
virtual TransactionStatus execute(Message& msg) =0;
|
11
|
+
virtual ~LocalTransactionExecuter(){}
|
12
|
+
};
|
13
|
+
}
|
14
|
+
|
15
|
+
#endif
|
16
|
+
|
@@ -0,0 +1,96 @@
|
|
1
|
+
#ifndef __MESSAGE_H__
|
2
|
+
#define __MESSAGE_H__
|
3
|
+
|
4
|
+
#include <map>
|
5
|
+
#include <vector>
|
6
|
+
#include <sstream>
|
7
|
+
#include "ONSClient.h"
|
8
|
+
namespace ons {
|
9
|
+
|
10
|
+
class ONSCLIENT_API SystemPropKey
|
11
|
+
{
|
12
|
+
public:
|
13
|
+
SystemPropKey(){}
|
14
|
+
~SystemPropKey(){}
|
15
|
+
static CONSTSTRING TAG;
|
16
|
+
static CONSTSTRING KEY;
|
17
|
+
static CONSTSTRING MSGID;
|
18
|
+
static CONSTSTRING RECONSUMETIMES;
|
19
|
+
static CONSTSTRING STARTDELIVERTIME;
|
20
|
+
};
|
21
|
+
|
22
|
+
//<!***************************************************************************
|
23
|
+
class ONSCLIENT_API Message
|
24
|
+
{
|
25
|
+
public:
|
26
|
+
Message();
|
27
|
+
Message(CONSTSTRING topic, CONSTSTRING tags, CONSTSTRING body);
|
28
|
+
Message(CONSTSTRING topic, CONSTSTRING tags, CONSTSTRING keys, CONSTSTRING body);
|
29
|
+
|
30
|
+
virtual ~Message();
|
31
|
+
|
32
|
+
Message(const Message& other);
|
33
|
+
Message& operator=(const Message& other);
|
34
|
+
|
35
|
+
//userProperties was used to save user specific parameters which doesn't belong to SystemPropKey
|
36
|
+
void putUserProperties(CONSTSTRING key, CONSTSTRING value);
|
37
|
+
CONSTSTRING getUserProperties(CONSTSTRING key) const;
|
38
|
+
void setUserProperties(std::map<std::string, std::string>& userProperty);
|
39
|
+
std::map<std::string, std::string> getUserProperties() const;
|
40
|
+
|
41
|
+
//systemProperties only save parameters defined in SystemPropKey, please do not add other parameters into systemProperties, else it was not saved.
|
42
|
+
void putSystemProperties(CONSTSTRING key,CONSTSTRING value);
|
43
|
+
CONSTSTRING getSystemProperties(CONSTSTRING key) const;
|
44
|
+
void setSystemProperties(std::map<std::string, std::string>& systemProperty);
|
45
|
+
std::map<std::string, std::string> getSystemProperties() const;
|
46
|
+
|
47
|
+
CONSTSTRING getTopic()const;
|
48
|
+
void setTopic(CONSTSTRING topic);
|
49
|
+
|
50
|
+
CONSTSTRING getTag() const;
|
51
|
+
void setTag(CONSTSTRING tags);
|
52
|
+
|
53
|
+
CONSTSTRING getKey() const;
|
54
|
+
void setKey(CONSTSTRING keys);
|
55
|
+
|
56
|
+
CONSTSTRING getMsgID() const;
|
57
|
+
void setMsgID(CONSTSTRING msgId);
|
58
|
+
|
59
|
+
const long long getStartDeliverTime() const;
|
60
|
+
void setStartDeliverTime(long long level);
|
61
|
+
|
62
|
+
CONSTSTRING getBody()const;
|
63
|
+
void setBody(CONSTSTRING msgbody);
|
64
|
+
|
65
|
+
const int getReconsumeTimes() const;
|
66
|
+
void setReconsumeTimes(int reconsumeTimes);
|
67
|
+
|
68
|
+
long long getStoreTimestamp() const;
|
69
|
+
void setStoreTimestamp(long long storeTimestamp);
|
70
|
+
|
71
|
+
const std::string toString() const;
|
72
|
+
|
73
|
+
const std::string toSystemString() const;
|
74
|
+
|
75
|
+
const std::string toUserString() const;
|
76
|
+
|
77
|
+
protected:
|
78
|
+
void Init(const std::string& topic,
|
79
|
+
const std::string& tags,
|
80
|
+
const std::string& keys,
|
81
|
+
const std::string& body);
|
82
|
+
|
83
|
+
|
84
|
+
private:
|
85
|
+
std::string topic;
|
86
|
+
std::string body;
|
87
|
+
long long m_storeTimestamp;
|
88
|
+
std::map<std::string, std::string> systemProperties;
|
89
|
+
std::map<std::string, std::string> userProperties;
|
90
|
+
};
|
91
|
+
//<!***************************************************************************
|
92
|
+
|
93
|
+
|
94
|
+
}//<!end namespace;
|
95
|
+
#endif
|
96
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#ifndef __MESSAGELISTENER_H__
|
2
|
+
#define __MESSAGELISTENER_H__
|
3
|
+
|
4
|
+
#include "Action.h"
|
5
|
+
#include "Message.h"
|
6
|
+
#include "ConsumeContext.h"
|
7
|
+
|
8
|
+
namespace ons{
|
9
|
+
|
10
|
+
class ONSCLIENT_API MessageListener {
|
11
|
+
public:
|
12
|
+
MessageListener(){}
|
13
|
+
virtual ~MessageListener(){}
|
14
|
+
|
15
|
+
//interface of consuming message, should be realized by application
|
16
|
+
virtual Action consume(Message& message, ConsumeContext& context) = 0;
|
17
|
+
};
|
18
|
+
|
19
|
+
}
|
20
|
+
#endif
|
@@ -0,0 +1,28 @@
|
|
1
|
+
/********************************************************************
|
2
|
+
author: ×ÔÐÞ jianlin.yjl@alibaba-cn.com
|
3
|
+
*********************************************************************/
|
4
|
+
#ifndef __ONSCLIENT_H__
|
5
|
+
#define __ONSCLIENT_H__
|
6
|
+
|
7
|
+
#include <string>
|
8
|
+
|
9
|
+
#ifdef WIN32
|
10
|
+
typedef const char* CONSTSTRING;
|
11
|
+
typedef char* STRING;
|
12
|
+
#else
|
13
|
+
typedef const std::string CONSTSTRING;
|
14
|
+
typedef std::string STRING;
|
15
|
+
#endif
|
16
|
+
|
17
|
+
|
18
|
+
#ifdef WIN32
|
19
|
+
#ifdef ONSCLIENT_EXPORTS
|
20
|
+
#define ONSCLIENT_API __declspec(dllexport)
|
21
|
+
#else
|
22
|
+
#define ONSCLIENT_API __declspec(dllimport)
|
23
|
+
#endif
|
24
|
+
#else
|
25
|
+
#define ONSCLIENT_API
|
26
|
+
#endif
|
27
|
+
|
28
|
+
#endif
|
@@ -0,0 +1,27 @@
|
|
1
|
+
#ifndef __ONSCLIENTEXCEPTION_H__
|
2
|
+
#define __ONSCLIENTEXCEPTION_H__
|
3
|
+
|
4
|
+
#include <exception>
|
5
|
+
#include "ONSClient.h"
|
6
|
+
|
7
|
+
namespace ons{
|
8
|
+
|
9
|
+
class ONSCLIENT_API ONSClientException: public std::exception
|
10
|
+
{
|
11
|
+
public:
|
12
|
+
ONSClientException() throw();
|
13
|
+
virtual ~ONSClientException() throw();
|
14
|
+
ONSClientException(std::string msg, int error) throw();
|
15
|
+
const char* GetMsg() const throw();
|
16
|
+
const char* what() const throw();
|
17
|
+
int GetError() const throw();
|
18
|
+
|
19
|
+
private:
|
20
|
+
std::string m_msg;
|
21
|
+
int m_error;
|
22
|
+
};
|
23
|
+
|
24
|
+
}
|
25
|
+
|
26
|
+
|
27
|
+
#endif
|
@@ -0,0 +1,73 @@
|
|
1
|
+
#ifndef __ONSFACTORY_H_
|
2
|
+
#define __ONSFACTORY_H_
|
3
|
+
|
4
|
+
#include "Producer.h"
|
5
|
+
#include "TransactionProducer.h"
|
6
|
+
#include "PushConsumer.h"
|
7
|
+
#include "ONSChannel.h"
|
8
|
+
#include "LocalTransactionChecker.h"
|
9
|
+
|
10
|
+
namespace ons {
|
11
|
+
class ONSCLIENT_API ONSFactoryProperty{
|
12
|
+
public:
|
13
|
+
ONSFactoryProperty();
|
14
|
+
virtual ~ONSFactoryProperty();
|
15
|
+
bool checkValidityOfFactoryProperties(const std::string& key, const std::string& value);
|
16
|
+
void setSendMsgTimeout(const int value);
|
17
|
+
void setOnsChannel(ONSChannel onsChannel);
|
18
|
+
void setFactoryProperty(CONSTSTRING& key, CONSTSTRING value);
|
19
|
+
void setFactoryProperties(std::map<std::string, std::string> factoryProperties);
|
20
|
+
std::map<std::string, std::string> getFactoryProperties() const;
|
21
|
+
CONSTSTRING getProducerId() const;
|
22
|
+
CONSTSTRING getConsumerId() const;
|
23
|
+
CONSTSTRING getPublishTopics() const;
|
24
|
+
CONSTSTRING getMessageModel() const;
|
25
|
+
const int getMessageTimeout() const;
|
26
|
+
const int getConsumeThreadNums() const;
|
27
|
+
const ONSChannel getOnsChannel() const;
|
28
|
+
CONSTSTRING getChannel() const;
|
29
|
+
CONSTSTRING getMessageContent() const;
|
30
|
+
CONSTSTRING getNameSrvAddr() const;
|
31
|
+
CONSTSTRING getNameSrvDomain() const;
|
32
|
+
CONSTSTRING getAccessKey() const;
|
33
|
+
CONSTSTRING getSecretKey() const;
|
34
|
+
public:
|
35
|
+
static CONSTSTRING ProducerId;
|
36
|
+
static CONSTSTRING ConsumerId;
|
37
|
+
static CONSTSTRING PublishTopics;
|
38
|
+
static CONSTSTRING MsgContent;
|
39
|
+
static CONSTSTRING ONSAddr;
|
40
|
+
static CONSTSTRING AccessKey;
|
41
|
+
static CONSTSTRING SecretKey;
|
42
|
+
static CONSTSTRING MessageModel;
|
43
|
+
static CONSTSTRING BROADCASTING;
|
44
|
+
static CONSTSTRING CLUSTERING;
|
45
|
+
static CONSTSTRING SendMsgTimeoutMillis;
|
46
|
+
static CONSTSTRING NAMESRV_ADDR;
|
47
|
+
static CONSTSTRING ConsumeThreadNums;
|
48
|
+
static CONSTSTRING OnsChannel;
|
49
|
+
private:
|
50
|
+
std::map<std::string, std::string> m_onsFactoryProperties;
|
51
|
+
};
|
52
|
+
|
53
|
+
class ONSCLIENT_API ONSFactoryAPI{
|
54
|
+
public:
|
55
|
+
ONSFactoryAPI();
|
56
|
+
virtual ~ONSFactoryAPI();
|
57
|
+
|
58
|
+
virtual Producer* createProducer(ONSFactoryProperty factoryProperty);
|
59
|
+
virtual TransactionProducer* createTransactionProducer(ONSFactoryProperty factoryProperty, LocalTransactionChecker *checker);
|
60
|
+
virtual PushConsumer* createPushConsumer(ONSFactoryProperty factoryProperty);
|
61
|
+
};
|
62
|
+
|
63
|
+
class ONSCLIENT_API ONSFactory{
|
64
|
+
public:
|
65
|
+
virtual ~ONSFactory();
|
66
|
+
static ONSFactoryAPI* getInstance();
|
67
|
+
private:
|
68
|
+
ONSFactory();
|
69
|
+
static ONSFactoryAPI *onsFactoryInstance;
|
70
|
+
};
|
71
|
+
}
|
72
|
+
#endif
|
73
|
+
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#ifndef __PRODUCER_H__
|
2
|
+
#define __PRODUCER_H__
|
3
|
+
|
4
|
+
|
5
|
+
#include "SendResultONS.h"
|
6
|
+
#include "Message.h"
|
7
|
+
|
8
|
+
|
9
|
+
namespace ons {
|
10
|
+
|
11
|
+
class ONSCLIENT_API Producer{
|
12
|
+
|
13
|
+
public:
|
14
|
+
|
15
|
+
Producer(){}
|
16
|
+
virtual ~Producer(){}
|
17
|
+
|
18
|
+
//before send msg, start must be called to allocate resources.
|
19
|
+
virtual void start()=0;
|
20
|
+
//before exit ons, shutdown must be called to release all resources allocated by ons internally.
|
21
|
+
virtual void shutdown()=0;
|
22
|
+
//retry max 3 times if send failed. if no exception throwed, it sends success;
|
23
|
+
virtual SendResultONS send(Message& msg)=0;
|
24
|
+
|
25
|
+
};
|
26
|
+
|
27
|
+
}
|
28
|
+
#endif
|
29
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
#ifndef __PUSHCONSUMER_H__
|
2
|
+
#define __PUSHCONSUMER_H__
|
3
|
+
|
4
|
+
#include "MessageListener.h"
|
5
|
+
|
6
|
+
namespace ons {
|
7
|
+
|
8
|
+
class ONSCLIENT_API PushConsumer{
|
9
|
+
|
10
|
+
public:
|
11
|
+
PushConsumer(){}
|
12
|
+
virtual ~PushConsumer(){}
|
13
|
+
|
14
|
+
virtual void start()=0;
|
15
|
+
virtual void shutdown()=0;
|
16
|
+
virtual void subscribe(CONSTSTRING topic, CONSTSTRING subExpression, MessageListener* listener)=0;
|
17
|
+
//virtual void setNamesrvAddr(const std::string& nameSrvAddr) = 0;
|
18
|
+
};
|
19
|
+
|
20
|
+
}
|
21
|
+
#endif
|
22
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
#ifndef __SENDRESULTONS_H__
|
2
|
+
#define __SENDRESULTONS_H__
|
3
|
+
|
4
|
+
#include "ONSClient.h"
|
5
|
+
|
6
|
+
namespace ons{
|
7
|
+
|
8
|
+
class ONSCLIENT_API SendResultONS{
|
9
|
+
public:
|
10
|
+
SendResultONS();
|
11
|
+
virtual ~SendResultONS();
|
12
|
+
void setMessageId(const std::string& msgId);
|
13
|
+
CONSTSTRING getMessageId() const;
|
14
|
+
|
15
|
+
|
16
|
+
private:
|
17
|
+
std::string messageId;
|
18
|
+
|
19
|
+
};
|
20
|
+
|
21
|
+
}
|
22
|
+
#endif
|
@@ -0,0 +1,22 @@
|
|
1
|
+
#ifndef __TRANSACTIONPRODUCER_H__
|
2
|
+
#define __TRANSACTIONPRODUCER_H__
|
3
|
+
|
4
|
+
#include "LocalTransactionExecuter.h"
|
5
|
+
|
6
|
+
namespace ons{
|
7
|
+
class TransactionProducer{
|
8
|
+
public:
|
9
|
+
TransactionProducer(){}
|
10
|
+
virtual ~TransactionProducer(){}
|
11
|
+
|
12
|
+
//before send msg, start must be called to allocate resources.
|
13
|
+
virtual void start()=0;
|
14
|
+
//before exit ons, shutdown must be called to release all resources allocated by ons internally.
|
15
|
+
virtual void shutdown()=0;
|
16
|
+
//retry max 3 times if send failed. if no exception throwed, it sends success;
|
17
|
+
virtual SendResultONS send(Message& msg, LocalTransactionExecuter *executer)=0;
|
18
|
+
};
|
19
|
+
}
|
20
|
+
|
21
|
+
#endif
|
22
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
#ifndef __TRANSACTIONSTATUS_H__
|
2
|
+
#define __TRANSACTIONSTATUS_H__
|
3
|
+
|
4
|
+
namespace ons {
|
5
|
+
|
6
|
+
enum TransactionStatus {
|
7
|
+
CommitTransaction=0,//Ìá½»ÊÂÎñ
|
8
|
+
RollbackTransaction=1,//»Ø¹öÊÂÎñ
|
9
|
+
Unknow=2,//δ֪״̬£¬Ò»°ãÔÚÓû§ÎÞ·¨È·¶¨ÊÂÎñÊdzɹ¦»¹ÊÇʧ°ÜʱʹÓÃ
|
10
|
+
};
|
11
|
+
|
12
|
+
|
13
|
+
}
|
14
|
+
|
15
|
+
#endif
|
Binary file
|