A passionate Java developer
- 🔭 I’m currently Focusing on Java、SpringBoot
- 🌱 I’m currently learning Vue3、ELK、K8s
- ⚡ Interested in full stack.
Java 复盘计划
非 WebFlex 下使用 websocket
临时解决:
@Bean
public AsyncTaskExecutor taskExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setThreadNamePrefix("Anno-Executor");
executor.setMaxPoolSize(10);
// 设置拒绝策略
executor.setRejectedExecutionHandler((r, executor1) -> {
// .....
});
// 使用预定义的异常处理类
// executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
return executor;
}
参考文档:http://redisdoc.com/topic/notification.html
键空间通知,所有通知以 keyspace@
为前缀
键事件通知,所有通知以 keyevent@
为前缀
例如:"__keyevent@<db>__:set"
,@ 后面是数据库序号,或者用 *
所有命令都只在键真的被改动了之后,才会产生通知,比如删除 foo 会产生键空间通知:
“pmessage”,"__ key*__ : * “,”__ keyspace@0__:foo",“set”
以及键事件通知:
“pmessage”,"__ key*__ : *","__ keyevent@0__:set",“foo”
如果要监听某个 key 的执行了什么操作,就订阅 keyspace@
监听某种操作动了哪些 key,就订阅 keyevent@
。
根据 GMT 来转换时间的示例:
其中使用了 Hutool 提供的工具来做了个 LocalDateTime 转 Date;
String timeZone = "GMT+8";
final ZoneId zoneId = TimeZone.getTimeZone(timeZone).toZoneId();
LocalDateTime localDateTime = LocalDateTime.now(zoneId);
localDateTime = LocalDateTimeUtil.offset(localDateTime, JobScheduleHelper.PRE_READ_MS, ChronoUnit.MILLIS);
Instant localDateTime2Instant = localDateTime.atZone(ZoneId.systemDefault()).toInstant();
Date d = Date.from(localDateTime2Instant);
例如使用 AWS 的 redis 服务,会导致 springboot ERR unknown command CONFIG
解决:
KeyExpirationEventMessageListener 或者 KeyspaceEventMessageListener 的构造方法中,重置配置为空:
setKeyspaceNotificationsConfigParameter("");
KeyspaceEventMessageListener 类中有个私有变量 keyspaceNotificationsConfigParameter = "EA",在init()方法中,我们可以看到如果判断到该变量不为空,则会获取redis的配置,之后修改redis的配置,也就是只要我们把这个变量设置为空,那么springboot 初始化实例的时候也就不会去操作redis的CONFIG了,恰好,该类提供了setKeyspaceNotificationsConfigParameter()供我们修改变量的值。
因此,我们可以在自己写的Key监听器的构造方法中把keyspaceNotificationsConfigParameter 设置为空即可解决此问题
see:https://blog.csdn.net/zsxlbr1314/article/details/116650952
Spring 本身提供了很多好用的工具类。
org.springframework.util
慢慢补充
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.