예제 #1
0
func SendMessage(client *nsqd.ClientV2, msg *nsqd.Message, buf *bytes.Buffer, needFlush bool) error {
	buf.Reset()
	if !client.EnableTrace {
		_, err := msg.WriteTo(buf)
		if err != nil {
			return err
		}
	} else {
		_, err := msg.WriteToWithDetail(buf)
		if err != nil {
			return err
		}
	}

	err := internalSend(client, frameTypeMessage, buf.Bytes(), needFlush)
	if err != nil {
		return err
	}

	return nil
}
예제 #2
0
func (s *nsqdCoordGRpcServer) PutMessages(ctx context.Context, req *pb.RpcPutMessages) (*pb.CoordErr, error) {
	var coordErr pb.CoordErr
	if coordLog.Level() >= levellogger.LOG_DEBUG {
		s := time.Now().Unix()
		defer func() {
			e := time.Now().Unix()
			if e-s > int64(RPC_TIMEOUT/2) {
				coordLog.Infof("PutMessage rpc call used: %v", e-s)
			}
		}()
	}

	tc, err := s.nsqdCoord.checkWriteForGRpcCall(req.TopicData)
	if err != nil {
		coordErr.ErrMsg = err.ErrMsg
		coordErr.ErrCode = int32(err.ErrCode)
		coordErr.ErrType = int32(err.ErrType)
		return &coordErr, nil
	}
	// do local pub message
	var commitData CommitLogData
	commitData.Epoch = EpochType(req.LogData.Epoch)
	commitData.LogID = req.LogData.LogID
	commitData.MsgNum = req.LogData.MsgNum
	commitData.MsgCnt = req.LogData.MsgCnt
	commitData.MsgSize = req.LogData.MsgSize
	commitData.MsgOffset = req.LogData.MsgOffset
	commitData.LastMsgLogID = req.LogData.LastMsgLogID
	var msgs []*nsqd.Message
	for _, pbm := range req.TopicMessage {
		var msg nsqd.Message
		msg.ID = nsqd.MessageID(pbm.ID)
		msg.TraceID = pbm.Trace_ID
		msg.Attempts = uint16(pbm.Attemps)
		msg.Timestamp = pbm.Timestamp
		msg.Body = pbm.Body
		msgs = append(msgs, &msg)
	}

	err = s.nsqdCoord.putMessagesOnSlave(tc, commitData, msgs)
	if err != nil {
		coordErr.ErrMsg = err.ErrMsg
		coordErr.ErrCode = int32(err.ErrCode)
		coordErr.ErrType = int32(err.ErrType)
	}
	return &coordErr, nil
}