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.

48 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 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. BootstrapServers []string
  11. GrpcDialOption grpc.DialOption
  12. }
  13. type ContentConfiguration struct {
  14. Namespace string
  15. Topic string
  16. Filter string
  17. }
  18. type OnEachMessageFunc func(key, value []byte) (shouldContinue bool)
  19. type OnCompletionFunc func()
  20. type TopicSubscriber struct {
  21. SubscriberConfig *SubscriberConfiguration
  22. ContentConfig *ContentConfiguration
  23. brokerPartitionAssignments []*mq_pb.BrokerPartitionAssignment
  24. OnEachMessageFunc OnEachMessageFunc
  25. OnCompletionFunc OnCompletionFunc
  26. bootstrapBroker string
  27. }
  28. func NewTopicSubscriber(bootstrapBroker string, subscriber *SubscriberConfiguration, content *ContentConfiguration) *TopicSubscriber {
  29. return &TopicSubscriber{
  30. SubscriberConfig: subscriber,
  31. ContentConfig: content,
  32. bootstrapBroker: bootstrapBroker,
  33. }
  34. }
  35. func (sub *TopicSubscriber) SetEachMessageFunc(onEachMessageFn OnEachMessageFunc) {
  36. sub.OnEachMessageFunc = onEachMessageFn
  37. }
  38. func (sub *TopicSubscriber) SetCompletionFunc(onCompeletionFn OnCompletionFunc) {
  39. sub.OnCompletionFunc = onCompeletionFn
  40. }