multipusher.go 766 B

1234567891011121314151617181920212223242526272829303132333435
  1. package queue
  2. import "git.i2edu.net/i2/go-zero/core/errorx"
  3. // A MultiPusher is a pusher that can push messages to multiple underlying pushers.
  4. type MultiPusher struct {
  5. name string
  6. pushers []Pusher
  7. }
  8. // NewMultiPusher returns a MultiPusher.
  9. func NewMultiPusher(pushers []Pusher) Pusher {
  10. return &MultiPusher{
  11. name: generateName(pushers),
  12. pushers: pushers,
  13. }
  14. }
  15. // Name returns the name of pusher.
  16. func (pusher *MultiPusher) Name() string {
  17. return pusher.name
  18. }
  19. // Push pushes a message into the underlying queue.
  20. func (pusher *MultiPusher) Push(message string) error {
  21. var batchError errorx.BatchError
  22. for _, each := range pusher.pushers {
  23. if err := each.Push(message); err != nil {
  24. batchError.Add(err)
  25. }
  26. }
  27. return batchError.Err()
  28. }