multipusher.go 556 B

12345678910111213141516171819202122232425262728293031
  1. package queue
  2. import "github.com/tal-tech/go-zero/core/errorx"
  3. type MultiPusher struct {
  4. name string
  5. pushers []Pusher
  6. }
  7. func NewMultiPusher(pushers []Pusher) Pusher {
  8. return &MultiPusher{
  9. name: generateName(pushers),
  10. pushers: pushers,
  11. }
  12. }
  13. func (pusher *MultiPusher) Name() string {
  14. return pusher.name
  15. }
  16. func (pusher *MultiPusher) Push(message string) error {
  17. var batchError errorx.BatchError
  18. for _, each := range pusher.pushers {
  19. if err := each.Push(message); err != nil {
  20. batchError.Add(err)
  21. }
  22. }
  23. return batchError.Err()
  24. }