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

2 years ago
  1. package client
  2. import (
  3. "github.com/seaweedfs/seaweedfs/weed/pb"
  4. "time"
  5. )
  6. type PublishProcessor interface {
  7. AddMessage(m *Message) error
  8. Shutdown() error
  9. }
  10. type PublisherOption struct {
  11. Masters string
  12. Topic string
  13. }
  14. type Publisher struct {
  15. option *PublisherOption
  16. masters []pb.ServerAddress
  17. processor *PublishStreamProcessor
  18. }
  19. func NewPublisher(option *PublisherOption) *Publisher {
  20. p := &Publisher{
  21. masters: pb.ServerAddresses(option.Masters).ToAddresses(),
  22. option: option,
  23. processor: NewPublishStreamProcessor(3, 887*time.Millisecond),
  24. }
  25. return p
  26. }
  27. type Message struct {
  28. Key []byte
  29. Content []byte
  30. Properties map[string]string
  31. Ts time.Time
  32. }
  33. func (p Publisher) Publish(m *Message) error {
  34. return p.processor.AddMessage(m)
  35. }
  36. func (p Publisher) Shutdown() error {
  37. return p.processor.Shutdown()
  38. }