治理暂态事件、文件解析公共参数添加
This commit is contained in:
@@ -28,6 +28,9 @@ public interface BusinessTopic {
|
|||||||
*/
|
*/
|
||||||
String NJCN_APP_FILE_TOPIC = "njcnAppFileTopic";
|
String NJCN_APP_FILE_TOPIC = "njcnAppFileTopic";
|
||||||
|
|
||||||
|
String NJCN_APP_FILE_STREAM_TOPIC = "njcnAppFileStreamTopic";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/********************************数据中心*********************************/
|
/********************************数据中心*********************************/
|
||||||
|
|
||||||
|
|||||||
@@ -22,9 +22,9 @@ public class AppFileMessageTemplate extends RocketMQEnhanceTemplate {
|
|||||||
super(template);
|
super(template);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SendResult sendMember(AppFileMessage appFileMessage, String tag) {
|
public SendResult sendMember(AppFileMessage appFileMessage) {
|
||||||
appFileMessage.setSource(BusinessResource.APP_RESOURCE);
|
appFileMessage.setSource(BusinessResource.APP_RESOURCE);
|
||||||
return send(BusinessTopic.NJCN_APP_FILE_TOPIC, tag, appFileMessage);
|
return send(BusinessTopic.NJCN_APP_FILE_TOPIC, BusinessTopic.FileTag.INFO_TAG, appFileMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package com.njcn.mq.template;
|
||||||
|
|
||||||
|
import com.njcn.middle.rocket.template.RocketMQEnhanceTemplate;
|
||||||
|
import com.njcn.mq.constant.BusinessResource;
|
||||||
|
import com.njcn.mq.constant.BusinessTopic;
|
||||||
|
import com.njcn.mq.message.AppFileMessage;
|
||||||
|
import org.apache.rocketmq.client.producer.SendResult;
|
||||||
|
import org.apache.rocketmq.spring.core.RocketMQTemplate;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 类的介绍:
|
||||||
|
*
|
||||||
|
* @author xuyang
|
||||||
|
* @version 1.0.0
|
||||||
|
* @createTime 2023/8/11 15:28
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class AppFileStreamMessageTemplate extends RocketMQEnhanceTemplate {
|
||||||
|
|
||||||
|
public AppFileStreamMessageTemplate(RocketMQTemplate template) {
|
||||||
|
super(template);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SendResult sendMember(AppFileMessage appFileMessage) {
|
||||||
|
appFileMessage.setSource(BusinessResource.APP_RESOURCE);
|
||||||
|
return send(BusinessTopic.NJCN_APP_FILE_STREAM_TOPIC, BusinessTopic.FileTag.STREAM_TAG, appFileMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -10,6 +10,8 @@ import com.njcn.minioss.config.MinIossProperties;
|
|||||||
import com.njcn.minioss.util.MinIoUtils;
|
import com.njcn.minioss.util.MinIoUtils;
|
||||||
import com.njcn.oss.constant.GeneralConstant;
|
import com.njcn.oss.constant.GeneralConstant;
|
||||||
import com.njcn.oss.enums.OssResponseEnum;
|
import com.njcn.oss.enums.OssResponseEnum;
|
||||||
|
import io.minio.MinioClient;
|
||||||
|
import io.minio.PutObjectArgs;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.tomcat.util.http.fileupload.IOUtils;
|
import org.apache.tomcat.util.http.fileupload.IOUtils;
|
||||||
@@ -17,8 +19,10 @@ import org.springframework.http.MediaType;
|
|||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -31,6 +35,9 @@ import java.util.UUID;
|
|||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class FileStorageUtil {
|
public class FileStorageUtil {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private MinioClient instance;
|
||||||
|
|
||||||
private final GeneralInfo generalInfo;
|
private final GeneralInfo generalInfo;
|
||||||
|
|
||||||
/***
|
/***
|
||||||
@@ -99,6 +106,31 @@ public class FileStorageUtil {
|
|||||||
return filePath;
|
return filePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上传InputStream流,并指定文件的名称
|
||||||
|
* @author xuyang
|
||||||
|
* @param inputStream
|
||||||
|
* @param dir
|
||||||
|
* @param fileName
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String uploadStreamSpecifyName(InputStream inputStream, String dir, String fileName) {
|
||||||
|
String filePath;
|
||||||
|
if (generalInfo.getBusinessFileStorage() == GeneralConstant.HUAWEI_OBS) {
|
||||||
|
filePath = dir + minIoUtils.minFileName(fileName);
|
||||||
|
obsUtil.uploadStream(inputStream, filePath);
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
//把名称存入数据
|
||||||
|
MinIoUploadResDTO minIoUploadResDTO = uploadStreamSpecifyName(inputStream, minIossProperties.getBucket(), dir, fileName);
|
||||||
|
filePath = minIoUploadResDTO.getMinFileName();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new BusinessException(OssResponseEnum.UPLOAD_FILE_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return filePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/***
|
/***
|
||||||
* 根据文件路径获取文件短期的一个url
|
* 根据文件路径获取文件短期的一个url
|
||||||
@@ -221,6 +253,15 @@ public class FileStorageUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public MinIoUploadResDTO uploadStreamSpecifyName(InputStream inputStream, String bucketName, String directory, String fileName) throws Exception {
|
||||||
|
if (!minIoUtils.bucketExists(bucketName)) {
|
||||||
|
minIoUtils.makeBucket(bucketName);
|
||||||
|
}
|
||||||
|
directory = (String) Optional.ofNullable(directory).orElse("");
|
||||||
|
String minFileName = directory + fileName;
|
||||||
|
this.instance.putObject((PutObjectArgs)((io.minio.PutObjectArgs.Builder)((io.minio.PutObjectArgs.Builder)PutObjectArgs.builder().bucket(bucketName)).object(minFileName)).stream(inputStream, (long)inputStream.available(), -1L).build());
|
||||||
|
inputStream.close();
|
||||||
|
return new MinIoUploadResDTO(minFileName, minIoUtils.getObjectUrl(bucketName, minFileName, 60));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,4 +51,6 @@ public interface AppRedisKey {
|
|||||||
*/
|
*/
|
||||||
String RMQ_FILE_CONSUME_KEY="rocketMQFileConsumeKey:";
|
String RMQ_FILE_CONSUME_KEY="rocketMQFileConsumeKey:";
|
||||||
|
|
||||||
|
String TIME="time-:";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user