Browse Source

update 添加日志打印

dev
lucas 1 month ago
parent
commit
8ee59c1985
  1. 15
      adaptors/安心云最新设备数据toES.go
  2. 5
      consumers/consumerAXYraw.go
  3. 8
      main_test.go

15
adaptors/安心云最新设备数据toES.go

@ -14,12 +14,20 @@ import (
// Adaptor_AXY_LastRAW 安心云 kafka iota数据 转换 es设备数据
type Adaptor_AXY_LastRAW struct {
AXYraw.Info
Redis *dbOperate.RedisHelper
Redis *dbOperate.RedisHelper
TagDeviceId string
}
func (the Adaptor_AXY_LastRAW) Transform(topic, rawMsg string) *models.EsRaw {
iotaData := models.IotaData{}
json.Unmarshal([]byte(rawMsg), &iotaData)
err := json.Unmarshal([]byte(rawMsg), &iotaData)
if err != nil {
log.Printf("反序列化 异常 dev数据=%s", rawMsg)
return nil
}
if iotaData.DeviceId == the.TagDeviceId {
log.Printf("--> Transform 标记设备数据 [%s] %s ", iotaData.DeviceId, rawMsg)
}
return the.raw2es(iotaData)
}
@ -60,6 +68,9 @@ func (the Adaptor_AXY_LastRAW) raw2es(iotaData models.IotaData) *models.EsRaw {
DimensionId: iotaData.DimensionId,
DataType: dataType,
}
if iotaData.DeviceId == the.TagDeviceId {
log.Printf("--> raw2es 标记设备[%s]数据 %v ", iotaData.DeviceId, iotaData.Data.Data)
}
EsRaws := toEsRaw(devdata)
return EsRaws
}

5
consumers/consumerAXYraw.go

@ -36,7 +36,7 @@ func (the *consumerAXYraw) LoadConfigJson(cfgStr string) {
func (the *consumerAXYraw) Initial(cfg string) error {
the.sinkRawMap = sync.Map{}
the.dataCache = make(chan *models.EsRaw, 200)
the.dataCache = make(chan *models.EsRaw, 500)
the.LoadConfigJson(cfg)
err := the.inputInitial()
@ -147,7 +147,8 @@ func (the *consumerAXYraw) onData(topic string, msg string) bool {
// log.Printf("recv:[%s]:%s ...", topic, msg[:80])
//}
adaptor := adaptors.Adaptor_AXY_LastRAW{
Redis: the.infoRedis,
Redis: the.infoRedis,
TagDeviceId: logTagDeviceId,
}
needPush := adaptor.Transform(topic, msg)

8
main_test.go

@ -6,7 +6,7 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"goInOut/consumers/GZG2ZJHL/protoFiles_zjhl"
"goInOut/consumers/GZG2ZJHL/protoFiles_zjhl/protoFiles_zjhl_v3"
"goInOut/utils"
"google.golang.org/protobuf/proto"
"log"
@ -97,7 +97,7 @@ func TestDeRC4(b *testing.T) {
println("无crc", hex.EncodeToString(RawBytesNoCrc))
println("=========")
complexData := &protoFiles_zjhl.ComplexData{}
complexData := &protoFiles_zjhl_v3.ComplexData{}
err := proto.Unmarshal(RawBytesNoCrc, complexData)
if err != nil {
println(err.Error())
@ -128,7 +128,7 @@ func TestDeRC4_2(b *testing.T) {
println("无crc", hex.EncodeToString(RawBytesNoCrc))
println("=========")
complexData := &protoFiles_zjhl.ComplexData{}
complexData := &protoFiles_zjhl_v3.ComplexData{}
err := proto.Unmarshal(RawBytesNoCrc, complexData)
if err != nil {
println(err.Error())
@ -138,7 +138,7 @@ func TestDeRC4_2(b *testing.T) {
func TestProtobufDe(t *testing.T) {
s := "0a3508011a1c10c7e84318e6b4e3b6d332220f0dcdcc8c3f15333353401dcdcc0c40721331313131313131313131313131313131313131"
bs, _ := hex.DecodeString(s)
complexData := &protoFiles_zjhl.ComplexData{}
complexData := &protoFiles_zjhl_v3.ComplexData{}
err := proto.Unmarshal(bs, complexData)
if err != nil {
println(err.Error())

Loading…
Cancel
Save