commit()yml

pull/4/head
张腾 2024-09-30 09:03:17 +08:00
parent 25bc628f8f
commit 6f52789cc0
11 changed files with 115 additions and 19 deletions

View File

@ -92,5 +92,9 @@
<artifactId>iotdb-session</artifactId>
<version>0.13.1</version>
</dependency>
<dependency>
<groupId>com.muyu</groupId>
<artifactId>cloud-common-rabbit</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -1,5 +1,6 @@
package com.muyu.carData;
import com.muyu.carData.listener.MyListener;
import com.muyu.common.security.annotation.EnableMyFeignClients;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@ -19,7 +20,8 @@ import javax.swing.*;
public class CarDataApplication {
public static void main(String[] args) {
SpringApplication.run(CarDataApplication.class,args);
System.out.println("caused: Handler dispatch failed; nested exception is java.lang.NoSuchMethodError: java.nio.ByteBuffer.flip()Ljava/nio/ByteBuffer;;caused: java.nio.ByteBuffer.flip()Ljava/nio/ByteBuffer;");
SpringApplication application = new SpringApplication(CarDataApplication.class);
application.addListeners(new MyListener());
application.run(args);
}
}

View File

@ -28,7 +28,7 @@ public class KafkaConfig {
//生产者可用于缓冲等待发送到服务器的记录的总内存字节数
configs.put("buffer-memory",3554432);
/**
*producerleader,
* ,
*acks=0,0,producer.(socket)
* .,,(retries)(),-1.
*acks=1,1,leader,followerproducer.,

View File

@ -15,7 +15,7 @@ import org.springframework.stereotype.Component;
import java.time.Duration;
import java.util.Collection;
/**
/**
* @Author
* @Packagecom.muyu.carData.consumer
* @Projectcloud-server-8

View File

@ -1,4 +1,4 @@
package com.muyu.carData.testcontroller;
package com.muyu.carData.controller;
import com.github.benmanes.caffeine.cache.Cache;
import com.muyu.carData.config.cacheconfig.CaffeineConfig;

View File

@ -1,4 +1,4 @@
package com.muyu.carData.testcontroller;
package com.muyu.carData.controller;
import com.muyu.carData.config.lotdbconfig.IotDBSessionConfig;
import lombok.extern.log4j.Log4j2;
@ -44,11 +44,13 @@ public class IotDBController {
@GetMapping("/insertData/{insertSize}/{count}")
public String insert(@PathVariable(name = "insertSize") int insertSize,@PathVariable(name = "count") int count) throws IoTDBConnectionException, StatementExecutionException {
Session session = iotDBSessionConfig.iotSession();
//schemaList 属性及类型
List<MeasurementSchema> schemaList = new ArrayList<>();
schemaList.add(new MeasurementSchema("id", TSDataType.INT32));
schemaList.add(new MeasurementSchema("name", TSDataType.TEXT));
schemaList.add(new MeasurementSchema("sex", TSDataType.TEXT));
//tablet 封装数据
Tablet tablet = new Tablet("root.yang.baling", schemaList);
//以当前时间戳作为插入的起始时间戳

View File

@ -1,7 +1,6 @@
package com.muyu.carData.testcontroller;
package com.muyu.carData.controller;
import com.alibaba.fastjson.JSONObject;
import com.muyu.carData.pojo.Student;
import lombok.extern.log4j.Log4j2;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerRecord;
@ -25,21 +24,15 @@ public class KafkaProducerController {
@Autowired
private KafkaProducer kafkaProducer;
private final String topicName = "test";
private final String topicName = "carJsons";
@GetMapping("/produceTest")
public String produceTest() {
@GetMapping("/producer")
public String produceTest(JSONObject data) {
try {
Student stu = Student.builder().id(2)
.name("杨闪闪")
.sex("男")
.build();
String stuStr = JSONObject.toJSONString(stu);
log.info("Topic:{}", topicName);
log.info("Java对象{}",stu);
log.info("转换为JSON{}",stuStr);
log.info("转换为JSON{}",data);
//使用KafkaProducer发送消息
ProducerRecord<String, String> stringProducerRecord = new ProducerRecord<>(topicName, stuStr);
ProducerRecord<String, String> stringProducerRecord = new ProducerRecord(topicName, data);
kafkaProducer.send(stringProducerRecord);
}catch (Exception e){
log.error("Producer写入Topic异常,异常信息是:{}",e.getMessage());
@ -47,4 +40,6 @@ public class KafkaProducerController {
return "消息发送成功";
}
}

View File

@ -0,0 +1,22 @@
package com.muyu.carData.event;
import com.alibaba.fastjson.JSONObject;
import org.springframework.context.ApplicationEvent;
/**
* @Author
* @Packagecom.muyu.carData.event
* @Projectcloud-server-8
* @nameEsSaveEvent
* @Date2024/9/29 21:15
*/
public class EsSaveEvent extends ApplicationEvent {
private JSONObject data;
public EsSaveEvent(JSONObject source) {
super(source);
this.data = source;
}
}

View File

@ -0,0 +1,22 @@
package com.muyu.carData.listener;
import com.muyu.carData.event.EsSaveEvent;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
/**
* @Author
* @Packagecom.muyu.carData.listener
* @Projectcloud-server-8
* @nameCustomEventListener
* @Date2024/9/29 23:49
*/
@Component
public class CustomEventListener {
@EventListener
public void handMyEvent(EsSaveEvent event){
//处理事件详情
}
}

View File

@ -0,0 +1,20 @@
package com.muyu.carData.listener;
import com.muyu.carData.event.EsSaveEvent;
import lombok.extern.log4j.Log4j2;
import org.springframework.context.ApplicationListener;
/**
* @Author
* @Packagecom.muyu.carData.listener
* @Projectcloud-server-8
* @nameMyListener
* @Date2024/9/29 21:18
*/
@Log4j2
public class MyListener implements ApplicationListener<EsSaveEvent> {
@Override
public void onApplicationEvent(EsSaveEvent event) {
log.info("监听到自定义事件........");
}
}

View File

@ -0,0 +1,29 @@
package com.muyu.carData.pulisher;
import com.alibaba.fastjson.JSONObject;
import com.muyu.carData.event.EsSaveEvent;
import lombok.AllArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Component;
/**
* @Author
* @Packagecom.muyu.carData.pulisher
* @Projectcloud-server-8
* @nameCustomEventPublisher
* @Date2024/9/29 23:51
*/
@Log4j2
@Component
@AllArgsConstructor
public class CustomEventPublisher {
private ApplicationEventPublisher applicationEventPublisher;
public void publish(JSONObject data){
EsSaveEvent esSaveEvent = new EsSaveEvent(data);
applicationEventPublisher.publishEvent(esSaveEvent);
log.info("事件发布成功 - 消息是:{}",data);
}
}