mark
This commit is contained in:
parent
13075f4507
commit
0134203b0c
@ -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<Event> events, String measurement){
|
||||
// List<Point> 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<Event> events, String measurement){
|
||||
List<Point> list = new ArrayList<>();
|
||||
for(Event event:events){
|
||||
@ -99,18 +110,6 @@ public enum InfluxClient {
|
||||
}
|
||||
writeApi.writePoints(list);
|
||||
}
|
||||
public void batchInsertString(List<EventString> events, String measurement){
|
||||
List<Point> 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<FluxTable> query(QueryDataParam param){
|
||||
String measurement = param.getMeasurement();
|
||||
|
@ -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");
|
||||
}
|
||||
|
@ -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<Event> list;
|
||||
String measurement;
|
||||
|
@ -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<EventString> list;
|
||||
String measurement;
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user