You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

50 lines
1.0 KiB

package main
import (
"context"
"fmt"
"github.com/seaweedfs/seaweedfs/weed/pb"
"github.com/seaweedfs/seaweedfs/weed/pb/mq_pb"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)
func main() {
err := pb.WithBrokerGrpcClient(true,
"localhost:17777",
grpc.WithTransportCredentials(insecure.NewCredentials()),
func(client mq_pb.SeaweedMessagingClient) error {
subClient, err := client.Subscribe(context.Background(), &mq_pb.SubscribeRequest{
Init: &mq_pb.SubscribeRequest_InitMessage{
Topic: &mq_pb.Topic{
Namespace: "test",
Name: "test",
},
},
})
if err != nil {
return err
}
for {
resp, err := subClient.Recv()
if err != nil {
return err
}
if resp.GetCtrl() != nil {
if resp.GetCtrl().Error != "" {
return fmt.Errorf("ctrl error: %v", resp.GetCtrl().Error)
}
}
if resp.GetData() != nil {
println(string(resp.GetData().Key), "=>", string(resp.GetData().Value))
}
}
return nil
})
if err != nil {
fmt.Println(err)
}
}