seaweedfs/weed/mq/client/sub_client/subscriber.go

54 lines
1.3 KiB
Go
Raw Normal View History

2023-09-01 07:36:51 +00:00
package sub_client
import (
"github.com/seaweedfs/seaweedfs/weed/pb/mq_pb"
"google.golang.org/grpc"
)
type SubscriberConfiguration struct {
2023-09-05 04:43:50 +00:00
ClientId string
GroupId string
GroupInstanceId string
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
}
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-09-01 07:36:51 +00:00
}
2023-09-05 04:43:50 +00:00
func NewTopicSubscriber(subscriber *SubscriberConfiguration, content *ContentConfiguration) *TopicSubscriber {
2023-09-01 07:36:51 +00:00
return &TopicSubscriber{
2023-09-05 04:43:50 +00:00
SubscriberConfig: subscriber,
ContentConfig: content,
2023-09-01 07:36:51 +00:00
}
}
func (sub *TopicSubscriber) Connect(bootstrapBroker string) error {
if err := sub.doLookup(bootstrapBroker); err != nil {
return err
}
return nil
}
2023-09-05 04:43:50 +00:00
func (sub *TopicSubscriber) SetEachMessageFunc(onEachMessageFn OnEachMessageFunc) {
sub.OnEachMessageFunc = onEachMessageFn
}
func (sub *TopicSubscriber) SetCompletionFunc(onCompeletionFn OnCompletionFunc) {
sub.OnCompletionFunc = onCompeletionFn
}