userbilltransfer.go 714 B

123456789101112131415161718192021222324252627282930
  1. package paopaoqueue
  2. import (
  3. "context"
  4. "encoding/json"
  5. "fmt"
  6. "git.banshen.xyz/huangguangrong/slow_wild_queue/types"
  7. "github.com/zeromicro/go-queue/kq"
  8. )
  9. type UserBillTransferClient interface {
  10. Push(msg *types.UserBillContentData) error
  11. }
  12. type userBillTransferClient struct {
  13. pusher *kq.Pusher
  14. }
  15. func NewUserBillTransferClient(addr []string, topic string, opts ...kq.Pusher) UserBillTransferClient {
  16. fmt.Println("topic: ", topic)
  17. return &userBillTransferClient{pusher: kq.NewPusher(addr, topic)}
  18. }
  19. func (m *userBillTransferClient) Push(msg *types.UserBillContentData) error {
  20. data, err := json.Marshal(msg)
  21. if err != nil {
  22. return err
  23. }
  24. return m.pusher.Push(context.Background(), string(data))
  25. }