initial import

This commit is contained in:
kevin
2020-07-26 17:09:05 +08:00
commit 7e3a369a8f
647 changed files with 54754 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
{
"Name": "kmq",
"Brokers": [
"172.16.56.64:19092",
"172.16.56.65:19092",
"172.16.56.66:19092"
],
"Group": "adhoc",
"Topic": "kevin",
"Offset": "first",
"NumProducers": 1
}

View File

@@ -0,0 +1,20 @@
package main
import (
"fmt"
"zero/core/conf"
"zero/kq"
)
func main() {
var c kq.KqConf
conf.MustLoad("config.json", &c)
q := kq.MustNewQueue(c, kq.WithHandle(func(k, v string) error {
fmt.Printf("=> %s\n", v)
return nil
}))
defer q.Stop()
q.Start()
}

View File

@@ -0,0 +1,51 @@
package main
import (
"encoding/json"
"fmt"
"log"
"math/rand"
"strconv"
"time"
"zero/core/cmdline"
"zero/kq"
)
type message struct {
Key string `json:"key"`
Value string `json:"value"`
Payload string `json:"message"`
}
func main() {
pusher := kq.NewPusher([]string{
"172.16.56.64:19092",
"172.16.56.65:19092",
"172.16.56.66:19092",
}, "kevin")
ticker := time.NewTicker(time.Millisecond)
for round := 0; round < 3; round++ {
select {
case <-ticker.C:
count := rand.Intn(100)
m := message{
Key: strconv.FormatInt(time.Now().UnixNano(), 10),
Value: fmt.Sprintf("%d,%d", round, count),
Payload: fmt.Sprintf("%d,%d", round, count),
}
body, err := json.Marshal(m)
if err != nil {
log.Fatal(err)
}
fmt.Println(string(body))
if err := pusher.Push(string(body)); err != nil {
log.Fatal(err)
}
}
}
cmdline.EnterToContinue()
}