forked from apache/rocketmq-client-cpp
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMQClientImpl.cpp
More file actions
102 lines (83 loc) · 3.49 KB
/
Copy pathMQClientImpl.cpp
File metadata and controls
102 lines (83 loc) · 3.49 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
/*
* 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 "MQClientImpl.h"
#include "Logging.h"
#include "MQAdminImpl.h"
#include "MQClientManager.h"
#include "TopicPublishInfo.hpp"
#include "UtilAll.h"
namespace rocketmq {
#define ROCKETMQCPP_VERSION "3.0.0"
#define BUILD_DATE __DATE__ " " __TIME__
// display version: strings bin/librocketmq.so |grep VERSION
const char* rocketmq_build_time = "VERSION: " ROCKETMQCPP_VERSION ", BUILD DATE: " BUILD_DATE;
void MQClientImpl::start() {
if (nullptr == client_instance_) {
if (nullptr == client_config_) {
THROW_MQEXCEPTION(MQClientException, "have not clientConfig for create clientInstance.", -1);
}
client_instance_ = MQClientManager::getInstance()->getOrCreateMQClientInstance(*client_config_, rpc_hook_);
}
LOG_INFO_NEW("MQClientImpl start, clientId:{}, real nameservAddr:{}", client_instance_->GetClientId(),
client_instance_->GetNamesrvAddress());
}
void MQClientImpl::shutdown() {
client_instance_ = nullptr;
}
void MQClientImpl::createTopic(const std::string& key, const std::string& newTopic, int queueNum) {
try {
client_instance_->GetMQAdminImpl()->createTopic(key, newTopic, queueNum);
} catch (MQException& e) {
LOG_ERROR(e.what());
}
}
int64_t MQClientImpl::searchOffset(const MessageQueue& mq, int64_t timestamp) {
return client_instance_->GetMQAdminImpl()->searchOffset(mq, timestamp);
}
int64_t MQClientImpl::maxOffset(const MessageQueue& mq) {
return client_instance_->GetMQAdminImpl()->maxOffset(mq);
}
int64_t MQClientImpl::minOffset(const MessageQueue& mq) {
return client_instance_->GetMQAdminImpl()->minOffset(mq);
}
int64_t MQClientImpl::earliestMsgStoreTime(const MessageQueue& mq) {
return client_instance_->GetMQAdminImpl()->earliestMsgStoreTime(mq);
}
MQMessageExt MQClientImpl::viewMessage(const std::string& msgId) {
return client_instance_->GetMQAdminImpl()->viewMessage(msgId);
}
QueryResult MQClientImpl::queryMessage(const std::string& topic,
const std::string& key,
int maxNum,
int64_t begin,
int64_t end) {
return client_instance_->GetMQAdminImpl()->queryMessage(topic, key, maxNum, begin, end);
}
bool MQClientImpl::isServiceStateOk() {
return service_state_ == ServiceState::kRunning;
}
MQClientInstancePtr MQClientImpl::getClientInstance() const {
return client_instance_;
}
void MQClientImpl::setClientInstance(MQClientInstancePtr clientInstance) {
if (service_state_ == ServiceState::kCreateJust) {
client_instance_ = clientInstance;
} else {
THROW_MQEXCEPTION(MQClientException, "Client already start, can not reset clientInstance!", -1);
}
}
} // namespace rocketmq