Skip to content

Commit b0e4d29

Browse files
✨ 小优化
1 parent 562ab29 commit b0e4d29

File tree

7 files changed

+99
-21
lines changed

7 files changed

+99
-21
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
package io.github.fastmq.domain.consumer.instantaneous;
22

33

4-
54
/**
65
* The interface Fast mq listener.
76
*
7+
* @param <T> the type parameter
88
* @author disaster
99
* @version 1.0
1010
*/
1111
public interface FastMQListener<T> {
1212

13+
/**
14+
* On message.
15+
*
16+
* @param t the t
17+
* @throws Throwable the throwable
18+
*/
1319
void onMessage(T t) throws Throwable;
1420
}

fast-mq-core/src/main/java/io/github/fastmq/domain/producer/delay/FastMQDelayTemplate.java

+24
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,34 @@
22

33
import java.util.concurrent.TimeUnit;
44

5+
/**
6+
* The interface Fast mq delay template.
7+
*/
58
public interface FastMQDelayTemplate {
9+
/**
10+
* Send msg.
11+
*
12+
* @param data the data
13+
* @param delayTime the delay time
14+
* @param delayQueue the delay queue
15+
* @param timeUnit the time unit
16+
*/
617
void sendMsg(Object data, long delayTime, String delayQueue, TimeUnit timeUnit);
718

19+
/**
20+
* Send msg.
21+
*
22+
* @param data the data
23+
* @param delayTime the delay time
24+
* @param timeUnit the time unit
25+
*/
826
void sendMsg(Object data, long delayTime, TimeUnit timeUnit);
927

28+
/**
29+
* Send msg.
30+
*
31+
* @param data the data
32+
* @param delayTime the delay time
33+
*/
1034
void sendMsg(Object data, long delayTime);
1135
}

fast-mq-core/src/main/java/io/github/fastmq/domain/producer/instantaneous/FastMQTemplate.java

+29
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,41 @@
44
import org.springframework.lang.NonNull;
55
import java.util.Map;
66

7+
/**
8+
* The interface Fast mq template.
9+
*/
710
public interface FastMQTemplate {
11+
/**
12+
* Send msg async.
13+
*
14+
* @param topic the topic
15+
* @param msg the msg
16+
*/
817
void sendMsgAsync(@NonNull String topic, Map<String, Object> msg);
918

19+
/**
20+
* Send msg async.
21+
*
22+
* @param id the id
23+
* @param topic the topic
24+
* @param msg the msg
25+
*/
1026
void sendMsgAsync(@NonNull Long id, @NonNull String topic, Map<String, Object> msg);
1127

28+
/**
29+
* Send msg async.
30+
*
31+
* @param topic the topic
32+
* @param msg the msg
33+
*/
1234
void sendMsgAsync(@NonNull String topic, Object msg);
1335

36+
/**
37+
* Send msg async.
38+
*
39+
* @param id the id
40+
* @param topic the topic
41+
* @param msg the msg
42+
*/
1443
void sendMsgAsync(@NonNull Long id, @NonNull String topic, Object msg);
1544
}

fast-mq-core/src/main/java/io/github/fastmq/domain/share/MQCenter.java

+15-17
Original file line numberDiff line numberDiff line change
@@ -57,30 +57,37 @@ public class MQCenter implements ApplicationRunner, ApplicationContextAware, Dis
5757
*/
5858
private Set<FastMQDelayListener> fastMQListeners2;
5959

60-
6160
/**
6261
* redissonClient对象
6362
*/
64-
@Autowired
65-
private RedissonClient client;
63+
private final RedissonClient client;
6664

6765
/**
6866
* fastmq配置属性
6967
*/
70-
@Autowired
71-
private FastMQProperties fastMQProperties;
68+
private final FastMQProperties fastMQProperties;
7269

7370
/**
7471
* 领域服务对象-异步
7572
*/
76-
@Autowired
77-
private FastMQAsyncService fastMQAsyncService;
73+
private final FastMQAsyncService fastMQAsyncService;
7874

