feat(reflector): require MQTT_NAME when twin-mode + MQTT both enabled
Two twin reflectors sharing a broker need disjoint MQTT subtrees; MQTT_NAME is the per-reflector path component. Failing fast at startup is better than silent retained-topic corruption when the operator forgets to set it.
This commit is contained in:
1 parent
f4bc684d7b
commit
83bbfc4fab
2 files changed
+28
-1
No files matched your search
@@ -535,6 +535,29 @@ bool Reflector::initialize(Async::Config &cfg)
|
|||||||
initTrunkLinks();
|
initTrunkLinks();
|
||||||
initTrunkServer();
|
initTrunkServer();
|
||||||
initTwinLink();
|
initTwinLink();
|
||||||
|
|
||||||
|
// Twin reflectors sharing a broker need disjoint MQTT subtrees;
|
||||||
|
// MQTT_NAME is the per-reflector path component. Fail fast at startup
|
||||||
|
// when the combination is unsafe.
|
||||||
|
{
|
||||||
|
std::string mqtt_topic_prefix;
|
||||||
|
const bool has_mqtt = m_cfg->getValue("MQTT", "TOPIC_PREFIX", mqtt_topic_prefix)
|
||||||
|
&& !mqtt_topic_prefix.empty();
|
||||||
|
if (m_twin_link != nullptr && has_mqtt)
|
||||||
|
{
|
||||||
|
std::string mqtt_name;
|
||||||
|
m_cfg->getValue("MQTT", "MQTT_NAME", mqtt_name);
|
||||||
|
if (mqtt_name.empty())
|
||||||
|
{
|
||||||
|
geulog::error("core",
|
||||||
|
"[MQTT] MQTT_NAME is required when [TWIN] is configured "
|
||||||
|
"(prevents retained-topic collision when twins share a broker). "
|
||||||
|
"Aborting startup.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
initTwinServer();
|
initTwinServer();
|
||||||
initSatelliteServer();
|
initSatelliteServer();
|
||||||
|
|
||||||
|
|||||||
@@ -417,8 +417,12 @@ def generate_twin_reflector_conf(name: str) -> str:
|
|||||||
f"PASSWORD={T.MQTT['password']}",
|
f"PASSWORD={T.MQTT['password']}",
|
||||||
f"TOPIC_PREFIX=svxreflector/{name}",
|
f"TOPIC_PREFIX=svxreflector/{name}",
|
||||||
"STATUS_INTERVAL=1000",
|
"STATUS_INTERVAL=1000",
|
||||||
"",
|
|
||||||
]
|
]
|
||||||
|
# Twin pair members must have MQTT_NAME to avoid retained-topic collision
|
||||||
|
# when both reflectors share the same broker (enforced by Reflector::initialize).
|
||||||
|
if r.get("twin_of"):
|
||||||
|
lines.append(f"MQTT_NAME={name}")
|
||||||
|
lines.append("")
|
||||||
|
|
||||||
if r.get("redis"):
|
if r.get("redis"):
|
||||||
lines += [
|
lines += [
|
||||||
|
|||||||
Reference in new issue
Block a user