-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpitcher.go
46 lines (35 loc) · 1.38 KB
/
pitcher.go
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
/*
Copyright © 2024 Patrick Hermann patrick.hermann@sva.de
*/
package homerun
import (
"context"
"github.com/nitishm/go-rejson/v4"
"github.com/nitishm/go-rejson/v4/clients"
"github.com/pterm/pterm"
sthingsCli "github.com/stuttgart-things/sthingsCli"
)
var (
logger = pterm.DefaultLogger.WithLevel(pterm.LogLevelTrace)
)
func EnqueueMessageInRedisStreams(msg Message, redisConnection map[string]string) (objectID, streamID string) {
var redisJSONHandler = rejson.NewReJSONHandler()
var redisClient = sthingsCli.CreateRedisClient(redisConnection["addr"]+":"+redisConnection["port"], redisConnection["password"])
var conn clients.GoRedisClientConn = redisClient
redisJSONHandler.SetGoRedisClientWithContext(context.Background(), conn)
// SET TO REDIS JSON
objectID = GenerateUUID() + "-" + msg.System
sthingsCli.SetRedisJSON(redisJSONHandler, msg, objectID)
// SET TO REDIS STREAMS
streamID = redisConnection["stream"]
streamValues := map[string]interface{}{
"messageID": objectID,
}
enqueue := sthingsCli.EnqueueDataInRedisStreams(redisConnection["addr"]+":"+redisConnection["port"], redisConnection["password"], streamID, streamValues)
if enqueue {
logger.Info("MESSAGE WAS ENQUEUED IN REDIS STREAMS", logger.Args(streamID, streamValues))
} else {
logger.Error("MESSAGE WAS NOT ENQUEUED IN REDIS STREAMS", logger.Args(streamID, streamValues))
}
return objectID, streamID
}