编写版本:v3.5.7
适用版本:v3.5.7+
配置或修改scoket支持
工程iform-response中的:
application-dev-socket.yml
application-test-socket.yml
application-cloud-socket.yml
application-prod-socket.yml
application-optimize-socket.yml
application-saas-test-socket.yml
application-saas-prod-socket.yml
socket:
enabled: ${SOCKET_ENABLED:true} #true:支持,false:不支持
port: 5888 #端口
reconnect-max-num: 5
新服务中增加socket配置
application-dev.yml
application-test.yml
application-cloud.yml
application-prod.yml
application-optimize.yml
application-saas-test.yml
application-saas-prod.yml
spring:
profiles:
include: dev-base,dev-nacos,dev-socket
注:dev-socket中的dev是根据工程iform-response中的配置来的,比如测试环境为:test-socket
新服务引入socket包
<dependency>
<groupId>com.ak.iform.cloud.base</groupId>
<artifactId>iform-comp-socket-api</artifactId>
</dependency>
新服务启动类修改
增加引入:
@Autowired
private Environment env;
继承AbstractBasicCommandLineRunner类,实现其ext()方法:
@Override
protected void ext() {
renewalSystemExpriedTime();
NewsHelper.handleExpiredNews(env);
}
private void renewalSystemExpriedTime() {
long period = EnvUtil.getProperty(env, "auto.renewal.system.expried.time.interval", Long.class, 480L);
Function<Void, Void> execution = new Function<Void, Void>() {
@Override
public Void apply(Void t) {
IHandlerValidator<UniqueHandlerValidation> uniqueHandlerValidator = null;
try {
String key = "platform.auto.renewal.system.expried.time";
uniqueHandlerValidator =
HandlerValidationUtil.createUniqueHandlerValidator(key, "renewal", null, null);
HandlerValidationErrors errors = uniqueHandlerValidator.validate(key);
if (null != errors && errors.hasError()) {
return null;
}
ContextUtil.setCurrentUri("/auth/client/save");
ContextUtil.setCurrentUserIp(AppUtil.getProperty("spring.cloud.client.ip-address"));
AuthClient authClient = AppUtil.getBean(AuthClient.class);
authClient.renewalSystemExpriedTime();
} catch (Exception e) {
if(LOGGER.isWarnEnabled()) {
LOGGER.warn(e.getMessage(), e);
}
} finally {
HandlerValidationUtil.processAfterInvoke(uniqueHandlerValidator);
}
return null;
}
};
ScheduledUtil.createAndRunningScheduledThreadPoolExecutor(1, "auto-renewal-system-expried-time", 1L, period,
TimeUnit.MINUTES, execution);
}
调用方式
//发送webSocket消息
PushSocketMessageVo vo = SocketMessageUtil.createPushSocketMessageVo(toUserId, fromUserId, type, body, expandVo);
SocketMessageUtil.pushSomebodiesMessage(vo);
作者:caoyl 创建时间:2024-01-31 16:59
最后编辑:caoyl 更新时间:2024-11-25 19:17
最后编辑:caoyl 更新时间:2024-11-25 19:17