-
Notifications
You must be signed in to change notification settings - Fork 0
/
sender.go
55 lines (43 loc) · 1.07 KB
/
sender.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
package main
import (
"SimpleGoEventProcessingExample/internal"
"SimpleGoEventProcessingExample/types"
"context"
"fmt"
"math/rand"
"time"
)
func main() {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
defer cancel()
server := &types.Server{
Rdb: internal.NewRedisClient("localhost:6379", "", 0),
Ctx: ctx,
Conn: internal.NewRabbitConnection(),
QueueName: "person_created",
}
defer server.Conn.Close()
defer server.Rdb.Close()
internal.PingOrPanic(server)
ch, err := server.Conn.Channel()
internal.HandleError(err, "Error creating RabbitMQ channel")
defer ch.Close()
queue, err := ch.QueueDeclare(
server.QueueName,
false,
false,
false,
false,
nil)
internal.HandleError(err, "Failed to declare a queue")
for i := 0; i <= 10; i++ {
person := types.Person{
ID: internal.NewUUID(),
Name: fmt.Sprintf("Person %s", internal.NewUUID()),
Age: rand.Intn(100),
}
internal.SavePerson(server, &person)
internal.PublishPerson(server, person.ID, ch, queue)
time.Sleep(1 * time.Second)
}
}