0

我正在做的 atm 是:我必须从服务器获取 XML 文件。此 XML 包含许多日志,每个日志都被解析并转换为一个事件,一个beat.event. 我想要的是,将所有日志发送到elasticsearch,或者不发送。我可以举办一个大型活动并立即发布所有内容吗?或者做一个队列来存储所有需要发送的事件,这样如果一个事件发送失败,事务就结束,elasticsearch回滚?

这里的词是交易。我想发布全部或全部内容。有没有办法做到这一点?

我的代码如下:

for i := 0; i < len(s.List); i++ {
                //fmt.Printf("Starting to build the event %v \n", i)
                event := beat.Event{
                    Timestamp: time.Now(),
                    Fields: common.MapStr{
                        "id":                s.List[i].Id,
                        "sipCallId":         s.List[i].SipCallId,
                        "originNumber":      s.List[i].OriginNumber,
                        "targetNumber":      s.List[i].TargetNumber,
                        "originDDD":         s.List[i].OriginDDD,
                        "targetDDD":         s.List[i].TargetDDD,
                        "originInstitution": s.List[i].OriginInstitution,
                        "targetInstitution": s.List[i].TargetInstitution,
                        "setupTime":         s.List[i].SetupTime.SetupTime,
                        "connectTime":       s.List[i].ConnectTime.ConnectTime,
                        "disconnectTime":    s.List[i].DisconnectTime.DisconnectTime,
                        "duration":          s.List[i].Duration,
                        "originType":        s.List[i].OriginType,
                        "targetType":        s.List[i].TargetType,
                        "answered":          s.List[i].Answered,
                        "callCompleted":     s.List[i].CallCompleted,
                        "sipJustification":  s.List[i].SipJustification,
                        //Dados adicionados como argumentos pra chamada do programa.
                        "tipoDoEquipamento":    bt.config.TipoEquipamento,
                        "versaoDoEquipamento":  bt.config.Versao,
                        "nivelDoEquipamento":   bt.config.Nivel,
                        "instituição":          bt.config.Instituicao,
                        "enderecoIP":           bt.config.Ip,
                        "timestampColeta":      time.Now(),
                        "consolidado":          bt.config.Consolidado,
                        "timestampConsolidado": bt.config.TimestampConsolidado,
                    },
                }
                bt.client.Publish(event)
                logp.Info("Event sent")
                //fmt.Printf("Event %v published \n", i)
4

0 回答 0