//发送消息 func (self *KiteClientManager) SendMessage(msg *protocol.QMessage) error { c, err := self.selectKiteClient(msg.GetHeader()) if nil != err { return err } return c.sendMessage(msg) }
//发送事务消息 func (self *KiteClientManager) SendTxMessage(msg *protocol.QMessage, doTranscation DoTranscation) (err error) { //路由选择策略 c, err := self.selectKiteClient(msg.GetHeader()) if nil != err { return err } //先发送消息 err = c.sendMessage(msg) if nil != err { return err } //执行本地事务返回succ为成功则提交、其余条件包括错误、失败都属于回滚 feedback := "" succ := false txstatus := protocol.TX_UNKNOWN //执行本地事务 succ, err = doTranscation(msg) if nil == err && succ { txstatus = protocol.TX_COMMIT } else { txstatus = protocol.TX_ROLLBACK if nil != err { feedback = err.Error() } } //发送txack到服务端 c.sendTxAck(msg, txstatus, feedback) return err }
func (self *MockListener) OnMessage(msg *protocol.QMessage) bool { log.Println("MockListener|OnMessage", msg.GetHeader(), msg.GetBody()) self.rc <- msg.GetHeader().GetMessageId() return true }
func (self *defualtListener) OnMessage(msg *protocol.QMessage) bool { log.Info("defualtListener|OnMessage", msg.GetHeader(), msg.GetBody()) return true }
func (self *defualtListener) OnMessage(msg *protocol.QMessage) bool { log.Printf("defualtListener|OnMessage|%s\n", msg.GetHeader().GetMessageId()) return true }
func (self *MockListener) OnMessage(msg *protocol.QMessage) bool { log.Debug("MockListener|OnMessage", msg.GetHeader(), msg.GetBody()) return true }
//创建stringmessage func NewMessageEntity(msg *protocol.QMessage) *MessageEntity { entity := &MessageEntity{ Header: msg.GetHeader(), Body: msg.GetBody(), MessageId: msg.GetHeader().GetMessageId(), Topic: msg.GetHeader().GetTopic(), MessageType: msg.GetHeader().GetMessageType(), PublishGroup: msg.GetHeader().GetGroupId(), Commit: msg.GetHeader().GetCommit(), ExpiredTime: msg.GetHeader().GetExpiredTime(), DeliverCount: 0, DeliverLimit: msg.GetHeader().GetDeliverLimit(), //消息种类 MsgType: msg.GetMsgType()} return entity }
//发送事务的确认,无需等待服务器反馈 func (self *kiteClient) sendTxAck(message *protocol.QMessage, txstatus protocol.TxStatus, feedback string) error { txpacket := protocol.MarshalTxACKPacket(message.GetHeader(), txstatus, feedback) return self.innerSendMessage(protocol.CMD_TX_ACK, txpacket, 0) }
func (self *defualtListener) OnMessage(msg *protocol.QMessage) bool { log.Info("defualtListener|OnMessage|%s", msg.GetHeader().GetMessageId()) atomic.AddInt32(&self.count, 1) return true }