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