7975
/**
8076
* 领域服务对象-同步
8177
*/
78+
private final FastMQService fastMQService;
79+
80+
8281
@Autowired
83-
private FastMQService fastMQService;
82+
public MQCenter(RedissonClient client, FastMQProperties fastMQProperties, FastMQAsyncService fastMQAsyncService, FastMQService fastMQService) {
83+
this.client = client;
84+
this.fastMQProperties = fastMQProperties;
85+
this.fastMQAsyncService = fastMQAsyncService;
86+
this.fastMQService = fastMQService;
87+
fastMQListeners0 = new HashSet<>();
88+
fastMQListeners1 = new HashSet<>();
89+
fastMQListeners2 = new HashSet<>();
90+
}
8491

8592
/**
8693
* spring上下文对象,用于获取fastmq的bean实例
@@ -111,15 +118,6 @@ public class MQCenter implements ApplicationRunner, ApplicationContextAware, Dis
111118
luaStr = sb.toString();
112119
}
113120

114-
/**
115-
* Instantiates a new Mq center.
116-
*/
117-
public MQCenter() {
118-
fastMQListeners0 = new HashSet<>();
119-
fastMQListeners1 = new HashSet<>();
120-
fastMQListeners2 = new HashSet<>();
121-
}
122-
123121

124122
private void initThreadPool() {
125123
service = Executors.newScheduledThreadPool(

fast-mq-core/src/main/java/io/github/fastmq/infrastructure/utils/BeanMapUtils.java

+22-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import java.util.*;
1818

1919
/**
20-
* Bean和Map类型转换工具类,参考自Barry
20+
* Bean和Map类型转换工具类
2121
*
2222
* @author disaster
2323
* @version 1.0
@@ -48,6 +48,13 @@ public static final Object toBean(Class<?> type, Map<Object, ? extends Object> m
4848
return isEquals(parse0, parse1) ? BeanUtil.mapToBean(map, aClass, true, CopyOptions.create()) : null;
4949
}
5050

51+
/**
52+
* To bean object.
53+
*
54+
* @param type the type
55+
* @param msg the msg
56+
* @return the object
57+
*/
5158
@SneakyThrows
5259
public static final Object toBean(Class<?> type, String msg) {
5360
Type generic = getType(type, FastMQDelayListenerInfo);
@@ -59,13 +66,27 @@ public static final Object toBean(Class<?> type, String msg) {
5966
}
6067

6168

69+
/**
70+
* Is equals boolean.
71+
*
72+
* @param source the source
73+
* @param target the target
74+
* @return the boolean
75+
*/
6276
public static Boolean isEquals(Object source, Object target) {
6377
Class<?> aClass0 = source.getClass();
6478
Class<?> aClass1 = target.getClass();
6579
return aClass0.equals(aClass1);
6680
}
6781

6882

83+
/**
84+
* Gets type.
85+
*
86+
* @param type the type
87+
* @param typeName the type name
88+
* @return the type
89+
*/
6990
public static Type getType(Class<?> type, String typeName) {
7091
Type[] genericInterfaces = type.getGenericInterfaces();
7192
Type generic = null;

fast-mq-core/src/main/java/io/github/fastmq/infrastructure/utils/SystemClock.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
/**
1010
* <p>
11-
* 高并发场景下System.currentTimeMillis()的性能问题的优化
11+
* 高并发场景下System.currentTimeMillis()的性能问题的优化、redis中的LRU链表中的时间戳就是通过这种方式去实现(很高效也很有用)
1212
* </p>
1313
* <p>
1414
* System.currentTimeMillis()的调用比new一个普通对象要耗时的多<br>

fast-mq-core/src/main/resources/application.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ fastmq:
3131
executor:
3232
#拉取默认主题信息的周期
3333
pullDefaultTopicMessagesPeriod: 10
34-
#检查PendingList周期
34+
#拉取自定义主题信息的周期
3535
pullTopicMessagesPeriod: 1
3636
time-unit: seconds
3737
#第一次延迟执行的时间

0 commit comments

Comments
 (0)