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.3 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. package sub_client
  2. import (
  3. "github.com/seaweedfs/seaweedfs/weed/pb/mq_pb"
  4. "google.golang.org/grpc"
  5. )
  6. type SubscriberConfiguration struct {
  7. ClientId string
  8. GroupId string
  9. GroupInstanceId string
  10. GroupMinimumPeers int32
  11. GroupMaximumPeers int32
  12. BootstrapServers []string
  13. GrpcDialOption grpc.DialOption
  14. }
  15. type ContentConfiguration struct {
  16. Namespace string
  17. Topic string
  18. Filter string
  19. }
  20. type OnEachMessageFunc func(key, value []byte) (shouldContinue bool)
  21. type OnCompletionFunc func()
  22. type TopicSubscriber struct {
  23. SubscriberConfig *SubscriberConfiguration
  24. ContentConfig *ContentConfiguration
  25. brokerPartitionAssignments []*mq_pb.BrokerPartitionAssignment
  26. OnEachMessageFunc OnEachMessageFunc
  27. OnCompletionFunc OnCompletionFunc
  28. bootstrapBroker string
  29. }
  30. func NewTopicSubscriber(bootstrapBroker string, subscriber *SubscriberConfiguration, content *ContentConfiguration) *TopicSubscriber {
  31. return &TopicSubscriber{
  32. SubscriberConfig: subscriber,
  33. ContentConfig: content,
  34. bootstrapBroker: bootstrapBroker,
  35. }
  36. }
  37. func (sub *TopicSubscriber) SetEachMessageFunc(onEachMessageFn OnEachMessageFunc) {
  38. sub.OnEachMessageFunc = onEachMessageFn
  39. }
  40. func (sub *TopicSubscriber) SetCompletionFunc(onCompeletionFn OnCompletionFunc) {
  41. sub.OnCompletionFunc = onCompeletionFn
  42. }