2023-08-28 08:50:59 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"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-08-28 08:50:59 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
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{
|
|
|
|
Namespace: "test",
|
|
|
|
Topic: "test",
|
|
|
|
Filter: "",
|
|
|
|
}
|
|
|
|
|
2023-10-02 02:59:19 +08:00
|
|
|
subscriber := sub_client.NewTopicSubscriber("localhost:17777", 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
|
|
|
}
|