seaweedfs/weed/mq/client/publisher.go

41 lines
811 B
Go
Raw Normal View History

2022-09-04 08:29:01 +00:00
package client
import (
2022-09-23 06:21:13 +00:00
"github.com/seaweedfs/seaweedfs/weed/mq/messages"
2022-09-04 08:29:01 +00:00
"github.com/seaweedfs/seaweedfs/weed/pb"
"time"
)
type PublishProcessor interface {
2022-09-23 06:21:13 +00:00
AddMessage(m *messages.Message) error
2022-09-04 08:29:01 +00:00
Shutdown() error
}
type PublisherOption struct {
Masters string
Topic string
}
type Publisher struct {
option *PublisherOption
masters []pb.ServerAddress
processor *PublishStreamProcessor
}
func NewPublisher(option *PublisherOption) *Publisher {
p := &Publisher{
masters: pb.ServerAddresses(option.Masters).ToAddresses(),
option: option,
processor: NewPublishStreamProcessor(3, 887*time.Millisecond),
}
return p
}
2022-09-23 06:21:13 +00:00
func (p Publisher) Publish(m *messages.Message) error {
2022-09-04 08:29:01 +00:00
return p.processor.AddMessage(m)
}
func (p Publisher) Shutdown() error {
return p.processor.Shutdown()
}