From 0134203b0c64cce2ae72fe32a42ca3e1bb346ae8 Mon Sep 17 00:00:00 2001 From: caixiang <939387484@qq.com> Date: Tue, 18 Oct 2022 09:15:23 +0800 Subject: [PATCH] mark --- .../qgs/dc/influx/config/InfluxClient.java | 27 +++++++++---------- .../controller/InfluxDemoController.java | 11 +++----- .../com/qgs/dc/influx/param/InsertParam.java | 2 -- .../dc/influx/param/InsertParamString.java | 19 ------------- .../com/qgs/dc/influx/template/Event.java | 6 +---- .../qgs/dc/influx/template/EventString.java | 23 ---------------- 6 files changed, 17 insertions(+), 71 deletions(-) delete mode 100644 src/main/java/com/qgs/dc/influx/param/InsertParamString.java delete mode 100644 src/main/java/com/qgs/dc/influx/template/EventString.java diff --git a/src/main/java/com/qgs/dc/influx/config/InfluxClient.java b/src/main/java/com/qgs/dc/influx/config/InfluxClient.java index 94a166c..cc8afe9 100644 --- a/src/main/java/com/qgs/dc/influx/config/InfluxClient.java +++ b/src/main/java/com/qgs/dc/influx/config/InfluxClient.java @@ -12,7 +12,6 @@ import com.qgs.dc.influx.param.PageInfo; import com.qgs.dc.influx.param.QueryDataParam; import com.qgs.dc.influx.param.Range; import com.qgs.dc.influx.template.Event; -import com.qgs.dc.influx.template.EventString; import java.util.ArrayList; import java.util.List; @@ -22,7 +21,7 @@ public enum InfluxClient { /** * influxdb 读写客户端,,如果write比较繁忙,后续可以考虑,维护 client一个线程池。 * */ - Client("http://192.168.0.170:8086","lkBsC27QZr1W50BSPlGxpTqNNpwuUk5uz1dZZRPSPbCG5VmNDDUo8P3UkZIhGWwfJwkuz6ZGZ7Et4_KBaG3gHw==","qgs","qgs-bucket"), + Client("http://192.168.0.170:8086","lkBsC27QZr1W50BSPlGxpTqNNpwuUk5uz1dZZRPSPbCG5VmNDDUo8P3UkZIhGWwfJwkuz6ZGZ7Et4_KBaG3gHw==","qgs","qgs-bucket2"), ; private String url; @@ -87,6 +86,18 @@ public enum InfluxClient { //异步 批量写入数据 //如果要批量插入的话,一次也只能写入 +// public void batchInsert(List events, String measurement){ +// List list = new ArrayList<>(); +// for(Event event:events){ +// Point point = Point.measurement(measurement) +// .addTag("transationId", event.getTransationId()) +// .addTag("argName", event.getArgName()) +// .addField("argValue", event.getArgValue()) +// .time(event.getTime().toEpochMilli(), WritePrecision.MS); +// list.add(point); +// } +// writeApi.writePoints(list); +// } public void batchInsert(List events, String measurement){ List list = new ArrayList<>(); for(Event event:events){ @@ -99,18 +110,6 @@ public enum InfluxClient { } writeApi.writePoints(list); } - public void batchInsertString(List events, String measurement){ - List list = new ArrayList<>(); - for(EventString event:events){ - Point point = Point.measurement(measurement) - .addTag("transationId", event.getTransationId()) - .addTag("argName", event.getArgName()) - .addField("argValue", event.getArgValue()) - .time(event.getTime().toEpochMilli(), WritePrecision.MS); - list.add(point); - } - writeApi.writePoints(list); - } public List query(QueryDataParam param){ String measurement = param.getMeasurement(); diff --git a/src/main/java/com/qgs/dc/influx/controller/InfluxDemoController.java b/src/main/java/com/qgs/dc/influx/controller/InfluxDemoController.java index 517703b..1f5bc18 100644 --- a/src/main/java/com/qgs/dc/influx/controller/InfluxDemoController.java +++ b/src/main/java/com/qgs/dc/influx/controller/InfluxDemoController.java @@ -7,7 +7,6 @@ import com.influxdb.query.FluxTable; import com.qgs.dc.influx.config.InfluxClient; import com.qgs.dc.influx.param.*; import com.qgs.dc.influx.template.Event; -import com.qgs.dc.influx.template.EventString; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.web.bind.annotation.PostMapping; @@ -76,7 +75,7 @@ public class InfluxDemoController { event.setTransationId("S1"); event.setTime(new Date().toInstant()); event.setArgName("A1"); - event.setArgValue((double)3); + event.setArgValue("3"); Thread.sleep(100); @@ -84,7 +83,7 @@ public class InfluxDemoController { event2.setTransationId("S1"); event2.setTime(new Date().toInstant()); event2.setArgName("A2"); - event2.setArgValue((double)4); + event2.setArgValue("4"); list.add(event); list.add(event2); @@ -94,10 +93,6 @@ public class InfluxDemoController { } - @PostMapping("/insertBatchString") - public void insertBatchString(@RequestBody InsertParamString insertParam) throws InterruptedException { - InfluxClient.Client.batchInsertString(insertParam.getList(),insertParam.getMeasurement()); - } public Point insert(Event event, String measurement){ Point point = Point.measurement(measurement) @@ -116,7 +111,7 @@ public class InfluxDemoController { event.setTime(Instant.now()); event.setTransationId("asasd11"); event.setArgName("argName11"); - event.setArgValue(99765d); + event.setArgValue("898989"); Point asProcessCompleteEvent = insert(event, "ASProcessCompleteEvent"); InfluxClient.Client.insert(event,"ASProcessCompleteEvent"); } diff --git a/src/main/java/com/qgs/dc/influx/param/InsertParam.java b/src/main/java/com/qgs/dc/influx/param/InsertParam.java index 06696d7..58d462d 100644 --- a/src/main/java/com/qgs/dc/influx/param/InsertParam.java +++ b/src/main/java/com/qgs/dc/influx/param/InsertParam.java @@ -1,6 +1,5 @@ package com.qgs.dc.influx.param; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; import com.qgs.dc.influx.template.Event; import lombok.Data; @@ -12,7 +11,6 @@ import java.util.List; * @DATE: 2022/10/13 16:10 */ @Data -@JsonPropertyOrder(value = {"list","measurement"}) public class InsertParam { List list; String measurement; diff --git a/src/main/java/com/qgs/dc/influx/param/InsertParamString.java b/src/main/java/com/qgs/dc/influx/param/InsertParamString.java deleted file mode 100644 index b668f28..0000000 --- a/src/main/java/com/qgs/dc/influx/param/InsertParamString.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.qgs.dc.influx.param; - -import com.fasterxml.jackson.annotation.JsonPropertyOrder; -import com.qgs.dc.influx.template.Event; -import com.qgs.dc.influx.template.EventString; -import lombok.Data; - -import java.util.List; - -/** - * @Desc: "" - * @Author: caixiang - * @DATE: 2022/10/13 16:10 - */ -@Data -public class InsertParamString { - List list; - String measurement; -} diff --git a/src/main/java/com/qgs/dc/influx/template/Event.java b/src/main/java/com/qgs/dc/influx/template/Event.java index 4a472c4..1ec6b76 100644 --- a/src/main/java/com/qgs/dc/influx/template/Event.java +++ b/src/main/java/com/qgs/dc/influx/template/Event.java @@ -1,8 +1,5 @@ package com.qgs.dc.influx.template; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; -import com.influxdb.annotations.Column; -import com.influxdb.annotations.Measurement; import lombok.Data; import java.time.Instant; @@ -13,7 +10,6 @@ import java.time.Instant; * @DATE: 2022/6/25 11:13 */ @Data -@JsonPropertyOrder(value = {"time","transationId","argName","argValue"}) public class Event { private Instant time; @@ -22,5 +18,5 @@ public class Event { private String argName; - private Double argValue; + private String argValue; } diff --git a/src/main/java/com/qgs/dc/influx/template/EventString.java b/src/main/java/com/qgs/dc/influx/template/EventString.java deleted file mode 100644 index 4bf1890..0000000 --- a/src/main/java/com/qgs/dc/influx/template/EventString.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.qgs.dc.influx.template; - -import com.fasterxml.jackson.annotation.JsonPropertyOrder; -import lombok.Data; - -import java.time.Instant; - -/** - * @Desc: "" - * @Author: caixiang - * @DATE: 2022/6/25 11:13 - */ -@Data -public class EventString { - - private Instant time; - - private String transationId; - - private String argName; - - private String argValue; -}