2023-09-01 07:36:51 +00:00
|
|
|
package sub_client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/mq_pb"
|
|
|
|
"google.golang.org/grpc"
|
2023-12-11 20:05:54 +00:00
|
|
|
"time"
|
2023-09-01 07:36:51 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type SubscriberConfiguration struct {
|
2023-10-02 08:02:27 +00:00
|
|
|
ClientId string
|
|
|
|
GroupId string
|
|
|
|
GroupInstanceId string
|
|
|
|
GroupMinimumPeers int32
|
|
|
|
GroupMaximumPeers int32
|
|
|
|
BootstrapServers []string
|
|
|
|
GrpcDialOption grpc.DialOption
|
2023-09-01 07:36:51 +00:00
|
|
|
}
|
|
|
|
|
2023-09-05 04:43:50 +00:00
|
|
|
type ContentConfiguration struct {
|
|
|
|
Namespace string
|
|
|
|
Topic string
|
|
|
|
Filter string
|
2023-12-11 20:05:54 +00:00
|
|
|
StartTime time.Time
|
2023-09-05 04:43:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type OnEachMessageFunc func(key, value []byte) (shouldContinue bool)
|
|
|
|
type OnCompletionFunc func()
|
|
|
|
|
2023-09-01 07:36:51 +00:00
|
|
|
type TopicSubscriber struct {
|
2023-09-05 04:43:50 +00:00
|
|
|
SubscriberConfig *SubscriberConfiguration
|
|
|
|
ContentConfig *ContentConfiguration
|
2023-09-01 07:36:51 +00:00
|
|
|
brokerPartitionAssignments []*mq_pb.BrokerPartitionAssignment
|
2023-09-05 04:43:50 +00:00
|
|
|
OnEachMessageFunc OnEachMessageFunc
|
|
|
|
OnCompletionFunc OnCompletionFunc
|
2023-12-11 20:05:54 +00:00
|
|
|
bootstrapBrokers []string
|
|
|
|
waitForMoreMessage bool
|
|
|
|
alreadyProcessedTsNs int64
|
2023-09-01 07:36:51 +00:00
|
|
|
}
|
|
|
|
|
2023-12-11 20:05:54 +00:00
|
|
|
func NewTopicSubscriber(bootstrapBrokers []string, subscriber *SubscriberConfiguration, content *ContentConfiguration) *TopicSubscriber {
|
2023-09-01 07:36:51 +00:00
|
|
|
return &TopicSubscriber{
|
2023-12-11 20:05:54 +00:00
|
|
|
SubscriberConfig: subscriber,
|
|
|
|
ContentConfig: content,
|
|
|
|
bootstrapBrokers: bootstrapBrokers,
|
|
|
|
waitForMoreMessage: true,
|
|
|
|
alreadyProcessedTsNs: content.StartTime.UnixNano(),
|
2023-09-01 07:36:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-05 04:43:50 +00:00
|
|
|
func (sub *TopicSubscriber) SetEachMessageFunc(onEachMessageFn OnEachMessageFunc) {
|
|
|
|
sub.OnEachMessageFunc = onEachMessageFn
|
|
|
|
}
|
|
|
|
|
2023-12-11 20:05:54 +00:00
|
|
|
func (sub *TopicSubscriber) SetCompletionFunc(onCompletionFn OnCompletionFunc) {
|
|
|
|
sub.OnCompletionFunc = onCompletionFn
|
2023-09-05 04:43:50 +00:00
|
|
|
}
|