intermediate fixes

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
2021-08-22 12:10:58 +03:00
parent fc9af8c63e
commit 3f7fcaf4aa
4 changed files with 180 additions and 92 deletions

View File

@@ -6,15 +6,18 @@ import (
"os"
"strings"
"testing"
"time"
kgo "github.com/unistack-org/micro-broker-kgo/v3"
jsoncodec "github.com/unistack-org/micro-codec-json/v3"
"github.com/unistack-org/micro/v3/broker"
"github.com/unistack-org/micro/v3/logger"
"github.com/unistack-org/micro/v3/metadata"
)
var (
bm = &broker.Message{
Header: map[string]string{"hkey": "hval"},
Header: map[string]string{"hkey": "hval", metadata.HeaderTopic: "test"},
Body: []byte(`"body"`),
}
)
@@ -24,17 +27,17 @@ func TestPubSub(t *testing.T) {
t.Skip()
}
logger.DefaultLogger.Init(logger.WithLevel(logger.TraceLevel))
logger.DefaultLogger.Init(logger.WithLevel(logger.TraceLevel), logger.WithCallerSkipCount(3))
ctx := context.Background()
var addrs []string
if addr := os.Getenv("BROKER_ADDRS"); len(addr) == 0 {
addrs = []string{"127.0.0.1:9092"}
addrs = []string{"127.0.0.1:29091", "127.0.0.2:29092", "127.0.0.3:29093"}
} else {
addrs = strings.Split(addr, ",")
}
b := kgo.NewBroker(broker.Addrs(addrs...), kgo.ClientID("test"))
b := kgo.NewBroker(broker.Codec(jsoncodec.NewCodec()), broker.Addrs(addrs...), kgo.ClientID("test"))
if err := b.Init(); err != nil {
t.Fatal(err)
}
@@ -49,14 +52,26 @@ func TestPubSub(t *testing.T) {
}
}()
/*
fmt.Printf("prefill")
msgs := make([]*broker.Message, 0, 600000)
for i := 0; i < 600000; i++ {
msgs = append(msgs, bm)
}
if err := b.BatchPublish(ctx, msgs); err != nil {
t.Fatal(err)
}
*/
done := make(chan bool, 1)
idx := 0
fn := func(msg broker.Event) error {
fmt.Printf("EEEE %s\n", msg.Message().Body)
done <- true
idx++
return msg.Ack()
}
sub, err := b.Subscribe(ctx, "test_topic", fn, broker.SubscribeGroup("test"))
sub, err := b.Subscribe(ctx, "test", fn, broker.SubscribeAutoAck(true), broker.SubscribeGroup("test"), broker.SubscribeBodyOnly(true))
if err != nil {
t.Fatal(err)
}
@@ -65,8 +80,10 @@ func TestPubSub(t *testing.T) {
t.Fatal(err)
}
}()
if err := b.Publish(ctx, "test_topic", bm); err != nil {
t.Fatal(err)
for {
fmt.Printf("processed %v\n", idx)
time.Sleep(1 * time.Second)
}
<-done
}