feat: make kafka write in another gorutine
This commit is contained in:
parent
2118e0fb86
commit
2a3ee97dc3
8
main.go
8
main.go
@ -267,7 +267,6 @@ func main() {
|
|||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
is_anon := gofakeit.IntN(10) > 3
|
|
||||||
preferred_categories, _ := weightedrand.NewChooser(
|
preferred_categories, _ := weightedrand.NewChooser(
|
||||||
weightedrand.Choice{Item: "Development", Weight: gofakeit.UintN(10) + 1},
|
weightedrand.Choice{Item: "Development", Weight: gofakeit.UintN(10) + 1},
|
||||||
weightedrand.Choice{Item: "Novel", Weight: gofakeit.UintN(10) + 1},
|
weightedrand.Choice{Item: "Novel", Weight: gofakeit.UintN(10) + 1},
|
||||||
@ -281,12 +280,14 @@ func main() {
|
|||||||
for i := 1; i <= 100*60*5; i++ {
|
for i := 1; i <= 100*60*5; i++ {
|
||||||
click_events := []string{}
|
click_events := []string{}
|
||||||
click_event_count := gofakeit.IntRange(1, 5)
|
click_event_count := gofakeit.IntRange(1, 5)
|
||||||
if is_anon {
|
|
||||||
|
if gofakeit.IntN(10) > 3 {
|
||||||
for j := 0; j < click_event_count; j++ {
|
for j := 0; j < click_event_count; j++ {
|
||||||
click_events = append(click_events, fmt.Sprintf("{\"type\":\"click\",\"details\":{\"element\":\".%s\",\"content\":{\"item_name\":\"%s\",\"item_category\":\"%s\",\"item_location\":\"%s\"}},\"credentials\":{\"session_id\":null,\"session_issuer\":null,\"sys_trace_id\":\"ubks__mainsvc__vNeptune_1_%s\"},\"event_at\":\"%s\"}",
|
click_events = append(click_events, fmt.Sprintf("{\"type\":\"click\",\"details\":{\"element\":\".%s\",\"content\":{\"item_name\":\"%s\",\"item_category\":\"%s\",\"item_location\":\"%s\"}},\"credentials\":{\"session_id\":null,\"session_issuer\":null,\"sys_trace_id\":\"ubks__mainsvc__vNeptune_1_%s\"},\"event_at\":\"%s\"}",
|
||||||
gofakeit.RandomString([]string{"bookItem", "audioItem"}), gofakeit.Adjective()+" "+gofakeit.Noun(), preferred_categories.Pick().(string), gofakeit.Street(), gofakeit.UUID(), time.Now().Format("2006-01-02T15:04:05.999999-07:00")))
|
gofakeit.RandomString([]string{"bookItem", "audioItem"}), gofakeit.Adjective()+" "+gofakeit.Noun(), preferred_categories.Pick().(string), gofakeit.Street(), gofakeit.UUID(), time.Now().Format("2006-01-02T15:04:05.999999-07:00")))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
go func() {
|
||||||
writer.WriteMessages(context.Background(),
|
writer.WriteMessages(context.Background(),
|
||||||
kafka.Message{
|
kafka.Message{
|
||||||
Value: []byte("[" + strings.Join(click_events, ",") + "]"),
|
Value: []byte("[" + strings.Join(click_events, ",") + "]"),
|
||||||
@ -304,6 +305,7 @@ func main() {
|
|||||||
gofakeit.Adjective(), gofakeit.Noun(), gofakeit.LoremIpsumSentence(100), time.Now().Format("2006-01-02T15:04:05.999999-07:00"))),
|
gofakeit.Adjective(), gofakeit.Noun(), gofakeit.LoremIpsumSentence(100), time.Now().Format("2006-01-02T15:04:05.999999-07:00"))),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
}()
|
||||||
} else {
|
} else {
|
||||||
session_id := gofakeit.UUID()
|
session_id := gofakeit.UUID()
|
||||||
for j := 0; j < click_event_count; j++ {
|
for j := 0; j < click_event_count; j++ {
|
||||||
@ -311,6 +313,7 @@ func main() {
|
|||||||
gofakeit.RandomString([]string{"bookItem", "audioItem"}), gofakeit.Adjective()+" "+gofakeit.Noun(), preferred_categories.Pick().(string), gofakeit.Street(), session_id, gofakeit.UUID(), time.Now().Format("2006-01-02T15:04:05.999999-07:00")))
|
gofakeit.RandomString([]string{"bookItem", "audioItem"}), gofakeit.Adjective()+" "+gofakeit.Noun(), preferred_categories.Pick().(string), gofakeit.Street(), session_id, gofakeit.UUID(), time.Now().Format("2006-01-02T15:04:05.999999-07:00")))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
go func() {
|
||||||
writer.WriteMessages(context.Background(),
|
writer.WriteMessages(context.Background(),
|
||||||
kafka.Message{
|
kafka.Message{
|
||||||
Value: []byte(fmt.Sprintf("{\"type\":\"login\",\"details\":{\"user_id\":\"%s\",\"user_name\":\"%s\",\"user_age\":%d},\"credentials\":{\"session_id\":\"ubks_%s\",\"session_issuer\":\"mainsvc__vNeptune_1\",\"sys_trace_id\":\"ubks__mainsvc__vNeptune_1_%s\"},\"event_at\":\"%s\"}",
|
Value: []byte(fmt.Sprintf("{\"type\":\"login\",\"details\":{\"user_id\":\"%s\",\"user_name\":\"%s\",\"user_age\":%d},\"credentials\":{\"session_id\":\"ubks_%s\",\"session_issuer\":\"mainsvc__vNeptune_1\",\"sys_trace_id\":\"ubks__mainsvc__vNeptune_1_%s\"},\"event_at\":\"%s\"}",
|
||||||
@ -332,6 +335,7 @@ func main() {
|
|||||||
gofakeit.Adjective(), gofakeit.Noun(), gofakeit.LoremIpsumSentence(100), time.Now().Format("2006-01-02T15:04:05.999999-07:00"))),
|
gofakeit.Adjective(), gofakeit.Noun(), gofakeit.LoremIpsumSentence(100), time.Now().Format("2006-01-02T15:04:05.999999-07:00"))),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
time.Sleep(10 * time.Millisecond)
|
time.Sleep(10 * time.Millisecond)
|
||||||
|
Loading…
Reference in New Issue
Block a user