func NewFlumeEvent(business, action string, body []byte) *flume.ThriftFlumeEvent { //拼装头部信息 header := make(map[string]string, 2) header["businessName"] = business header["type"] = action event := flume.NewThriftFlumeEvent() event.Headers = header event.Body = body return event }
func (self *FlumeClient) Append(header map[string]string, body []byte) error { if self.status == STATUS_DEAD { return errors.New("flume client is dead") } var err error event := flume.NewThriftFlumeEvent() event.Headers = header event.Body = body if nil != err { return err } ch := make(chan flume.Status, 1) go func(ch chan flume.Status) { //获取远程调用的对象 status, err := self.thriftclient.Append(event) if nil != err { log.Println("send flume event fail " + err.Error()) status = flume.Status_ERROR } ch <- status }(ch) defer close(ch) status := <-ch //如果没有成功则向上抛出 if status != flume.Status_OK { return errors.New("deliver fail ! " + status.String()) } return nil }
func NewFlumeEvent() flume.ThriftFlumeEvent { return *flume.NewThriftFlumeEvent() }