seaweedfs/weed/mq/client/pub_client/publisher.go

39 lines
1.1 KiB
Go
Raw Normal View History

2023-08-29 00:02:12 +08:00
package pub_client
2023-08-28 04:13:14 +08:00
2023-08-28 08:50:59 +08:00
import (
2023-08-29 00:02:12 +08:00
cmap "github.com/orcaman/concurrent-map/v2"
"github.com/rdleal/intervalst/interval"
2023-08-28 08:50:59 +08:00
"github.com/seaweedfs/seaweedfs/weed/pb/mq_pb"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)
2023-08-29 00:02:12 +08:00
type PublisherConfiguration struct {
}
type TopicPublisher struct {
namespace string
topic string
partition2Broker *interval.SearchTree[string, int32]
broker2PublishClient cmap.ConcurrentMap[string, mq_pb.SeaweedMessaging_PublishClient]
2023-09-01 15:36:51 +08:00
grpcDialOption grpc.DialOption
2023-08-29 00:02:12 +08:00
}
2023-08-28 08:50:59 +08:00
2023-08-29 00:02:12 +08:00
func NewTopicPublisher(namespace, topic string) *TopicPublisher {
return &TopicPublisher{
namespace: namespace,
topic: topic,
partition2Broker: interval.NewSearchTree[string](func(a, b int32) int {
return int(a - b)
}),
broker2PublishClient: cmap.New[mq_pb.SeaweedMessaging_PublishClient](),
2023-09-01 15:36:51 +08:00
grpcDialOption: grpc.WithTransportCredentials(insecure.NewCredentials()),
2023-08-28 08:50:59 +08:00
}
2023-08-29 00:02:12 +08:00
}
2023-08-28 08:50:59 +08:00
2023-08-29 00:02:12 +08:00
func (p *TopicPublisher) Connect(bootstrapBroker string) error {
2023-09-01 15:36:51 +08:00
if err := p.doLookup(bootstrapBroker); err != nil {
2023-08-29 00:02:12 +08:00
return err
}
return nil
2023-08-28 04:13:14 +08:00
}