seaweedfs/weed/mq/client/cmd/weed_sub/subscriber.go

41 lines
896 B
Go
Raw Normal View History

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