-
Notifications
You must be signed in to change notification settings - Fork 12
/
kafka_consumer_msgs.go
executable file
·60 lines (47 loc) · 1.19 KB
/
kafka_consumer_msgs.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright [2021] - [2022], AssetMantle Pte. Ltd. and the code contributors
// SPDX-License-Identifier: Apache-2.0
package queuing
import (
"time"
"github.com/cosmos/cosmos-sdk/client"
)
// kafkaConsumerMessages : messages to consume 5-second delay
func kafkaConsumerMessages(context client.Context) {
quit := make(chan bool)
var kafkaMsgList []kafkaMsg
go func() {
var msg kafkaMsg
for {
select {
case <-quit:
return
default:
msg = kafkaTopicConsumer("Topic", KafkaState.Consumers, context.LegacyAmino)
if msg.Msg != nil {
kafkaMsgList = append(kafkaMsgList, msg)
}
}
}
}()
time.Sleep(sleepTimer)
quit <- true
if len(kafkaMsgList) == 0 {
return
}
output, err := signAndBroadcastMultiple(kafkaMsgList, context)
if err != nil {
jsonError, e := context.LegacyAmino.MarshalJSON(struct {
Error string `json:"error"`
}{Error: err.Error()})
if e != nil {
panic(e)
}
for _, kafkaMsg := range kafkaMsgList {
addResponseToDB(kafkaMsg.TicketID, jsonError, KafkaState.KafkaDB, context.LegacyAmino)
}
return
}
for _, kafkaMsg := range kafkaMsgList {
addResponseToDB(kafkaMsg.TicketID, output, KafkaState.KafkaDB, context.LegacyAmino)
}
}