38 const std::string& clientId,
39 std::uint8_t qoSDefault,
40 std::uint16_t keepAlive,
42 const std::string& willTopic,
43 const std::string& willMessage,
46 const std::string& username,
47 const std::string& password,
48 const std::list<std::string>& subTopics,
50 const std::string& rawTable,
51 bool autoCreateRawTable,
53 const std::string& sessionStoreFileName)
54 : iot::
mqtt::client::Mqtt(connectionName, clientId, keepAlive, sessionStoreFileName)
65 VLOG(1) <<
"MQTTStore client id: " << clientId;
66 VLOG(1) <<
" Keep Alive: " << keepAlive;
67 VLOG(1) <<
" Clean Session: " << cleanSession;
68 VLOG(1) <<
" Will Topic: " << willTopic;
69 VLOG(1) <<
" Will QoS: " <<
static_cast<std::uint16_t>(willQoS);
70 VLOG(1) <<
" Will Retain: " << willRetain;
71 VLOG(1) <<
" Username configured: " << (!username.empty());
98 if (connack.getReturnCode() != 0) {
99 VLOG(0) << connectionName <<
" MQTTStore: broker rejected connection with return code "
100 <<
static_cast<
int>(connack.getReturnCode());
105 if (subTopics.empty()) {
106 VLOG(0) << connectionName <<
" MQTTStore: no subscriptions configured";
112 std::list<iot::mqtt::Topic> topicList;
113 std::transform(subTopics.begin(),
115 std::back_inserter(topicList),
116 [qoSDefault =
this->qoSDefault](
const std::string& compositeTopic) {
117 const std::size_t pos = compositeTopic.rfind(
"##");
118 const std::string topic = compositeTopic.substr(0, pos);
119 std::uint8_t qoS = qoSDefault;
121 if (pos != std::string::npos) {
122 qoS =
getQos(compositeTopic.substr(pos + 2)
);
125 VLOG(0) <<
"MQTTStore subscribe: QoS " <<
static_cast<
int>(qoS) <<
" | " << topic;
126 return iot::mqtt::Topic(topic, qoS);
129 sendSubscribe(topicList);
130 }
catch (
const std::logic_error& error) {
131 VLOG(0) << connectionName <<
" MQTTStore subscription failed: " << error.what();
137 VLOG(1) << connectionName <<
" MQTTStore received publish: topic='" << publish.getTopic()
138 <<
"' qos=" <<
static_cast<std::uint16_t>(publish.getQoS()) <<
" retain=" << (publish.getRetain() != 0)
139 <<
" dup=" << (publish.getDup() != 0);
141 storage.store({.connectionName = connectionName,
142 .topic = publish.getTopic(),
143 .payload = publish.getMessage(),
144 .qoS = publish.getQoS(),
145 .retain = publish.getRetain() != 0,
146 .dup = publish.getDup() != 0,
147 .packetIdentifier = publish.getPacketIdentifier()});
Mqtt(const std::string &connectionName, const std::string &clientId, std::uint8_t qoSDefault, std::uint16_t keepAlive, bool cleanSession, const std::string &willTopic, const std::string &willMessage, std::uint8_t willQoS, bool willRetain, const std::string &username, const std::string &password, const std::list< std::string > &subTopics, MariaDbStorage::ConnectionConfig connectionConfig, const std::string &rawTable, bool autoCreateRawTable, StoragePlan storagePlan, const std::string &sessionStoreFileName="")