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.

46 lines
1.4 KiB

  1. package agent
  2. import (
  3. "context"
  4. "github.com/seaweedfs/seaweedfs/weed/mq/client/sub_client"
  5. "github.com/seaweedfs/seaweedfs/weed/mq/topic"
  6. "github.com/seaweedfs/seaweedfs/weed/pb/mq_agent_pb"
  7. "google.golang.org/grpc"
  8. "google.golang.org/grpc/credentials/insecure"
  9. "math/rand/v2"
  10. )
  11. func (a *MessageQueueAgent) StartSubscribeSession(ctx context.Context, req *mq_agent_pb.StartSubscribeSessionRequest) (*mq_agent_pb.StartSubscribeSessionResponse, error) {
  12. sessionId := rand.Int64()
  13. subscriberConfig := &sub_client.SubscriberConfiguration{
  14. ConsumerGroup: req.ConsumerGroup,
  15. ConsumerGroupInstanceId: req.ConsumerGroupInstanceId,
  16. GrpcDialOption: grpc.WithTransportCredentials(insecure.NewCredentials()),
  17. MaxPartitionCount: req.MaxSubscribedPartitions,
  18. SlidingWindowSize: req.SlidingWindowSize,
  19. }
  20. contentConfig := &sub_client.ContentConfiguration{
  21. Topic: topic.FromPbTopic(req.Topic),
  22. Filter: req.Filter,
  23. PartitionOffsets: req.PartitionOffsets,
  24. }
  25. topicSubscriber := sub_client.NewTopicSubscriber(
  26. a.brokersList(),
  27. subscriberConfig,
  28. contentConfig,
  29. make(chan sub_client.KeyedOffset, 1024),
  30. )
  31. a.subscribersLock.Lock()
  32. a.subscribers[SessionId(sessionId)] = &SessionEntry[*sub_client.TopicSubscriber]{
  33. entry: topicSubscriber,
  34. }
  35. a.subscribersLock.Unlock()
  36. return &mq_agent_pb.StartSubscribeSessionResponse{
  37. SessionId: sessionId,
  38. }, nil
  39. }