This commit is contained in:
959814898@qq.com
2023-07-22 22:35:18 +08:00
parent f978245495
commit ec6035d80f
35 changed files with 1076 additions and 202 deletions
+7
View File
@@ -15,5 +15,12 @@
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>io.minio</groupId>
<artifactId>minio</artifactId>
<version>8.4.3</version>
</dependency>
</dependencies>
</project>
@@ -0,0 +1,125 @@
package com.wyl.file.sequence;
import io.minio.*;
import okhttp3.OkHttpClient;
import javax.net.ssl.*;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.Objects;
/**
* Java MinIO Client
*
* 上传文件到指定Bucket桶。
*/
public class MinIOUploadFile {
private static MinioClient minioClient;
private static final String END_POINT = "https://oss.test_minio.com:39000";
private static final String AK = "aul30E0ccjbxUm5dor6z";
private static final String SK = "2Fl58bDxeApSYyIHvOSzd0BBifrtwOESuhrl1Q25!@#";
private static final String DEFAULT_BUCKET = "";
private static final String REGION = "cn-global-123456";
public static void main(String[] args) throws Exception {
MinIOUploadFile client = new MinIOUploadFile();
client.initConfig();
// 查询指定region中是否存在tx-bucket桶
if (!client.isExistBucket(DEFAULT_BUCKET, REGION)) {
// 桶不存在,创建桶
client.createBucket(DEFAULT_BUCKET, REGION);
}
// 上传文件到指定的桶
client.uploadFileToBucket(DEFAULT_BUCKET, "C:\\Users\\Administrator\\Downloads\\CN_ORDERACK_07f601bc-fb56-48d9-9a8d-c9ec7dd95872.pdf", "CN_ORDERACK_07f601bc-fb56-48d9-9a8d-c9ec7dd95872.pdf");
}
/**
* 初始化MinIO的配置
*/
private void initConfig() throws KeyManagementException {
minioClient = MinioClient.builder()
.endpoint(END_POINT)
.credentials(AK, SK)
.region(REGION) // 自定义region
.httpClient(Objects.requireNonNull(getUnsafeOkHttpsClient()))
.build();
}
/**
* 判断指定的桶是否存在
*
* @param bucketName 桶名称
* @param region 区域
* @return 存在true,否则false
*/
private boolean isExistBucket(String bucketName, String region) throws Exception {
return minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucketName).region(region).build());
}
/**
* 创建指定名称的桶
*
* @param bucketName 桶名称
* @param region 区域
*/
private void createBucket(String bucketName, String region) throws Exception {
minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucketName).region(region).build());
}
private void uploadFileToBucket(String bucketName, String object, String fileName) throws Exception {
minioClient.uploadObject(UploadObjectArgs.builder()
.bucket(bucketName)
.filename(object)
.object(fileName)
.build());
}
public static OkHttpClient getUnsafeOkHttpsClient() throws KeyManagementException {
try {
final TrustManager[] trustAllCerts = new TrustManager[]{
new X509TrustManager() {
@Override
public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
}
@Override
public void checkServerTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
}
@Override
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[]{};
}
}
};
final SSLContext sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, trustAllCerts, new SecureRandom());
final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
OkHttpClient.Builder builder = new OkHttpClient.Builder();
builder.sslSocketFactory(sslSocketFactory);
builder.hostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String s, SSLSession sslSession) {
return true;
}
});
return builder.build();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return null;
}
}
@@ -27,7 +27,6 @@ class Solution {
}
public static void main(String[] args) {
int i = lengthOfLongestSubstring("tmmzuxt");
System.out.println(i);
}
}
+13 -4
View File
@@ -19,10 +19,19 @@
<dependencies>
<dependency>
<groupId>org.opencv</groupId>
<artifactId>opencv</artifactId>
<version>470</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/opencv-470.jar</systemPath>
<artifactId>opencv-480</artifactId>
<version>1.0.0</version>
</dependency>
<!--JAVA使用javacv实现图片合成短视频,相关JAR包-->
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>javacv</artifactId>
<version>1.5.9</version>
</dependency>
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>javacv-platform</artifactId>
<version>1.5.9</version>
</dependency>
</dependencies>
</project>
@@ -1,49 +1,50 @@
package com.wyl.javacv;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.core.MatOfByte;
import org.opencv.highgui.HighGui;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.net.URL;
public class DemoApplicationTests {
/**
* @return
* @Description
* @Param
* @Author zhangsan
* @Date 2020.09.05 9:43
**/
public static void main(String[] args) throws Exception {
// 解决awt报错问题
// 加载动态库
URL url = ClassLoader.getSystemResource("opencv_java470.dll");
System.load(url.getPath());
// 读取图像
// Mat image = Imgcodecs.imread("D:\\1.jpg");
File file = new File("D:/1.jpg");
InputStream fos = new FileInputStream(file);
Mat image = Imgcodecs.imdecode(new MatOfByte(fos.readAllBytes()), Imgcodecs.IMREAD_COLOR);
if (image.empty()) {
throw new Exception("image is empty");
}
HighGui.imshow("Original Image", image);
// 创建输出单通道图像
Mat grayImage = new Mat(image.rows(), image.cols(), CvType.CV_8SC1);
// 进行图像色彩空间转换
Imgproc.cvtColor(image, grayImage, Imgproc.COLOR_RGB2GRAY);
HighGui.imshow("Processed Image", grayImage);
Imgcodecs.imwrite("D:/hello.jpg", grayImage);
HighGui.waitKey();
}
}
//package com.wyl.javacv;
//
//
//import org.opencv.core.CvType;
//import org.opencv.core.Mat;
//import org.opencv.core.MatOfByte;
//import org.opencv.highgui.HighGui;
//import org.opencv.imgcodecs.Imgcodecs;
//import org.opencv.imgproc.Imgproc;
//import org.opencv.videoio.VideoWriter;
//
//import java.io.File;
//import java.io.FileInputStream;
//import java.io.InputStream;
//import java.net.URL;
//
//
//public class DemoApplicationTests {
// /**
// * @return
// * @Description
// * @Param
// * @Author zhangsan
// * @Date 2020.09.05 9:43
// **/
// public static void main(String[] args) throws Exception {
// // 解决awt报错问题
// // 加载动态库
// URL url = ClassLoader.getSystemResource("opencv_java480.dll");
// System.load(url.getPath());
// // 读取图像
//// Mat image = Imgcodecs.imread("D:\\1.jpg");
// File file = new File("C:\\Users\\95981\\Desktop\\Mattingfailure.jpg");
// InputStream fos = new FileInputStream(file);
// Mat image = Imgcodecs.imdecode(new MatOfByte(fos.readAllBytes()), Imgcodecs.IMREAD_COLOR);
// if (image.empty()) {
// throw new Exception("image is empty");
// }
// HighGui.imshow("Original Image", image);
//
// // 创建输出单通道图像
// Mat grayImage = new Mat(image.rows(), image.cols(), CvType.CV_8SC1);
// // 进行图像色彩空间转换
// Imgproc.cvtColor(image, grayImage, Imgproc.COLOR_RGB2GRAY);
//
// HighGui.imshow("Processed Image", grayImage);
// Imgcodecs.imwrite("D:/hello.jpg", grayImage);
// HighGui.waitKey();
// }
//}
@@ -0,0 +1,58 @@
package com.wyl.javacv;
import org.opencv.core.Mat;
import org.opencv.core.MatOfByte;
import org.opencv.core.Size;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.videoio.VideoWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
public class ImageToVideoConverter {
public static void main(String[] args) throws IOException {
URL url = ClassLoader.getSystemResource("opencv_java480.dll");
System.load(url.getPath());
String imageFolderPath = "C:\\Users\\95981\\Desktop\\picture"; // 你的图片文件夹路径
String outputVideoPath = "C:\\Users\\95981\\Desktop\\vidoe\\video14.mp4"; // 输出视频文件路径
try {
Size frameSize = new Size(910, 910); // 设置视频帧的大小(根据你的图片大小进行调整)
int fps = 15; // 视频帧率
int x = VideoWriter.fourcc('D', 'I', 'V', 'X');
VideoWriter videoWriter = new VideoWriter(outputVideoPath, x, fps, frameSize, true);
// 获取图片文件列表
File imageFolder = new File(imageFolderPath);
File[] imageFiles = imageFolder.listFiles();
if (imageFiles != null) {
for (File imageFile : imageFiles) {
if (imageFile.isFile()) {
// Mat image = Imgcodecs.imread(imageFile.getAbsolutePath());
InputStream fos = new FileInputStream(imageFile);
Mat image = Imgcodecs.imdecode(new MatOfByte(fos.readAllBytes()), Imgcodecs.IMREAD_COLOR);
if (!image.empty()) {
// 调整图片大小,以适应视频帧大小(可选,如果图片与视频帧大小相同,可省略)
// Imgproc.resize(image, image, frameSize);
videoWriter.write(image);
image.release();
}
}
}
videoWriter.release(); // 释放VideoWriter资源
System.out.println("Video created successfully!");
} else {
System.out.println("No image files found in the folder.");
}
} catch (Exception e) {
File file = new File(outputVideoPath);
file.deleteOnExit();
}
}
}
@@ -0,0 +1,76 @@
package com.wyl.javacv;
import org.bytedeco.ffmpeg.global.avcodec;
import org.bytedeco.ffmpeg.global.avutil;
import org.bytedeco.javacv.FFmpegFrameRecorder;
import org.bytedeco.javacv.FrameRecorder;
import org.bytedeco.javacv.Java2DFrameConverter;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
public class JavaCvTest {
public static void main(String[] args) throws Exception {
//合成的MP4 存放的地址路径 这里的路径并不会自动创建,需要手动提前创建好,否则会报错:Could not open 'null'
String mp4SavePath = "C:\\Users\\95981\\Desktop\\vidoe\\img2.mp4";
//图片存放的地址路径
String img = "C:\\Users\\95981\\Desktop\\picture";
int width = 910;
int height = 910;
//读取所有图片
File file = new File(img);
File[] files = file.listFiles();
Map<Integer, File> imgMap = new HashMap<Integer, File>();
int num = 0;
for (File imgFile : files) {
imgMap.put(num, imgFile);
num++;
}
createMp4(mp4SavePath, imgMap, width, height);
}
private static void createMp4(String mp4SavePath, Map<Integer, File> imgMap, int width, int height) throws FrameRecorder.Exception {
//视频宽高最好是按照常见的视频的宽高 16:9 或者 9:16
FFmpegFrameRecorder recorder = new FFmpegFrameRecorder(mp4SavePath, width, height);
int bitrate = 1000000;
//设置视频编码层模式 import org.bytedeco.ffmpeg.global.avcodec;可能需要手动复制添加
recorder.setVideoCodec(avcodec.AV_CODEC_ID_H264);
//设置视频为25帧每秒
recorder.setFrameRate(15);
//设置视频图像数据格式 import org.bytedeco.ffmpeg.global.avutil;可能需要手动复制添加
recorder.setPixelFormat(avutil.AV_PIX_FMT_YUV420P);
recorder.setVideoBitrate(bitrate);
recorder.setFormat("mp4");
try {
recorder.start();
Java2DFrameConverter converter = new Java2DFrameConverter();
//录制一个22秒的视频,22秒为自定义的一个视频时间长度,图片少则在22秒内,多则到22秒停止
imgMap.entrySet().stream().forEach(e -> {
BufferedImage read = null;
try {
read = ImageIO.read(e.getValue());
} catch (IOException ioException) {
ioException.printStackTrace();
}
try {
recorder.record(converter.getFrame(read));
} catch (FrameRecorder.Exception exception) {
exception.printStackTrace();
}
});
} catch (Exception e) {
e.printStackTrace();
} finally {
//最后一定要结束并释放资源
recorder.stop();
recorder.release();
}
}
}
Binary file not shown.
Binary file not shown.
+6 -1
View File
@@ -20,7 +20,12 @@
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>5.13.0</version>
<version>5.2.0</version>
</dependency>
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna-platform</artifactId>
<version>5.2.0</version>
</dependency>
</dependencies>
</project>
@@ -0,0 +1,18 @@
package com.wyl.jna;
import com.sun.jna.Pointer;
import com.sun.jna.Structure;
import java.util.Arrays;
import java.util.List;
public class BmpData extends Structure {
public Pointer data;
public int size;
@Override
protected List getFieldOrder() {
return Arrays.asList(new String[]{"data", "size"});
}
}
+26
View File
@@ -0,0 +1,26 @@
package com.wyl.jna;
import com.sun.jna.Library;
import com.sun.jna.Native;
public class Dll1 {
public interface Dll1lib extends Library {
Dll1lib INSTANCE = Native.load("Dll1", Dll1lib.class);
void fibonacci_init(int x, int y);
boolean fibonacci_next();
long fibonacci_current();
void fibonacci_index();
}
public static void main(String[] args) {
Dll1lib.INSTANCE.fibonacci_init(6, 7);
long a = Dll1lib.INSTANCE.fibonacci_current();
boolean b = Dll1lib.INSTANCE.fibonacci_next();
System.out.println(a);
System.out.println(b);
}
}
+105 -3
View File
@@ -1,10 +1,112 @@
package com.wyl.jna;
import java.io.File;
import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.Pointer;
import java.io.FileOutputStream;
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
public class Main {
public static void main(String[] args) throws IOException {
File tempFile = File.createTempFile("file", ".dll");
public interface CLibrary extends Library {
CLibrary INSTANCE = (CLibrary)
Native.load("JavaImageDLL", CLibrary.class);
int getValue1();
BmpData getStruct1(String imagePath);
}
public static void main1(String[] args) {
System.setProperty("jna.debug_load", "true");
System.setProperty("jna.debug_load.jna", "true");
System.setProperty("jna.platform.library.path", "C:\\Users\\95981\\Desktop\\dll");
// int value1 = CLibrary.INSTANCE.getValue1();
// System.out.println(value1);
BmpData struct1 = CLibrary.INSTANCE.getStruct1("C:\\Users\\95981\\Desktop\\wangyongliang.jpg");
int datasize = struct1.size;
Pointer data = struct1.data;
byte[] byteArray = data.getByteArray(0, datasize);
String filePath = "C:\\Users\\95981\\Desktop\\wyl001.jpg"; // 替换为您要写入的文件路径
try (FileOutputStream fos = new FileOutputStream(filePath)) {
fos.write(byteArray);
System.out.println("字节数组成功写入文件。");
} catch (IOException e) {
System.out.println("写入文件时发生错误:" + e.getMessage());
}
// 将内存块转换为byte[]数组
}
public static void main123(String[] args) {
LocalDateTime fromDateTime = LocalDateTime.now();
LocalDateTime toDateTime = fromDateTime.plusDays(1).plusHours(6).plusMinutes(12);
LocalDateTime tempDateTime = LocalDateTime.from(fromDateTime);
ChronoUnit a = ChronoUnit.MINUTES;
long days = 0;
long hours = 0;
long minutes = 0;
long seconds = 0;
switch (a) {
case DAYS:
days = tempDateTime.until(toDateTime, ChronoUnit.DAYS);
tempDateTime = tempDateTime.plusDays(days);
case HOURS:
hours = tempDateTime.until(toDateTime, ChronoUnit.HOURS);
tempDateTime = tempDateTime.plusHours(hours);
case MINUTES:
minutes = tempDateTime.until(toDateTime, ChronoUnit.MINUTES);
tempDateTime = tempDateTime.plusMinutes(minutes);
case SECONDS:
seconds = tempDateTime.until(toDateTime, ChronoUnit.SECONDS);
}
System.out.println(
days + "" +
hours + " 小时 " +
minutes + "" +
seconds + " 秒.");
}
public static void main(String[] args) {
long minutes = 62;
String result = convertMinutesToUnits(minutes, ChronoUnit.DAYS);
System.out.println(result);
}
public static String convertMinutesToUnits(long minutes1, ChronoUnit maxUnit) {
long min = minutes1;
long days = 0;
long hours = 0;
long minutes = 0;
long secound = 0;
long millis = 0;
switch (maxUnit) {
case DAYS:
days = min / 1440;
min = min % 1440;
case HOURS:
hours = min / 60;
min = min % 60;
case MINUTES:
minutes = min / 1;
break;
case SECONDS:
secound = min * 60;
break;
case MILLIS:
millis = min * 6000;
}
String reult = days + "" +
hours + " 小时 " +
minutes + "" +
secound + "" +
millis + " 毫秒 ";
return reult;
}
}
@@ -1,9 +0,0 @@
package com.wyl.jna;
import com.sun.jna.Library;
import com.sun.jna.Native;
public interface MyLibrary extends Library {
MyLibrary INSTANCE = Native.load("mylibrary", MyLibrary.class);
void myFunction();
}
@@ -0,0 +1,28 @@
package com.wyl.jna;
import java.io.File;
public class RecursiveFileDeletion {
public static void main(String[] args) {
String targetDirectory = "C:\\Users\\95981\\Desktop\\文件\\10_565";
deleteFiles(targetDirectory);
System.out.println("Deletion complete.");
}
private static void deleteFiles(String directoryPath) {
File directory = new File(directoryPath);
File[] files = directory.listFiles();
if (files != null) {
for (File file : files) {
if (file.isDirectory()) {
if (!file.getName().equalsIgnoreCase("原图")) {
deleteFiles(file.getAbsolutePath());
}
} else {
System.out.println("Deleting: " + file.getAbsolutePath());
file.delete();
}
}
}
}
}
@@ -0,0 +1,28 @@
package com.wyl.jna;
import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.Platform;
/**
* @description: 调用系统库
* @author: wangyl
* @date: 2023/6/27
*/
public class UsageSystem {
public interface CLibrary extends Library {
CLibrary INSTANCE = (CLibrary)
Native.load((Platform.isWindows() ? "msvcrt" : "c"),
CLibrary.class);
void printf(String format, Object... args);
}
public static void main(String[] args) {
CLibrary.INSTANCE.printf("Hello, World\n");
for (int i = 0; i < args.length; i++) {
CLibrary.INSTANCE.printf("Argument %d: %s\n", i, args[i]);
}
}
}
@@ -0,0 +1,42 @@
package com.wyl.jna;
import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.Pointer;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
/**
* @description: 调用系统库
* @author: wangyl
* @date: 2023/6/27
*/
public class UsageTest {
public interface CLibrary extends Library {
CLibrary INSTANCE = Native.load("wyltest123", CLibrary.class);
// BmpData getStruct(String imagePath);
BmpData getStruct();
}
public static void main(String[] args) {
System.setProperty("jna.debug_load", "true");
System.setProperty("jna.debug_load.jna", "true");
System.setProperty("jna.library.path", "C:\\Users\\95981\\Desktop\\dll");
String inFilePath = "C:\\Users\\95981\\Desktop\\wangyongliang.jpg";
// BmpData struct1 = CLibrary.INSTANCE.getStruct(new String(inFilePath.getBytes(), StandardCharsets.UTF_8));
BmpData struct1 = CLibrary.INSTANCE.getStruct();
int datasize = struct1.size;
Pointer data = struct1.data;
byte[] byteArray = data.getByteArray(0, datasize);
String filePath = "C:\\Users\\95981\\Desktop\\wyl001.jpg"; // 替换为您要写入的文件路径
try (FileOutputStream fos = new FileOutputStream(filePath)) {
fos.write(byteArray);
System.out.println("字节数组成功写入文件。");
} catch (IOException e) {
System.out.println("写入文件时发生错误:" + e.getMessage());
}
}
}
Binary file not shown.
Binary file not shown.
+14 -2
View File
@@ -11,13 +11,25 @@
<artifactId>kafka</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-clients</artifactId>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>3.22.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.protobuf/protobuf-java-util -->
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java-util</artifactId>
<version>3.22.3</version>
</dependency>
</dependencies>
</project>
@@ -14,15 +14,17 @@ import java.util.stream.Stream;
/**
* kafka发送消息测试
* @ClassName: KafkaProducerSend
* @Date: 2022/4/12 15:18
*
* @author wangyl
* @version V1.0
* @ClassName: KafkaProducerSend
* @Date: 2022/4/12 15:18
*/
@Slf4j
public class KafkaConsumerPoll {
/**
* 消费者消费消息
*
* @param kafkaConsumerNormal
* @param topic
* @return void
@@ -32,18 +34,21 @@ public class KafkaConsumerPoll {
*/
public static void PollMessage(Consumer<String, String> kafkaConsumerNormal, String topic) {
//消费者消费消息
kafkaConsumerNormal.subscribe(Arrays.asList(topic));
// kafkaConsumerNormal.subscribe(Arrays.asList(topic));
TopicPartition topicPartition = new TopicPartition(topic, 1);
kafkaConsumerNormal.assign(Arrays.asList(topicPartition));
while (true) {
//消费消息
kafkaConsumerNormal.poll(Duration.ofMillis(100))
.forEach(record -> {
log.info("消费者消费消息:{},分区:{},topic{},offset:{}", record.value(), record.partition(), record.topic(), record.offset());
});
.forEach(record -> {
log.info("消费者消费消息:{},分区:{},topic{},offset:{}", record.value(), record.partition(), record.topic(), record.offset());
});
}
}
/**
* 同步手动提交
*
* @param kafkaConsumerNormal
* @param topic
* @return void
@@ -57,9 +62,9 @@ public class KafkaConsumerPoll {
while (true) {
//消费消息
kafkaConsumerNormal.poll(Duration.ofMillis(100))
.forEach(record -> {
log.info("消费者消费消息:{},分区:{},topic{},offset:{}", record.value(), record.partition(), record.topic(), record.offset());
});
.forEach(record -> {
log.info("消费者消费消息:{},分区:{},topic{},offset:{}", record.value(), record.partition(), record.topic(), record.offset());
});
kafkaConsumerNormal.commitSync();
}
@@ -67,6 +72,7 @@ public class KafkaConsumerPoll {
/**
* 同步手动提交offset
*
* @param kafkaConsumerNormal
* @param topic
* @return void
@@ -81,10 +87,10 @@ public class KafkaConsumerPoll {
while (true) {
//消费消息
kafkaConsumerNormal.poll(Duration.ofMillis(100))
.forEach(record -> {
log.info("消费者消费消息:{},分区:{},topic{},offset:{}", record.value(), record.partition(), record.topic(), record.offset());
offsets.put(new TopicPartition(record.topic(), record.partition()), new OffsetAndMetadata(record.offset() + 1));
});
.forEach(record -> {
log.info("消费者消费消息:{},分区:{},topic{},offset:{}", record.value(), record.partition(), record.topic(), record.offset());
offsets.put(new TopicPartition(record.topic(), record.partition()), new OffsetAndMetadata(record.offset() + 1));
});
kafkaConsumerNormal.commitSync(offsets);
offsets.clear();
}
@@ -92,6 +98,7 @@ public class KafkaConsumerPoll {
/**
* 异步提交,有回调
*
* @param kafkaConsumerNormal
* @param topic
* @return void
@@ -106,10 +113,10 @@ public class KafkaConsumerPoll {
while (true) {
//消费消息
kafkaConsumerNormal.poll(Duration.ofMillis(100))
.forEach(record -> {
log.info("消费者消费消息:{},分区:{},topic{},offset:{}", record.value(), record.partition(), record.topic(), record.offset());
offsets.put(new TopicPartition(record.topic(), record.partition()), new OffsetAndMetadata(record.offset() + 1));
});
.forEach(record -> {
log.info("消费者消费消息:{},分区:{},topic{},offset:{}", record.value(), record.partition(), record.topic(), record.offset());
offsets.put(new TopicPartition(record.topic(), record.partition()), new OffsetAndMetadata(record.offset() + 1));
});
kafkaConsumerNormal.commitAsync(offsets, (offsetsInfo, exception) -> {
if (exception != null) {
log.error("提交消息异常:{}", exception.getMessage());
@@ -122,6 +129,7 @@ public class KafkaConsumerPoll {
/**
* 异步回调offsets
*
* @param kafkaConsumerNormal
* @param topic
* @return void
@@ -135,15 +143,15 @@ public class KafkaConsumerPoll {
while (true) {
//消费消息
kafkaConsumerNormal.poll(Duration.ofMillis(100))
.forEach(record -> {
log.info("消费者消费消息:{},分区:{},topic{},offset:{}", record.value(), record.partition(), record.topic(), record.offset());
});
.forEach(record -> {
log.info("消费者消费消息:{},分区:{},topic{},offset:{}", record.value(), record.partition(), record.topic(), record.offset());
});
kafkaConsumerNormal.commitAsync();
}
}
public static void PollMessageSeek(Consumer<String, String> kafkaConsumerNormal, String topic,int partition,int offset) {
public static void PollMessageSeek(Consumer<String, String> kafkaConsumerNormal, String topic, int partition, int offset) {
//消费者消费消息
kafkaConsumerNormal.subscribe(Arrays.asList(topic), new ConsumerRebalanceListener() {
@Override
@@ -160,14 +168,14 @@ public class KafkaConsumerPoll {
while (true) {
//消费消息
kafkaConsumerNormal.poll(Duration.ofMillis(100))
.forEach(record -> {
log.info("消费者消费消息:{},分区:{},topic{},offset:{}", record.value(), record.partition(), record.topic(), record.offset());
});
.forEach(record -> {
log.info("消费者消费消息:{},分区:{},topic{},offset:{}", record.value(), record.partition(), record.topic(), record.offset());
});
kafkaConsumerNormal.commitAsync();
}
}
public static void PollMessageSeekBegin(Consumer<String, String> kafkaConsumerNormal, String topic,int partition) {
public static void PollMessageSeekBegin(Consumer<String, String> kafkaConsumerNormal, String topic, int partition) {
final TopicPartition topicPartition = new TopicPartition(topic, partition);
final List<TopicPartition> topicPartitions = Arrays.asList(topicPartition);
kafkaConsumerNormal.subscribe(Arrays.asList(topic), new ConsumerRebalanceListener() {
@@ -185,14 +193,14 @@ public class KafkaConsumerPoll {
while (true) {
//消费消息
kafkaConsumerNormal.poll(Duration.ofMillis(100))
.forEach(record -> {
log.info("消费者消费消息:{},分区:{},topic{},offset:{}", record.value(), record.partition(), record.topic(), record.offset());
});
.forEach(record -> {
log.info("消费者消费消息:{},分区:{},topic{},offset:{}", record.value(), record.partition(), record.topic(), record.offset());
});
kafkaConsumerNormal.commitAsync();
}
}
public static void PollMessageSeekEnd(Consumer<String, String> kafkaConsumerNormal, String topic,int partition) {
public static void PollMessageSeekEnd(Consumer<String, String> kafkaConsumerNormal, String topic, int partition) {
//消费者消费消息
final TopicPartition topicPartition = new TopicPartition(topic, partition);
final List<TopicPartition> topicPartitions = Arrays.asList(topicPartition);
@@ -211,9 +219,9 @@ public class KafkaConsumerPoll {
while (true) {
//消费消息
kafkaConsumerNormal.poll(Duration.ofMillis(100))
.forEach(record -> {
log.info("消费者消费消息:{},分区:{},topic{},offset:{}", record.value(), record.partition(), record.topic(), record.offset());
});
.forEach(record -> {
log.info("消费者消费消息:{},分区:{},topic{},offset:{}", record.value(), record.partition(), record.topic(), record.offset());
});
kafkaConsumerNormal.commitAsync();
}
}
@@ -8,10 +8,11 @@ import java.util.Properties;
/**
* kafak生产者示例
* @ClassName: KafkaProducer
* @Date: 2022/4/12 14:36
*
* @author wangyl
* @version V1.0
* @ClassName: KafkaProducer
* @Date: 2022/4/12 14:36
*/
public class KafkaProducerExample {
+107
View File
@@ -0,0 +1,107 @@
syntax = "proto3";
package ivf_tl_Entity.DTO;
//生成的java文件名
option java_package = "com.aivfo.data.transmission.entity.dto";
option java_outer_classname = "ImageDataDTO";
message ImageDTO {
/**
* tl设备编号
*/
string tlSn = 1;
/**
* 仓室编号:1-10
*/
int32 houseSn = 2;
/**
* well编号 1-16
*/
int32 wellSn = 3;
/**
* ccd编号
*/
string ccdSn = 4;
/**
* 原图名字
*/
string sourceImageName = 5;
/**
* 原图的本地路径(不是上传后的保存路径)
*/
string sourceImagePath = 6;
/**
* 原图宽
*/
int32 sourceImageWidth = 7;
/**
* 原图高
*/
int32 sourceImageHeight = 8;
/**
* 设备拍摄时间 格式2020-10-10 00:00:00
*/
string imageTime = 9;
/**
* 受精时间 格式2020-10-10 00:00:00
*/
string fertilizationTime = 10;
/**
* 对焦还是ccd拍照 1 自动对焦 0 CCD拍照
*/
int32 photographType = 11;
/**
* 拍照总层数
*/
int32 totalLayer = 12;
/**
* 图片层
*/
int32 pictureLayer = 13;
/**
* 垂直电机位置
*/
int32 shootingPosition = 14;
/**
* 是否是最清晰的(CCD拍照才有)0不是 1最清晰
*/
int32 clearest = 15;
/**
* 拍照结束标记 1 结束 0 未结束 (结束后开始更新对焦起点,ccd拍照结束开始合成视频)
*/
int32 end = 16;
/**
* 培养记录id
*/
uint64 embryoCultureRecordId = 17;
/**
* 胚胎id
*/
uint64 embryoId = 18;
/**
* 图片数据
*/
bytes imageData = 19;
/**
* 水平电机位置
*/
int32 horizontalPosition = 20;
}
@@ -12,9 +12,11 @@ import org.apache.kafka.clients.consumer.KafkaConsumer;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.common.TopicPartition;
import org.junit.jupiter.api.Test;
import java.io.*;
import java.time.Duration;
import java.util.Arrays;
import java.util.Properties;
@@ -70,7 +72,7 @@ public class ConsumerTest {
}
/**
* 移动到指定问位置消费消息
* 移动到指定问位置消费消息
*/
@Test
public void pollMessageSeekTest() {
@@ -79,7 +81,7 @@ public class ConsumerTest {
}
/**
* 移动到开始位置消费消息
* 移动到开始位置消费消息
*/
@Test
public void pollMessageSeekBeginTest() {
@@ -88,7 +90,7 @@ public class ConsumerTest {
}
/**
* 移动到结束位置消费消息
* 移动到结束位置消费消息
*/
@Test
public void pollMessageCommitSeekEndTest() {
@@ -102,27 +104,21 @@ public class ConsumerTest {
// 创建 Kafka 消费者配置
Properties consumerProps = new Properties();
consumerProps.put("bootstrap.servers", "localhost:9092");
consumerProps.put("bootstrap.servers", "192.168.31.89:9092");
consumerProps.put("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
consumerProps.put("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
consumerProps.put("group.id","test");
consumerProps.put("group.id", "test");
consumerProps.put("max.request.size", "2097152");
// 创建 Kafka 生产者和消费者
KafkaConsumer<String, String> consumer = new KafkaConsumer<>(consumerProps);
TopicPartition topicPartition = new TopicPartition("wyl_topic", 1);
consumer.assign(Arrays.asList(topicPartition));
// 接收图片消息从 Kafka
consumer.subscribe(Arrays.asList("wyl-events"));
while (true) {
ConsumerRecords<String, String> records = consumer.poll(100);
ConsumerRecords<String, String> records = consumer.poll(Duration.ofMillis(100));
for (ConsumerRecord<String, String> record : records) {
byte[] imageBytes = record.value().getBytes(ISO_8859_1);
// 将图片字节数组保存到文件中
// 这里假设图片文件名为 received-image.jpg
File receivedFile = new File("/Users/wyl/Desktop/wyl01.png");
FileOutputStream fileOutputStream = new FileOutputStream(receivedFile);
fileOutputStream.write(imageBytes);
fileOutputStream.close();
System.out.println(11);
String value = record.value();
System.out.println(value);
}
}
}
@@ -1,18 +1,22 @@
package com.wyl.kafka.test;
import com.google.protobuf.ByteString;
import com.wyl.kafka.producers.KafkaProducerExample;
import com.wyl.kafka.producers.KafkaProducerSend;
import jdk.jfr.internal.tool.Main;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.junit.jupiter.api.Test;
import java.io.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.Properties;
@@ -31,73 +35,4 @@ public class ProducerTest {
final Producer<String, String> stringStringProducer = KafkaProducerExample.KafkaProducerTransactional();
KafkaProducerSend.sendMessageTransactional(stringStringProducer, TOPIC_NAME, "test123");
}
@Test
public void imageSend() throws IOException, InterruptedException {
// 创建 Kafka 生产者配置
Properties producerProps = new Properties();
producerProps.put("bootstrap.servers", "localhost:9092");
producerProps.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
producerProps.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
producerProps.put("max.request.size", "2097152");
// 创建 Kafka 生产者和消费者
KafkaProducer<String, String> producer = new KafkaProducer<>(producerProps);
// 发送图片消息到 Kafka
File file = new File("/Users/wyl/Desktop/wyl.png");
InputStream inputStream = new FileInputStream(file);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, bytesRead);
}
byte[] imageData = outputStream.toByteArray();
String s = new String(imageData,StandardCharsets.ISO_8859_1);
ProducerRecord<String, String> record = new ProducerRecord<>("wyl-events", s);
producer.send(record,(m,e)->{
if(Objects.nonNull(e))
{
e.printStackTrace();
}
System.out.println(m);
});
Thread.sleep(100000);
}
public static void main(String[] args) throws IOException {
byte[] byteArray = { -119, 66, 67 };
String str = new String(byteArray,StandardCharsets.ISO_8859_1);
System.out.println(str);
byte[] bytes = str.getBytes(StandardCharsets.ISO_8859_1);
System.out.println(bytes);
}
public static void main1(String[] args) throws IOException {
File file = new File("/Users/wyl/Desktop/wyl.png");
InputStream inputStream = new FileInputStream(file);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, bytesRead);
}
byte[] imageData = outputStream.toByteArray();
String s = new String(imageData);
}
public static void main2(String[] args) {
byte[] byteArray = { -119, 66, 67 };
Charset[] charsets = { StandardCharsets.UTF_8, Charset.forName("ISO-8859-1"), Charset.forName("GBK") };
for (Charset charset : charsets) {
String str = new String(byteArray, charset);
System.out.println(charset.name() + ": " + str);
byte[] newByteArray = str.getBytes(charset);
System.out.println(charset.name() + ": " + Arrays.toString(newByteArray));
}
}
}
@@ -0,0 +1,216 @@
package com.wyl.kafka.test;
import com.google.protobuf.ByteString;
import lombok.Data;
import lombok.SneakyThrows;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.junit.jupiter.api.Test;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
public class TlPictureProducerTest {
@SneakyThrows
@Test
public void autofocus() {
/**
* 构建kafka 生产者
*/
KafkaProducer<String, byte[]> kafkaProducer = buildProducer();
String topic = "CCD-PICTURE-NEO-1-wyltest";
AtomicReference<Integer> partition = new AtomicReference<>(0);
LocalDateTime now = LocalDateTime.now();
String format = now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
List<Embryo> embryoList = bulidEmbtyo();
Integer shootingPosition = 10000;
embryoList.stream().forEach(embryo -> {
embryo.embryoIds.entrySet().stream().forEach(id -> {
for (int i = 1; i < 81; i++) {
Integer end = 0;
if (i == 80) {
end = 1;
}
ImageDataDTO.ImageDTO image = makeSendData(null, embryo.getHouseSn(), id.getKey(), 1, format, embryo.getFertilizationTime(), i, shootingPosition * (125 + i), end, id.getValue(), embryo.getId());
partition.set(image.getHouseSn() % 3);
ProducerRecord<String, byte[]> record = new ProducerRecord<>(topic, partition.get(), null, image.toByteArray());
/**
* 发送消息
*/
kafkaProducer.send(record, (m, e) -> {
if (!Objects.isNull(e)) {
e.printStackTrace();
} else {
System.out.println(m.timestamp());
}
});
}
});
});
Thread.sleep(100000);
}
@SneakyThrows
@Test
public void ccd() {
/**
* 构建kafka 生产者
*/
KafkaProducer<String, byte[]> kafkaProducer = buildProducer();
String topic = "CCD-PICTURE-NEO-1-wyltest";
AtomicReference<Integer> partition = new AtomicReference<>(0);
LocalDateTime now = LocalDateTime.now();
String format = now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
List<Embryo> embryoList = bulidEmbtyo();
Integer shootingPosition = 40000;
embryoList.stream().forEach(embryo -> {
embryo.embryoIds.entrySet().stream().forEach(id -> {
for (int i = 1; i < 22; i++) {
Integer end = 0;
if (i == 21) {
end = 1;
}
int a = (i + 1) / 2;
int c = 0;
if (a == 11) {
c = 1;
}
ImageDataDTO.ImageDTO image = makeSendData(c, embryo.getHouseSn(), id.getKey(), 0, format,
embryo.getFertilizationTime(), i, shootingPosition * (125 + i),
end, id.getValue(), embryo.getId());
partition.set(image.getHouseSn() % 3);
ProducerRecord<String, byte[]> record = new ProducerRecord<>(topic, partition.get(), null, image.toByteArray());
/**
* 发送消息
*/
kafkaProducer.send(record, (m, e) -> {
if (!Objects.isNull(e)) {
e.printStackTrace();
} else {
System.out.println(m.timestamp());
}
});
}
});
});
Thread.sleep(100000);
}
/**
* 构建kafka生产者
*
* @param
* @return org.apache.kafka.clients.producer.KafkaProducer<java.lang.String, byte [ ]>
* @Date 2023/7/18
* @Author wangyl
*/
private static KafkaProducer<String, byte[]> buildProducer() {
Properties producerProps = new Properties();
producerProps.put("bootstrap.servers", "192.168.31.89:9092");
producerProps.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
producerProps.put("value.serializer", "org.apache.kafka.common.serialization.ByteArraySerializer");
producerProps.put("max.request.size", "2097152");
KafkaProducer<String, byte[]> producer = new KafkaProducer<>(producerProps);
return producer;
}
/**
* 获取图片数据
*
* @param
* @return byte[]
* @Date 2023/7/18
* @Author wangyl
*/
public static byte[] getImageData() throws IOException {
File file = new File("C:\\Users\\95981\\Desktop\\wangyongliang.jpg");
InputStream inputStream = new FileInputStream(file);
byte[] bytes = inputStream.readAllBytes();
return bytes;
}
/**
* 构建图片传输数据
*
* @param imageTime
* @param pictureLayer
* @param shootingPosition
* @param end
* @return com.wyl.kafka.test.ImageDataDTO.ImageDTO
* @Date 2023/7/18
* @Author wangyl
*/
@SneakyThrows
public static ImageDataDTO.ImageDTO makeSendData(Integer c, Integer houseSn, Integer wellSn, Integer photographType, String imageTime, String fertilizationTime, Integer pictureLayer, Integer shootingPosition, Integer end, long embryoCultureRecordId, long embryoId) {
ImageDataDTO.ImageDTO.Builder builder = ImageDataDTO.ImageDTO.newBuilder()
.setTlSn("NEO-1-wyltest")
.setHouseSn(houseSn)
.setWellSn(wellSn)
.setCcdSn("dfbb63a9-20ee-4b9b-9f0d-ae8205f4fa1f")
.setSourceImageName(UUID.randomUUID().toString())
.setSourceImagePath("TLData/Embryos/1_558/13_6578/1/")
.setSourceImageWidth(753)
.setSourceImageHeight(895)
.setImageTime(imageTime)
.setFertilizationTime(fertilizationTime)
.setPhotographType(photographType)
.setTotalLayer(40)
.setPictureLayer(pictureLayer)
.setShootingPosition(shootingPosition)
.setEnd(end)
.setEmbryoCultureRecordId(embryoCultureRecordId)
.setEmbryoId(embryoId)
.setImageData(ByteString.copyFrom(getImageData()))
.setHorizontalPosition(0);
if (Objects.nonNull(c)) {
builder.setClearest(c);
}
return builder.build();
}
public static List<Embryo> bulidEmbtyo() {
List<Embryo> embryoList = new ArrayList<>();
Embryo embryo = new Embryo();
embryo.setId(10L);
embryo.setHouseSn(1);
embryo.setFertilizationTime("2023-07-13 11:06:23");
Map<Integer, Long> embryoIds = new HashMap<>();
embryoIds.put(1, 33L);
embryoIds.put(2, 34L);
embryoIds.put(3, 35L);
embryo.setEmbryoIds(embryoIds);
embryoList.add(embryo);
Embryo embryo2 = new Embryo();
embryo2.setId(11L);
embryo2.setHouseSn(2);
embryo2.setFertilizationTime("2023-07-13 11:06:23");
Map<Integer, Long> embryoIds2 = new HashMap<>();
embryoIds2.put(2, 36L);
embryoIds2.put(3, 37L);
embryoIds2.put(4, 38L);
embryo2.setEmbryoIds(embryoIds2);
embryoList.add(embryo2);
return embryoList;
}
@Data
public static class Embryo {
private Long id;
private Integer houseSn;
private Map<Integer, Long> embryoIds;
private String fertilizationTime;
}
}
+6
View File
@@ -22,6 +22,12 @@
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
<version>1.2.5</version>
</dependency>
<dependency>
<groupId>org.eclipse.paho</groupId>
<artifactId>org.eclipse.paho.mqttv5.client</artifactId>
<version>1.2.5</version>
</dependency>
</dependencies>
</project>
@@ -0,0 +1,52 @@
package com.wyl.mqtt;
import org.eclipse.paho.mqttv5.client.IMqttToken;
import org.eclipse.paho.mqttv5.client.MqttAsyncClient;
import org.eclipse.paho.mqttv5.client.MqttConnectionOptions;
import org.eclipse.paho.mqttv5.client.persist.MemoryPersistence;
import org.eclipse.paho.mqttv5.common.MqttException;
import org.eclipse.paho.mqttv5.common.MqttMessage;
import java.nio.charset.StandardCharsets;
public class MqttClientPublish5 {
public static void main(String[] args) {
String topic = "test";
String content = "Message from MqttPublishSample";
int qos = 2;
String broker = "tcp://192.168.31.89:1883";
String clientId = "JavaClientPublish";
MemoryPersistence persistence = new MemoryPersistence();
try {
MqttConnectionOptions connOpts = new MqttConnectionOptions();
connOpts.setUserName("aivfo");
connOpts.setPassword("aivfo".getBytes(StandardCharsets.UTF_8));
connOpts.setCleanStart(false);
MqttAsyncClient sampleClient = new MqttAsyncClient(broker, clientId, persistence);
System.out.println("Connecting to broker: " + broker);
IMqttToken token = sampleClient.connect(connOpts);
token.waitForCompletion();
System.out.println("Connected");
System.out.println("Publishing message: " + content);
MqttMessage message = new MqttMessage(content.getBytes());
message.setQos(qos);
token = sampleClient.publish(topic, message);
token.waitForCompletion();
System.out.println("Disconnected");
System.out.println("Close client.");
sampleClient.close();
System.exit(0);
} catch (MqttException me) {
System.out.println("reason " + me.getReasonCode());
System.out.println("msg " + me.getMessage());
System.out.println("loc " + me.getLocalizedMessage());
System.out.println("cause " + me.getCause());
System.out.println("excep " + me);
me.printStackTrace();
}
}
}
+12
View File
@@ -21,11 +21,23 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<!-- <dependency>-->
<!-- <groupId>com.aivfo</groupId>-->
<!-- <artifactId>aivfo-dfs-client-spring-boot-starter</artifactId>-->
<!-- <version>1.0.0-SNAPSHOT</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-web</artifactId>-->
<!-- </dependency>-->
<dependency>
<groupId>com.aivfo</groupId>
<artifactId>aivfo-kafka-spring-boot-starter</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.retry</groupId>
<artifactId>spring-retry</artifactId>
@@ -3,6 +3,7 @@ package com.wyl.spring.boot.common.service.impl;
import com.wyl.spring.boot.common.service.LogTestService;
import com.wyl.spring.boot.common.spel.annotation.SpelTest;
import com.wyl.spring.boot.common.spel.bean.Order;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -11,7 +12,6 @@ import java.util.List;
@Service
public class LogTestServiceImpl implements LogTestService {
@Override
// @LogTest
@Transactional
@@ -1,3 +1,7 @@
auth.should.skip.url[0] =1
auth.should.skip.url[1] =2
auth.should.skip.url[2] =3
auth.should.skip.url[0]=1
auth.should.skip.url[1]=2
auth.should.skip.url[2]=3
aivfo.dfs.fastdfs.enable=true
aivfo.dfs.fastdfs.trackerServers=172.23.194.180:22122
aivfo.kafka.properties.ips=192.168.31.89:9092
aivfo.kafka.properties.producer.enable=true
@@ -8,11 +8,10 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.List;
@RestController
@RequestMapping("rule")
@RequestMapping("rule1")
public class RuleContreller {
@Autowired
RuleGenerator ruleGenerator;
@@ -21,8 +20,14 @@ public class RuleContreller {
public void add(@RequestBody RuleDTO ruleDTO) {
ruleGenerator.generateRules(List.of(ruleDTO));
}
@PostMapping("del")
public void del() {
ruleGenerator.removeRules();
}
@PostMapping("/test")
public String test() {
return "123";
}
}
+5
View File
@@ -34,6 +34,11 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.aivfo</groupId>
<artifactId>aivfo-dfs-client-spring-boot-starter</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
@@ -1,5 +1,7 @@
spring.datasource.url=jdbc:mysql://192.168.123.102:3306/wyl_test?useUnicode=true&serverTimezone=UTC&characterEncoding=utf8&useSSL=false&autoReconnect=true&failOverReadOnly=false&rewriteBatchedStatements=true
spring.datasource.url=jdbc:mysql://wylgyx.top:3306/wyl_test?useUnicode=true&serverTimezone=UTC&characterEncoding=utf8&useSSL=false&autoReconnect=true&failOverReadOnly=false&rewriteBatchedStatements=true
spring.datasource.username=root
spring.datasource.password=Wyl.0629
spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver
server.port=80
aivfo.dsf.fastDFS.enable=true
aivfo.dsf.enable=true
@@ -4,11 +4,9 @@ import com.wyl.springbootmybatis.BaseTest;
import com.wyl.springbootmybatis.mybatis.domain.KeyTest;
import com.wyl.springbootmybatis.mybatis.domain.MybatisTest;
import com.wyl.springbootmybatis.mybatis.mapper.KeyTestMapper;
import com.wyl.springbootmybatis.mybatis.service.KeyTestService;
import com.wyl.springbootmybatis.mybatis.service.MybatisTestService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import sun.security.krb5.internal.ktab.KeyTabEntry;
import java.util.ArrayList;
import java.util.List;
@@ -30,10 +28,10 @@ class SpringBootMybatisApplicationTests extends BaseTest {
@Test
void saveDataTest() {
for (int i = 0; i < 300000; i++){
for (int i = 0; i < 300000; i++) {
MybatisTest mybatisTest = new MybatisTest();
mybatisTest.setCode(UUID.randomUUID()
.toString());
.toString());
mybatisTestService.save(mybatisTest);
}
}