Repository navigation
Expand file tree
/
Copy pathMQMessage.cpp
More file actions
executable file
·197 lines (158 loc) · 5.51 KB
/
Copy pathMQMessage.cpp
File metadata and controls
executable file
·197 lines (158 loc) · 5.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/*
* 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.
*/
#include "MQMessage.h"
#include "UtilAll.h"
namespace rocketmq {
//<!***************************************************************************
const string MQMessage::PROPERTY_KEYS = "KEYS";
const string MQMessage::PROPERTY_TAGS = "TAGS";
const string MQMessage::PROPERTY_WAIT_STORE_MSG_OK = "WAIT";
const string MQMessage::PROPERTY_DELAY_TIME_LEVEL = "DELAY";
const string MQMessage::PROPERTY_RETRY_TOPIC = "RETRY_TOPIC";
const string MQMessage::PROPERTY_REAL_TOPIC = "REAL_TOPIC";
const string MQMessage::PROPERTY_REAL_QUEUE_ID = "REAL_QID";
const string MQMessage::PROPERTY_TRANSACTION_PREPARED = "TRAN_MSG";
const string MQMessage::PROPERTY_PRODUCER_GROUP = "PGROUP";
const string MQMessage::PROPERTY_MIN_OFFSET = "MIN_OFFSET";
const string MQMessage::PROPERTY_MAX_OFFSET = "MAX_OFFSET";
const string MQMessage::KEY_SEPARATOR = " ";
//<!************************************************************************
MQMessage::MQMessage() { Init("", "", "", 0, "", true); }
MQMessage::MQMessage(const string& topic, const string& body) {
Init(topic, "", "", 0, body, true);
}
MQMessage::MQMessage(const string& topic, const string& tags,
const string& body) {
Init(topic, tags, "", 0, body, true);
}
MQMessage::MQMessage(const string& topic, const string& tags,
const string& keys, const string& body) {
Init(topic, tags, keys, 0, body, true);
}
MQMessage::MQMessage(const string& topic, const string& tags,
const string& keys, const int flag, const string& body,
bool waitStoreMsgOK) {
Init(topic, tags, keys, flag, body, waitStoreMsgOK);
}
MQMessage::~MQMessage() { m_properties.clear(); }
MQMessage::MQMessage(const MQMessage& other) {
m_body = other.m_body;
m_topic = other.m_topic;
m_flag = other.m_flag;
m_properties = other.m_properties;
}
MQMessage& MQMessage::operator=(const MQMessage& other) {
if (this != &other) {
m_body = other.m_body;
m_topic = other.m_topic;
m_flag = other.m_flag;
m_properties = other.m_properties;
}
return *this;
}
void MQMessage::setProperty(const string& name, const string& value) {
m_properties[name] = value;
}
string MQMessage::getProperty(const string& name) const {
map<string, string>::const_iterator it = m_properties.find(name);
return (it == m_properties.end()) ? "" : (*it).second;
}
string MQMessage::getTopic() const { return m_topic; }
void MQMessage::setTopic(const string& topic) { m_topic = topic; }
void MQMessage::setTopic(const char* body, int len) {
m_topic.clear();
m_topic.append(body, len);
}
string MQMessage::getTags() const { return getProperty(PROPERTY_TAGS); }
void MQMessage::setTags(const string& tags) {
setProperty(PROPERTY_TAGS, tags);
}
string MQMessage::getKeys() const { return getProperty(PROPERTY_KEYS); }
void MQMessage::setKeys(const string& keys) {
setProperty(PROPERTY_KEYS, keys);
}
void MQMessage::setKeys(const vector<string>& keys) {
if (keys.empty()) {
return;
}
vector<string>::const_iterator it = keys.begin();
string str;
str += *it;
it++;
for (; it != keys.end(); it++) {
str += KEY_SEPARATOR;
str += *it;
}
setKeys(str);
}
int MQMessage::getDelayTimeLevel() const {
string tmp = getProperty(PROPERTY_DELAY_TIME_LEVEL);
if (!tmp.empty()) {
return atoi(tmp.c_str());
}
return 0;
}
void MQMessage::setDelayTimeLevel(int level) {
char tmp[16];
sprintf(tmp, "%d", level);
setProperty(PROPERTY_DELAY_TIME_LEVEL, tmp);
}
bool MQMessage::isWaitStoreMsgOK() {
string tmp = getProperty(PROPERTY_WAIT_STORE_MSG_OK);
if (tmp.empty()) {
return true;
} else {
return (tmp == "true") ? true : false;
}
}
void MQMessage::setWaitStoreMsgOK(bool waitStoreMsgOK) {
if (waitStoreMsgOK) {
setProperty(PROPERTY_WAIT_STORE_MSG_OK, "true");
} else {
setProperty(PROPERTY_WAIT_STORE_MSG_OK, "false");
}
}
int MQMessage::getFlag() const { return m_flag; }
void MQMessage::setFlag(int flag) { m_flag = flag; }
string MQMessage::getBody() const { return m_body; }
void MQMessage::setBody(const char* body, int len) {
m_body.clear();
m_body.append(body, len);
}
void MQMessage::setBody(const string &body) {
m_body.clear();
m_body.append(body);
}
map<string, string> MQMessage::getProperties() const { return m_properties; }
void MQMessage::setProperties(map<string, string>& properties) {
m_properties = properties;
}
void MQMessage::Init(const string& topic, const string& tags,
const string& keys, const int flag, const string& body,
bool waitStoreMsgOK) {
m_topic = topic;
m_flag = flag;
m_body = body;
if (tags.length() > 0) {
setTags(tags);
}
if (keys.length() > 0) {
setKeys(keys);
}
setWaitStoreMsgOK(waitStoreMsgOK);
}
} //<!end namespace;