mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
45 lines
971 B
Go
45 lines
971 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/seaweedfs/seaweedfs/weed/mq/client/sub_client"
|
|
"google.golang.org/grpc"
|
|
"google.golang.org/grpc/credentials/insecure"
|
|
)
|
|
|
|
func main() {
|
|
|
|
subscriberConfig := &sub_client.SubscriberConfiguration{
|
|
ClientId: "testSubscriber",
|
|
GroupId: "test",
|
|
GroupInstanceId: "test",
|
|
GrpcDialOption: grpc.WithTransportCredentials(insecure.NewCredentials()),
|
|
}
|
|
|
|
contentConfig := &sub_client.ContentConfiguration{
|
|
Namespace: "test",
|
|
Topic: "test",
|
|
Filter: "",
|
|
}
|
|
|
|
subscriber := sub_client.NewTopicSubscriber(subscriberConfig, contentConfig)
|
|
if err := subscriber.Connect("localhost:17777"); err != nil {
|
|
fmt.Println(err)
|
|
return
|
|
}
|
|
|
|
subscriber.SetEachMessageFunc(func(key, value []byte) bool {
|
|
println(string(key), "=>", string(value))
|
|
return true
|
|
})
|
|
|
|
subscriber.SetCompletionFunc(func() {
|
|
println("done subscribing")
|
|
})
|
|
|
|
if err := subscriber.Subscribe(); err != nil {
|
|
fmt.Println(err)
|
|
}
|
|
|
|
}
|