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.

43 lines
1.0 KiB

2 years ago
2 years ago
2 years ago
  1. package pub_client
  2. import (
  3. "github.com/rdleal/intervalst/interval"
  4. "github.com/seaweedfs/seaweedfs/weed/pb/mq_pb"
  5. "google.golang.org/grpc"
  6. "google.golang.org/grpc/credentials/insecure"
  7. "sync"
  8. )
  9. type PublisherConfiguration struct {
  10. }
  11. type PublishClient struct {
  12. mq_pb.SeaweedMessaging_PublishClient
  13. Broker string
  14. Err error
  15. }
  16. type TopicPublisher struct {
  17. namespace string
  18. topic string
  19. partition2Broker *interval.SearchTree[*PublishClient, int32]
  20. grpcDialOption grpc.DialOption
  21. sync.Mutex // protects grpc
  22. }
  23. func NewTopicPublisher(namespace, topic string) *TopicPublisher {
  24. return &TopicPublisher{
  25. namespace: namespace,
  26. topic: topic,
  27. partition2Broker: interval.NewSearchTree[*PublishClient](func(a, b int32) int {
  28. return int(a - b)
  29. }),
  30. grpcDialOption: grpc.WithTransportCredentials(insecure.NewCredentials()),
  31. }
  32. }
  33. func (p *TopicPublisher) Connect(bootstrapBroker string) error {
  34. if err := p.doLookup(bootstrapBroker); err != nil {
  35. return err
  36. }
  37. return nil
  38. }