Skip to content

Commit 46ac583

Browse files
committed
Add cleanMqttRetain
1 parent d08f07f commit 46ac583

File tree

7 files changed

+40
-10
lines changed

7 files changed

+40
-10
lines changed

src/lib/common/string.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,7 @@ bool parseKafkaBrokerList(const std::string& url, std::string* cleanListOut, st
536536
/* Minimum path is always "/" */
537537
*path = "/";
538538
}
539+
539540
size_t slashPos = rawBroker.find('/');
540541
if (slashPos != std::string::npos)
541542
{

src/lib/mongoBackend/MongoCommonUpdate.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2121,11 +2121,17 @@ static unsigned int processSubscriptions
21212121
notification.httpInfo.fill(tSubP->httpInfo);
21222122
notification.mqttInfo.fill(tSubP->mqttInfo);
21232123
notification.kafkaInfo.fill(tSubP->kafkaInfo);
2124-
notification.type = (
2125-
notification.mqttInfo.topic.empty() ?
2126-
(notification.kafkaInfo.topic.empty() ? ngsiv2::HttpNotification : ngsiv2::KafkaNotification)
2127-
: ngsiv2::MqttNotification
2128-
);
2124+
2125+
if (!notification.mqttInfo.topic.empty())
2126+
{
2127+
notification.type = ngsiv2::MqttNotification;
2128+
} else if (!notification.kafkaInfo.topic.empty())
2129+
{
2130+
notification.type = ngsiv2::KafkaNotification;
2131+
} else
2132+
{
2133+
notification.type = ngsiv2::HttpNotification;
2134+
}
21292135

21302136
notificationSent = processNotification(notifyCerP,
21312137
tSubP->attrL,

src/lib/mongoBackend/dbConstants.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@
130130
#define CSUB_MQTTQOS "qos"
131131
#define CSUB_MQTTRETAIN "retain"
132132

133-
#define CSUB_KAFKATOPIC "kafka_topic"
133+
#define CSUB_KAFKATOPIC "kafkaTopic"
134134

135135
#define CSUB_USER "user"
136136
#define CSUB_PASSWD "passwd"

src/lib/mongoBackend/mongoSubCache.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,9 @@ int mongoSubCacheItemInsert(const char* tenant, const orion::BSONObj& sub)
140140
if (sub.hasField(CSUB_MQTTTOPIC))
141141
{
142142
cSubP->mqttInfo.fill(sub);
143-
} else
144-
if (sub.hasField(CSUB_KAFKATOPIC)){
143+
}
144+
else if (sub.hasField(CSUB_KAFKATOPIC))
145+
{
145146
cSubP->kafkaInfo.fill(sub);
146147
}
147148
else

test/functionalTest/cases/4388_mqtt_retain/mqttCustom_retain_true.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ MQTT message at topic orion/retain/custom:
178178

179179

180180
--TEARDOWN--
181-
mosquitto_pub -h mosquitto -p 1883 -t 'orion/retain/custom' -n -r
181+
cleanMqttRetain mosquitto 'orion/retain/custom' 1883
182182
brokerStop CB
183183
dbDrop CB
184184
accumulatorStop

test/functionalTest/cases/4388_mqtt_retain/mqtt_retain_true.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ MQTT message at topic orion/retain:
178178

179179

180180
--TEARDOWN--
181-
mosquitto_pub -h mosquitto -p 1883 -t 'orion/retain' -n -r
181+
cleanMqttRetain mosquitto 'orion/retain' 1883
182182
brokerStop CB
183183
dbDrop CB
184184
accumulatorStop

test/functionalTest/harnessFunctions.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,6 +1221,27 @@ kafkaDestroyTopics() {
12211221
done
12221222
}
12231223

1224+
1225+
1226+
# ------------------------------------------------------------------------------
1227+
#
1228+
# cleanMqttRetain -
1229+
#
1230+
# Delete retained topics by posting an empty message in the topic.
1231+
cleanMqttRetain() {
1232+
local host="$1"
1233+
local topic="$2"
1234+
local port="${3:-1883}"
1235+
1236+
if [[ -z "$host" || -z "$topic" ]]; then
1237+
echo "Uso: mqtt_retain_empty <host> <topic> [puerto]" >&2
1238+
return 1
1239+
fi
1240+
1241+
mosquitto_pub -h "$host" -p "$port" -t "$topic" -n -r
1242+
}
1243+
1244+
12241245
# ------------------------------------------------------------------------------
12251246
#
12261247
# orionCurl
@@ -1492,3 +1513,4 @@ export -f brokerStartAwait
14921513
export -f brokerStopAwait
14931514
export -f kafkaCreateTopics
14941515
export -f kafkaDestroyTopics
1516+
export -f cleanMqttRetain

0 commit comments

Comments
 (0)