github.com/sereiner/library@v0.0.0-20200518095232-1fa3e640cc5f/mq/nsq/nsq.message.go (about)

     1  package nsq
     2  
     3  import (
     4  	"github.com/nsqio/go-nsq"
     5  )
     6  
     7  //NsqMessage reids消息
     8  type NsqMessage struct {
     9  	Message string
    10  	HasData bool
    11  }
    12  
    13  //Ack 确定消息
    14  func (m *NsqMessage) Ack() error {
    15  	return nil
    16  }
    17  
    18  //Nack 取消消息
    19  func (m *NsqMessage) Nack() error {
    20  	return nil
    21  }
    22  
    23  //GetMessage 获取消息
    24  func (m *NsqMessage) GetMessage() string {
    25  	return m.Message
    26  }
    27  
    28  //Has 是否有数据
    29  func (m *NsqMessage) Has() bool {
    30  	return m.HasData
    31  }
    32  
    33  //NewNsqMessage 创建消息
    34  func NewNsqMessage(msg *nsq.Message) *NsqMessage {
    35  	ndata := string(msg.Body)
    36  	hasData := msg.HasResponded()
    37  	return &NsqMessage{Message: ndata, HasData: hasData}
    38  }