-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
67 lines (58 loc) · 2.27 KB
/
main.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
61
62
63
64
65
66
67
package main
import (
"math/rand/v2"
"strings"
"github.com/cohen990/exactlyOnce/brokering"
"github.com/cohen990/exactlyOnce/chaos"
"github.com/cohen990/exactlyOnce/logging"
"github.com/cohen990/exactlyOnce/publishing"
"github.com/cohen990/exactlyOnce/subscribing"
"github.com/tjarratt/babble"
)
func main() {
logger := logging.NewRoot("exactlyOnce").Child("main")
broker := brokering.Broker{}
subscriber := subscribing.Subscriber{}
publisher := publishing.Publisher{}
subscriber.Initialise()
subscriber.Start()
broker.Initialise()
publisher.Initialise()
broker.Start()
broker.RegisterSubscriber(subscriber.Url)
outage := brokering.NewBrokerOutage(&broker)
chaos := chaos.Chaos[chaos.Action[publishing.PublishStatus], publishing.PublishStatus]{}
chaos.Register(outage)
messageCount := rand.IntN(30)
// messageCount := 3
babbler := babble.NewBabbler()
babbler.Count = messageCount
babbler.Separator = ","
messages := strings.Split(babbler.Babble(), ",")
retries := []string{}
for len(messages) > 0 {
logger.Info("=============New run=============")
logger.Info("Publishing %d messages", len(messages))
for _, message := range messages {
result := chaos.InjectChaos(func() publishing.PublishStatus { return publisher.Publish(broker.Url, message) })
if result != publishing.Published {
retries = append(retries, message)
}
}
logger.Info("Retrying %d messages", len(retries))
messages = retries
retries = []string{}
logger.Info("Retries reset: %d", len(retries))
}
broker.Process()
logger.Info("============================")
logger.Info("Publishing %d messages, completed.", messageCount)
logger.Info("Publisher failed to enqueue messages %d times.", publisher.EnqueueFailedCount)
logger.Info("Publisher enqueued %d messages.", publisher.EnqueuedCount)
logger.Info("Broker failed to send messages %d times.", broker.SendFailedCount)
logger.Info("Broker sent %d messages.", broker.SentCount)
logger.Info("Subscriber failed to receive messages %d times.", subscriber.ReceiveFailedCount)
logger.Info("Subscriber received %d messages.", subscriber.ReceivedCount)
logger.Info("Queued %d messages. Sent %d messages in total.", messageCount, broker.TotalSentCount)
logger.Info("Exactly once delivery achieved?: %t", messageCount == broker.TotalSentCount)
}