2023-08-28 08:50:59 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2023-12-12 04:05:54 +08:00
|
|
|
"flag"
|
2023-08-28 08:50:59 +08:00
|
|
|
"fmt"
|
2023-09-01 15:36:51 +08:00
|
|
|
"github.com/seaweedfs/seaweedfs/weed/mq/client/sub_client"
|
2023-09-05 12:43:50 +08:00
|
|
|
"google.golang.org/grpc"
|
|
|
|
"google.golang.org/grpc/credentials/insecure"
|
2023-12-12 04:05:54 +08:00
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
namespace = flag.String("ns", "test", "namespace")
|
|
|
|
topic = flag.String("topic", "test", "topic")
|
|
|
|
seedBrokers = flag.String("brokers", "localhost:17777", "seed brokers")
|
2023-08-28 08:50:59 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2023-12-12 04:05:54 +08:00
|
|
|
flag.Parse()
|
2023-08-28 08:50:59 +08:00
|
|
|
|
2023-09-05 12:43:50 +08:00
|
|
|
subscriberConfig := &sub_client.SubscriberConfiguration{
|
|
|
|
ClientId: "testSubscriber",
|
|
|
|
GroupId: "test",
|
|
|
|
GroupInstanceId: "test",
|
|
|
|
GrpcDialOption: grpc.WithTransportCredentials(insecure.NewCredentials()),
|
|
|
|
}
|
|
|
|
|
|
|
|
contentConfig := &sub_client.ContentConfiguration{
|
2023-12-12 04:05:54 +08:00
|
|
|
Namespace: *namespace,
|
|
|
|
Topic: *topic,
|
2023-09-05 12:43:50 +08:00
|
|
|
Filter: "",
|
2023-12-12 04:05:54 +08:00
|
|
|
StartTime: time.Now(),
|
2023-09-05 12:43:50 +08:00
|
|
|
}
|
|
|
|
|
2023-12-12 04:05:54 +08:00
|
|
|
brokers := strings.Split(*seedBrokers, ",")
|
|
|
|
subscriber := sub_client.NewTopicSubscriber(brokers, subscriberConfig, contentConfig)
|
2023-08-28 08:50:59 +08:00
|
|
|
|
2023-09-05 12:43:50 +08:00
|
|
|
subscriber.SetEachMessageFunc(func(key, value []byte) bool {
|
2023-09-01 15:36:51 +08:00
|
|
|
println(string(key), "=>", string(value))
|
|
|
|
return true
|
2023-09-05 12:43:50 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
subscriber.SetCompletionFunc(func() {
|
2023-09-01 15:36:51 +08:00
|
|
|
println("done subscribing")
|
2023-09-05 12:43:50 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
if err := subscriber.Subscribe(); err != nil {
|
2023-08-28 08:50:59 +08:00
|
|
|
fmt.Println(err)
|
|
|
|
}
|
2023-09-01 15:36:51 +08:00
|
|
|
|
2023-08-28 08:50:59 +08:00
|
|
|
}
|