Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
caopu16
whatsmars
提交
2ee02595
W
whatsmars
项目概览
caopu16
/
whatsmars
与 Fork 源项目一致
Fork自
武汉红喜 / whatsmars
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
W
whatsmars
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
2ee02595
编写于
12月 14, 2018
作者:
武汉红喜
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
delay message
上级
11726b5a
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
43 addition
and
8 deletion
+43
-8
whatsmars-mq/rocketmq-spring-boot-starter/src/main/java/org/apache/rocketmq/spring/starter/core/RocketMQTemplate.java
...apache/rocketmq/spring/starter/core/RocketMQTemplate.java
+8
-7
whatsmars-mq/rocketmq-spring-boot-starter/src/main/java/org/apache/rocketmq/spring/starter/enums/MessageDelayLevel.java
...ache/rocketmq/spring/starter/enums/MessageDelayLevel.java
+33
-0
whatsmars-mq/whatsmars-mq-rocketmq/src/main/java/org/hongxi/whatsmars/rocketmq/boot/producer/ProducerApplication.java
...whatsmars/rocketmq/boot/producer/ProducerApplication.java
+2
-1
未找到文件。
whatsmars-mq/rocketmq-spring-boot-starter/src/main/java/org/apache/rocketmq/spring/starter/core/RocketMQTemplate.java
浏览文件 @
2ee02595
...
...
@@ -32,6 +32,7 @@ import org.apache.rocketmq.client.producer.SendCallback;
import
org.apache.rocketmq.client.producer.SendResult
;
import
org.apache.rocketmq.client.producer.selector.SelectMessageQueueByHash
;
import
org.apache.rocketmq.common.message.MessageConst
;
import
org.apache.rocketmq.spring.starter.enums.MessageDelayLevel
;
import
org.springframework.beans.factory.DisposableBean
;
import
org.springframework.beans.factory.InitializingBean
;
import
org.springframework.messaging.Message
;
...
...
@@ -120,7 +121,7 @@ public class RocketMQTemplate extends AbstractMessageSendingTemplate<String> imp
return
syncSend
(
destination
,
payload
,
producer
.
getSendMsgTimeout
());
}
public
SendResult
sendDelayed
(
String
destination
,
Message
<?>
message
,
int
delayLevel
)
{
public
SendResult
sendDelayed
(
String
destination
,
Message
<?>
message
,
MessageDelayLevel
delayLevel
)
{
return
sendDelayed
(
destination
,
message
,
producer
.
getSendMsgTimeout
(),
delayLevel
);
}
...
...
@@ -130,27 +131,27 @@ public class RocketMQTemplate extends AbstractMessageSendingTemplate<String> imp
* @param destination formats: `topicName:tags`
* @param message {@link org.springframework.messaging.Message}
* @param timeout send timeout with millis
* @param delayLevel level for the delay message
* @param delayLevel level for the delay message
{@link MessageDelayLevel}
* @return {@link SendResult}
*/
public
SendResult
sendDelayed
(
String
destination
,
Message
<?>
message
,
long
timeout
,
int
delayLevel
)
{
public
SendResult
sendDelayed
(
String
destination
,
Message
<?>
message
,
long
timeout
,
MessageDelayLevel
delayLevel
)
{
if
(
Objects
.
isNull
(
message
)
||
Objects
.
isNull
(
message
.
getPayload
()))
{
log
.
error
(
"s
yncSen
d failed. destination:{}, message is null "
,
destination
);
log
.
error
(
"s
endDelaye
d failed. destination:{}, message is null "
,
destination
);
throw
new
IllegalArgumentException
(
"`message` and `message.payload` cannot be null"
);
}
try
{
long
now
=
System
.
currentTimeMillis
();
org
.
apache
.
rocketmq
.
common
.
message
.
Message
rocketMsg
=
convertToRocketMsg
(
destination
,
message
);
if
(
delayLevel
>
0
)
{
rocketMsg
.
setDelayTimeLevel
(
delayLevel
);
if
(
delayLevel
.
level
>
0
)
{
rocketMsg
.
setDelayTimeLevel
(
delayLevel
.
level
);
}
SendResult
sendResult
=
producer
.
send
(
rocketMsg
,
timeout
);
long
costTime
=
System
.
currentTimeMillis
()
-
now
;
log
.
debug
(
"send message cost: {} ms, msgId:{}"
,
costTime
,
sendResult
.
getMsgId
());
return
sendResult
;
}
catch
(
Exception
e
)
{
log
.
error
(
"s
yncSen
d failed. destination:{}, message:{} "
,
destination
,
message
);
log
.
error
(
"s
endDelaye
d failed. destination:{}, message:{} "
,
destination
,
message
);
throw
new
MessagingException
(
e
.
getMessage
(),
e
);
}
}
...
...
whatsmars-mq/rocketmq-spring-boot-starter/src/main/java/org/apache/rocketmq/spring/starter/enums/MessageDelayLevel.java
0 → 100644
浏览文件 @
2ee02595
package
org.apache.rocketmq.spring.starter.enums
;
public
enum
MessageDelayLevel
{
TIME_1S
(
1
),
TIME_5S
(
2
),
TIME_10S
(
3
),
TIME_30S
(
4
),
TIME_1M
(
5
),
TIME_2M
(
6
),
TIME_3M
(
7
),
TIME_4M
(
8
),
TIME_5M
(
9
),
TIME_6M
(
10
),
TIME_7M
(
11
),
TIME_8M
(
12
),
TIME_9M
(
13
),
TIME_10M
(
14
),
TIME_20M
(
15
),
TIME_30M
(
16
),
TIME_1H
(
17
),
TIME_2H
(
18
),
// 新增延迟类型需要在broker配置增加messageDelayLevel
TIME_6H
(
19
),
TIME_12H
(
20
);
public
int
level
;
MessageDelayLevel
(
int
level
)
{
this
.
level
=
level
;
}
}
\ No newline at end of file
whatsmars-mq/whatsmars-mq-rocketmq/src/main/java/org/hongxi/whatsmars/rocketmq/boot/producer/ProducerApplication.java
浏览文件 @
2ee02595
package
org.hongxi.whatsmars.rocketmq.boot.producer
;
import
org.apache.rocketmq.spring.starter.core.RocketMQTemplate
;
import
org.apache.rocketmq.spring.starter.enums.MessageDelayLevel
;
import
org.hongxi.whatsmars.rocketmq.boot.OrderPaidEvent
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.CommandLineRunner
;
...
...
@@ -25,7 +26,7 @@ public class ProducerApplication implements CommandLineRunner {
rocketMQTemplate
.
convertAndSend
(
"test-topic-1"
,
"Hello, World!"
);
rocketMQTemplate
.
send
(
"test-topic-1"
,
MessageBuilder
.
withPayload
(
"Hello, World! I'm from spring message"
).
build
());
rocketMQTemplate
.
convertAndSend
(
"test-topic-2"
,
new
OrderPaidEvent
(
"T_001"
,
new
BigDecimal
(
"88.00"
)));
rocketMQTemplate
.
sendDelayed
(
"test-topic-1"
,
MessageBuilder
.
withPayload
(
"
Hello, World! I'm from spring message"
).
build
(),
2
);
rocketMQTemplate
.
sendDelayed
(
"test-topic-1"
,
MessageBuilder
.
withPayload
(
"
I'm delayed message"
).
build
(),
MessageDelayLevel
.
TIME_1M
.
level
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录