mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-10-15 20:06:19 +08:00
can pub and sub
This commit is contained in:
@@ -5,14 +5,12 @@ import (
|
||||
"fmt"
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb"
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb/mq_pb"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
func (p *TopicPublisher) doLookup(
|
||||
brokerAddress string, grpcDialOption grpc.DialOption) error {
|
||||
func (p *TopicPublisher) doLookup(brokerAddress string) error {
|
||||
err := pb.WithBrokerGrpcClient(true,
|
||||
brokerAddress,
|
||||
grpcDialOption,
|
||||
p.grpcDialOption,
|
||||
func(client mq_pb.SeaweedMessagingClient) error {
|
||||
lookupResp, err := client.LookupTopicBrokers(context.Background(),
|
||||
&mq_pb.LookupTopicBrokersRequest{
|
||||
@@ -36,7 +34,7 @@ func (p *TopicPublisher) doLookup(
|
||||
// send init message
|
||||
// save the publishing client
|
||||
brokerAddress := brokerPartitionAssignment.LeaderBroker
|
||||
grpcConnection, err := pb.GrpcDial(context.Background(), brokerAddress, true, grpcDialOption)
|
||||
grpcConnection, err := pb.GrpcDial(context.Background(), brokerAddress, true, p.grpcDialOption)
|
||||
if err != nil {
|
||||
return fmt.Errorf("dial broker %s: %v", brokerAddress, err)
|
||||
}
|
||||
|
@@ -15,6 +15,7 @@ type TopicPublisher struct {
|
||||
topic string
|
||||
partition2Broker *interval.SearchTree[string, int32]
|
||||
broker2PublishClient cmap.ConcurrentMap[string, mq_pb.SeaweedMessaging_PublishClient]
|
||||
grpcDialOption grpc.DialOption
|
||||
}
|
||||
|
||||
func NewTopicPublisher(namespace, topic string) *TopicPublisher {
|
||||
@@ -25,11 +26,12 @@ func NewTopicPublisher(namespace, topic string) *TopicPublisher {
|
||||
return int(a - b)
|
||||
}),
|
||||
broker2PublishClient: cmap.New[mq_pb.SeaweedMessaging_PublishClient](),
|
||||
grpcDialOption: grpc.WithTransportCredentials(insecure.NewCredentials()),
|
||||
}
|
||||
}
|
||||
|
||||
func (p *TopicPublisher) Connect(bootstrapBroker string) error {
|
||||
if err := p.doLookup(bootstrapBroker, grpc.WithTransportCredentials(insecure.NewCredentials())); err != nil {
|
||||
if err := p.doLookup(bootstrapBroker); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
Reference in New Issue
Block a user