コード例 #1
0
  void dr_cb (RdKafka::Message &message) {
    if (message.err()) {
      state.producer.numErr++;
      errorString("producer_send_error", message.errstr(),
		  message.topic_name(),
		  message.key(),
		  std::string(static_cast<const char*>(message.payload()),
			      message.len()));
    } else {
      successString("producer_send_success",
		    message.topic_name(),
		    (int)message.partition(),
		    message.offset(),
		    message.key(),
		    std::string(static_cast<const char*>(message.payload()),
				message.len()));
      state.producer.numAcked++;
    }
  }
コード例 #2
0
        void LogDeliverReportCb::dr_cb(RdKafka::Message &message){
            if(message.err()!=ERR_NO_ERROR && !needRecover){ //kafka 发送发生错误
                DebugMessageWithTime("error occured in kafka,err",message.errstr()," errCode:",message.err());
                LogPusherPtr logPusher = LogPusher::getLogger(MTTY_SERVICE_LOGGER);
                logPusher->setWorkMode(true);
                const char* payload = (const char*)message.payload();
#if defined(USE_ALIYUN_LOG)
                log::Message msg(message.topic_name(),"",std::string(payload,payload+message.len()));
#else
                log::Message msg(message.topic_name(),std::string(payload,payload+message.len()));
#endif
                //logPusher->startRemoteMonitor(msg);
                needRecover = true;
            }else if(message.err()==ERR_NO_ERROR && needRecover){ //kafka 错误恢复
                DebugMessageWithTime("kafka error recover,continue to work");
                needRecover = false;
                LogPusherPtr logPusher = LogPusher::getLogger(MTTY_SERVICE_LOGGER);
                logPusher->setWorkMode(false);
            }
        }