[+] 合并事件监听还有协议
This commit is contained in:
@@ -9,8 +9,7 @@ import java.lang.annotation.Target;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 事件监听
|
||||
* 事件用来处理异步业务还有广播业务
|
||||
* 事件信令协议
|
||||
*
|
||||
* @author acgist
|
||||
*/
|
||||
@@ -18,6 +17,6 @@ import org.springframework.stereotype.Component;
|
||||
@Component
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface EventListener {
|
||||
public @interface EventProtocol {
|
||||
|
||||
}
|
||||
@@ -9,7 +9,7 @@ import java.lang.annotation.Target;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 协议
|
||||
* 信令协议
|
||||
*
|
||||
* @author acgist
|
||||
*/
|
||||
|
||||
@@ -59,6 +59,7 @@ import com.acgist.taoyao.boot.service.IdService;
|
||||
import com.acgist.taoyao.boot.service.impl.IdServiceImpl;
|
||||
import com.acgist.taoyao.boot.utils.ErrorUtils;
|
||||
import com.acgist.taoyao.boot.utils.FileUtils;
|
||||
import com.acgist.taoyao.boot.utils.HTTPUtils;
|
||||
import com.acgist.taoyao.boot.utils.JSONUtils;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
@@ -122,12 +123,17 @@ public class BootAutoConfiguration {
|
||||
public TaskScheduler taskScheduler(TaskSchedulerBuilder builder) {
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
public CommandLineRunner successCommandLineRunner() {
|
||||
@Autowired
|
||||
public CommandLineRunner successCommandLineRunner(
|
||||
TaskExecutor taskExecutor,
|
||||
TaoyaoProperties taoyaoProperties
|
||||
) {
|
||||
return new CommandLineRunner() {
|
||||
@Override
|
||||
public void run(String ... args) throws Exception {
|
||||
HTTPUtils.init(taoyaoProperties.getTimeout(), taskExecutor);
|
||||
log.info("项目启动成功:{}", BootAutoConfiguration.this.name);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -18,7 +18,7 @@ public class IdProperties {
|
||||
/**
|
||||
* 机器序号
|
||||
*/
|
||||
private Integer sn;
|
||||
private Integer index;
|
||||
/**
|
||||
* 最大序号
|
||||
*/
|
||||
|
||||
@@ -22,9 +22,13 @@ public class MediaAudioProperties {
|
||||
public enum Format {
|
||||
|
||||
/**
|
||||
* PCM
|
||||
* PCMA
|
||||
*/
|
||||
PCM,
|
||||
PCMA,
|
||||
/**
|
||||
* PCMU
|
||||
*/
|
||||
PCMU,
|
||||
/**
|
||||
* OPUS
|
||||
*/
|
||||
|
||||
@@ -17,10 +17,10 @@ import lombok.Setter;
|
||||
public class MediaServerProperties {
|
||||
|
||||
/**
|
||||
* 名称
|
||||
* 媒体服务标识
|
||||
*/
|
||||
@Schema(title = "名称", description = "名称")
|
||||
private String name;
|
||||
@Schema(title = "媒体服务标识", description = "媒体服务标识")
|
||||
private String mediaId;
|
||||
/**
|
||||
* 是否启用
|
||||
*/
|
||||
|
||||
@@ -8,7 +8,7 @@ package com.acgist.taoyao.boot.service;
|
||||
public interface IdService {
|
||||
|
||||
/**
|
||||
* 生成十九位的ID:YYMMddHHmmss(12) + sn(1) + xxxxxx(6)
|
||||
* 生成十九位的ID:YYMMddHHmmss(12) + index(1) + xxxxxx(6)
|
||||
*
|
||||
* @return ID
|
||||
*/
|
||||
|
||||
@@ -33,7 +33,7 @@ public class IdServiceImpl implements IdService {
|
||||
1000000000L * time.getMinute() +
|
||||
10000000L * time.getSecond() +
|
||||
// 机器序号一位
|
||||
1000000L * this.idProperties.getSn() +
|
||||
1000000L * this.idProperties.getIndex() +
|
||||
// 每秒并发数量
|
||||
this.index;
|
||||
}
|
||||
|
||||
@@ -6,10 +6,13 @@ import java.security.NoSuchAlgorithmException;
|
||||
import java.security.SecureRandom;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.time.Duration;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
|
||||
import org.springframework.core.task.TaskExecutor;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
@@ -20,16 +23,38 @@ import lombok.extern.slf4j.Slf4j;
|
||||
@Slf4j
|
||||
public final class HTTPUtils {
|
||||
|
||||
/**
|
||||
* 超时时间
|
||||
*/
|
||||
private static long timeout;
|
||||
/**
|
||||
* 线程池
|
||||
*/
|
||||
private static TaskExecutor executor;
|
||||
|
||||
private HTTPUtils() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param timeout 超时时间
|
||||
* @param executor 线程池
|
||||
*/
|
||||
public static final void init(long timeout, TaskExecutor executor) {
|
||||
HTTPUtils.timeout = timeout;
|
||||
HTTPUtils.executor = executor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return HTTPClient
|
||||
*/
|
||||
public static final HttpClient newClient() {
|
||||
return HttpClient
|
||||
.newBuilder()
|
||||
.sslContext(buildSSLContext())
|
||||
// .version(Version.HTTP_2)
|
||||
.executor(HTTPUtils.executor)
|
||||
.sslContext(HTTPUtils.buildSSLContext())
|
||||
.connectTimeout(Duration.ofMillis(HTTPUtils.timeout))
|
||||
// .followRedirects(Redirect.ALWAYS)
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.acgist.taoyao.boot.utils;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.acgist.taoyao.boot.model.MessageCode;
|
||||
import com.acgist.taoyao.boot.model.MessageCodeException;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* 脚本工具
|
||||
*
|
||||
* @author acgist
|
||||
*/
|
||||
@Slf4j
|
||||
public class ScriptUtils {
|
||||
|
||||
/**
|
||||
* 执行命令
|
||||
*
|
||||
* @param script 命令
|
||||
*
|
||||
* @return 执行结果
|
||||
*/
|
||||
public static final String execute(String script) {
|
||||
if(StringUtils.isEmpty(script)) {
|
||||
throw MessageCodeException.of(MessageCode.CODE_1002, "无效命令:" + script);
|
||||
}
|
||||
String result = null;
|
||||
Process process = null;
|
||||
try {
|
||||
process = Runtime.getRuntime().exec(script);
|
||||
try(
|
||||
final InputStream input = process.getInputStream();
|
||||
final InputStream error = process.getErrorStream();
|
||||
) {
|
||||
final String inputValue = new String(input.readAllBytes());
|
||||
final String errorValue = new String(input.readAllBytes());
|
||||
log.info("""
|
||||
执行命令:{}
|
||||
执行结果:{}
|
||||
失败结果:{}
|
||||
""", script, inputValue, errorValue);
|
||||
result = StringUtils.isEmpty(inputValue) ? errorValue : inputValue;
|
||||
} catch (Exception e) {
|
||||
log.error("命令执行异常:{}", script, e);
|
||||
result = e.getMessage();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("执行命令异常:{}", script, e);
|
||||
result = e.getMessage();
|
||||
} finally {
|
||||
if(process != null) {
|
||||
process.destroy();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user