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.
46 lines
857 B
46 lines
857 B
package client
|
|
|
|
import (
|
|
"github.com/seaweedfs/seaweedfs/weed/pb"
|
|
"time"
|
|
)
|
|
|
|
type PublishProcessor interface {
|
|
AddMessage(m *Message) error
|
|
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
|
|
}
|
|
|
|
type Message struct {
|
|
Key []byte
|
|
Content []byte
|
|
Properties map[string]string
|
|
Ts time.Time
|
|
}
|
|
|
|
func (p Publisher) Publish(m *Message) error {
|
|
return p.processor.AddMessage(m)
|
|
}
|
|
|
|
func (p Publisher) Shutdown() error {
|
|
return p.processor.Shutdown()
|
|
}
|