partly works
This commit is contained in:
parent
c659a89ec3
commit
eea7c5c95b
16
config-test.json
Normal file
16
config-test.json
Normal file
@ -0,0 +1,16 @@
|
||||
{
|
||||
"mqtt": {
|
||||
"broker": "mqtt://172.23.1.102:1883",
|
||||
"username": "archiver",
|
||||
"tlsEnable": "true"
|
||||
},
|
||||
"includeTopics": [
|
||||
"#"
|
||||
],
|
||||
"excludeTopics": [
|
||||
"IoT/Watchdog",
|
||||
"snmp",
|
||||
"MainsCnt/#",
|
||||
"cem/#"
|
||||
]
|
||||
}
|
13
deployment/config.json
Normal file
13
deployment/config.json
Normal file
@ -0,0 +1,13 @@
|
||||
{
|
||||
"mqtt": {
|
||||
"broker": "mqtt://emqx01-anonymous-cluster-internal.broker.svc.cluster.local:1883",
|
||||
"tlsEnable": "false"
|
||||
},
|
||||
"includeTopics": [
|
||||
"#"
|
||||
],
|
||||
"includeTopics": [
|
||||
"mainscnt/#"
|
||||
"cem/#"
|
||||
]
|
||||
}
|
@ -26,7 +26,7 @@ func InputArchiver() {
|
||||
}
|
||||
|
||||
func handleMessage(message database.Message) {
|
||||
log.Printf("Archiving %", message)
|
||||
log.Printf("Archiving Timestamp: %s, Topic: %s, Payload: %s", message.Time, message.Topic, message.Payload)
|
||||
counter.S("Stored")
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,7 @@ import "ma/counter"
|
||||
type Message struct {
|
||||
Topic string
|
||||
Payload []byte
|
||||
Retained bool
|
||||
}
|
||||
|
||||
var InputChannel chan Message = make(chan Message, 100)
|
||||
@ -20,24 +21,30 @@ var OutputChannel chan Message = make(chan Message, 100)
|
||||
var mqttClient MQTT.Client
|
||||
|
||||
func onMessageReceived(client MQTT.Client, message MQTT.Message) {
|
||||
// log.Printf("Message received, topic: %s, payload: %s\n", message.Topic(), message.Payload())
|
||||
//log.Printf("Message received, topic: %s, payload: %s\n", message.Topic(), message.Payload())
|
||||
m := Message {
|
||||
Topic: message.Topic(),
|
||||
Payload: message.Payload(),
|
||||
Retained: message.Retained(),
|
||||
}
|
||||
if m.Retained {
|
||||
counter.S("Skipped")
|
||||
//log.Println("Retained message skipped")
|
||||
return
|
||||
}
|
||||
for _, i := range config.Config.ExcludeTopics {
|
||||
if i == m.Topic {
|
||||
if TopicMatchesSubscription(m.Topic, i) {
|
||||
counter.S("Skipped")
|
||||
log.Println("Message skipped")
|
||||
//log.Println("Message skipped")
|
||||
return
|
||||
}
|
||||
}
|
||||
select {
|
||||
case InputChannel <- m:
|
||||
counter.S("Received")
|
||||
log.Println("Message sent to channel")
|
||||
//log.Println("Message sent to channel")
|
||||
default:
|
||||
log.Println("Channel full, message lost")
|
||||
//log.Println("Channel full, message lost")
|
||||
counter.F("Received")
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user