producer.go 423 B

1234567891011121314
  1. package mqtt
  2. import (
  3. "gitee.com/xuyiping_admin/pkg/logger/zaplog"
  4. "go.uber.org/zap"
  5. )
  6. func (s *IMqttClient) Producer(top string, qos int32, data []byte) error {
  7. if token := s.Client.Publish(top, byte(qos), false, data); token.Wait() && token.Error() != nil {
  8. zaplog.Error("producer", zap.String("topic", top), zap.String("data", string(data)), zap.Any("err", token.Error()))
  9. return token.Error()
  10. }
  11. return nil
  12. }