Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
caopu16
whatsmars
提交
fb3a8bc0
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,发现更多精彩内容 >>
提交
fb3a8bc0
编写于
12月 19, 2018
作者:
武汉红喜
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
RocketMQMessageListener增加reconsumeTimes属性,用来控制消费失败重试次数
上级
c1a15d1b
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
65 addition
and
7 deletion
+65
-7
whatsmars-mq/rocketmq-spring-boot-starter/src/main/java/org/apache/rocketmq/spring/starter/RocketMQAutoConfiguration.java
...he/rocketmq/spring/starter/RocketMQAutoConfiguration.java
+1
-0
whatsmars-mq/rocketmq-spring-boot-starter/src/main/java/org/apache/rocketmq/spring/starter/annotation/RocketMQMessageListener.java
...mq/spring/starter/annotation/RocketMQMessageListener.java
+5
-0
whatsmars-mq/rocketmq-spring-boot-starter/src/main/java/org/apache/rocketmq/spring/starter/core/DefaultRocketMQListenerContainer.java
...spring/starter/core/DefaultRocketMQListenerContainer.java
+15
-3
whatsmars-mq/rocketmq-spring-boot-starter/src/main/java/org/apache/rocketmq/spring/starter/core/DefaultRocketMQListenerContainerConstants.java
...arter/core/DefaultRocketMQListenerContainerConstants.java
+1
-0
whatsmars-mq/whatsmars-mq-rocketmq/src/main/java/org/hongxi/whatsmars/rocketmq/boot/consumer/MyConsumer4.java
.../hongxi/whatsmars/rocketmq/boot/consumer/MyConsumer4.java
+18
-0
whatsmars-mq/whatsmars-mq-rocketmq/src/main/java/org/hongxi/whatsmars/rocketmq/boot/consumer/MyConsumer5.java
.../hongxi/whatsmars/rocketmq/boot/consumer/MyConsumer5.java
+19
-0
whatsmars-mq/whatsmars-mq-rocketmq/src/main/java/org/hongxi/whatsmars/rocketmq/boot/producer/ProducerApplication.java
...whatsmars/rocketmq/boot/producer/ProducerApplication.java
+6
-4
未找到文件。
whatsmars-mq/rocketmq-spring-boot-starter/src/main/java/org/apache/rocketmq/spring/starter/RocketMQAutoConfiguration.java
浏览文件 @
fb3a8bc0
...
...
@@ -176,6 +176,7 @@ public class RocketMQAutoConfiguration {
beanBuilder
.
addPropertyValue
(
PROP_CONSUMER_GROUP
,
environment
.
resolvePlaceholders
(
annotation
.
consumerGroup
()));
beanBuilder
.
addPropertyValue
(
PROP_CONSUME_MODE
,
annotation
.
consumeMode
());
beanBuilder
.
addPropertyValue
(
PROP_CONSUME_THREAD_MAX
,
annotation
.
consumeThreadMax
());
beanBuilder
.
addPropertyValue
(
PROP_RECONSUME_TIMES
,
annotation
.
reconsumeTimes
());
beanBuilder
.
addPropertyValue
(
PROP_MESSAGE_MODEL
,
annotation
.
messageModel
());
beanBuilder
.
addPropertyValue
(
PROP_SELECTOR_EXPRESS
,
environment
.
resolvePlaceholders
(
annotation
.
selectorExpress
()));
beanBuilder
.
addPropertyValue
(
PROP_SELECTOR_TYPE
,
annotation
.
selectorType
());
...
...
whatsmars-mq/rocketmq-spring-boot-starter/src/main/java/org/apache/rocketmq/spring/starter/annotation/RocketMQMessageListener.java
浏览文件 @
fb3a8bc0
...
...
@@ -80,4 +80,9 @@ public @interface RocketMQMessageListener {
*/
int
consumeThreadMax
()
default
64
;
/**
* Re-consume times for concurrent/orderly message
*/
int
reconsumeTimes
()
default
0
;
}
whatsmars-mq/rocketmq-spring-boot-starter/src/main/java/org/apache/rocketmq/spring/starter/core/DefaultRocketMQListenerContainer.java
浏览文件 @
fb3a8bc0
...
...
@@ -96,6 +96,10 @@ public class DefaultRocketMQListenerContainer implements InitializingBean, Rocke
@Getter
private
int
consumeThreadMax
=
64
;
@Setter
@Getter
private
int
reconsumeTimes
=
0
;
@Getter
@Setter
private
String
charset
=
"UTF-8"
;
...
...
@@ -180,9 +184,14 @@ public class DefaultRocketMQListenerContainer implements InitializingBean, Rocke
long
costTime
=
System
.
currentTimeMillis
()
-
now
;
log
.
info
(
"consume {} cost: {} ms"
,
messageExt
.
getMsgId
(),
costTime
);
}
catch
(
Exception
e
)
{
log
.
warn
(
"consume message failed. messageExt:{}"
,
messageExt
,
e
);
context
.
setSuspendCurrentQueueTimeMillis
(
suspendCurrentQueueTimeMillis
);
return
ConsumeOrderlyStatus
.
SUSPEND_CURRENT_QUEUE_A_MOMENT
;
if
(
reconsumeTimes
==
0
)
{
log
.
warn
(
"consume message failed, and will not retry. messageExt:{}"
,
messageExt
,
e
);
}
else
if
(
reconsumeTimes
<=
-
1
||
messageExt
.
getReconsumeTimes
()
<
reconsumeTimes
)
{
log
.
warn
(
"consume message failed, reconsumeTimes:{}. messageExt:{}"
,
messageExt
.
getReconsumeTimes
(),
messageExt
,
e
);
context
.
setSuspendCurrentQueueTimeMillis
(
suspendCurrentQueueTimeMillis
);
return
ConsumeOrderlyStatus
.
SUSPEND_CURRENT_QUEUE_A_MOMENT
;
}
}
}
...
...
@@ -273,6 +282,9 @@ public class DefaultRocketMQListenerContainer implements InitializingBean, Rocke
}
consumer
.
setMessageModel
(
messageModel
);
if
(
reconsumeTimes
>
0
)
{
consumer
.
setMaxReconsumeTimes
(
reconsumeTimes
);
}
switch
(
selectorType
)
{
case
TAG:
...
...
whatsmars-mq/rocketmq-spring-boot-starter/src/main/java/org/apache/rocketmq/spring/starter/core/DefaultRocketMQListenerContainerConstants.java
浏览文件 @
fb3a8bc0
...
...
@@ -27,6 +27,7 @@ public final class DefaultRocketMQListenerContainerConstants {
public
static
final
String
PROP_CONSUMER_GROUP
=
"consumerGroup"
;
public
static
final
String
PROP_CONSUME_MODE
=
"consumeMode"
;
public
static
final
String
PROP_CONSUME_THREAD_MAX
=
"consumeThreadMax"
;
public
static
final
String
PROP_RECONSUME_TIMES
=
"reconsumeTimes"
;
public
static
final
String
PROP_MESSAGE_MODEL
=
"messageModel"
;
public
static
final
String
PROP_SELECTOR_EXPRESS
=
"selectorExpress"
;
public
static
final
String
PROP_SELECTOR_TYPE
=
"selectorType"
;
...
...
whatsmars-mq/whatsmars-mq-rocketmq/src/main/java/org/hongxi/whatsmars/rocketmq/boot/consumer/MyConsumer4.java
0 → 100644
浏览文件 @
fb3a8bc0
package
org.hongxi.whatsmars.rocketmq.boot.consumer
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.rocketmq.spring.starter.annotation.RocketMQMessageListener
;
import
org.apache.rocketmq.spring.starter.core.RocketMQListener
;
import
org.apache.rocketmq.spring.starter.enums.ConsumeMode
;
import
org.springframework.stereotype.Service
;
@Slf4j
@Service
@RocketMQMessageListener
(
topic
=
"test-topic-4"
,
consumerGroup
=
"my-consumer_test-topic-4"
,
consumeMode
=
ConsumeMode
.
ORDERLY
)
public
class
MyConsumer4
implements
RocketMQListener
<
String
>
{
public
void
onMessage
(
String
message
)
{
log
.
info
(
"received message: "
+
message
);
int
a
=
1
/
0
;
}
}
\ No newline at end of file
whatsmars-mq/whatsmars-mq-rocketmq/src/main/java/org/hongxi/whatsmars/rocketmq/boot/consumer/MyConsumer5.java
0 → 100644
浏览文件 @
fb3a8bc0
package
org.hongxi.whatsmars.rocketmq.boot.consumer
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.rocketmq.common.message.MessageExt
;
import
org.apache.rocketmq.spring.starter.annotation.RocketMQMessageListener
;
import
org.apache.rocketmq.spring.starter.core.RocketMQListener
;
import
org.apache.rocketmq.spring.starter.enums.ConsumeMode
;
import
org.springframework.stereotype.Service
;
@Slf4j
@Service
@RocketMQMessageListener
(
topic
=
"test-topic-4"
,
consumerGroup
=
"my-consumer_test-topic-5"
,
consumeMode
=
ConsumeMode
.
ORDERLY
,
reconsumeTimes
=
3
)
public
class
MyConsumer5
implements
RocketMQListener
<
MessageExt
>
{
public
void
onMessage
(
MessageExt
messageExt
)
{
log
.
info
(
"received message: "
+
messageExt
);
int
a
=
1
/
0
;
}
}
\ No newline at end of file
whatsmars-mq/whatsmars-mq-rocketmq/src/main/java/org/hongxi/whatsmars/rocketmq/boot/producer/ProducerApplication.java
浏览文件 @
fb3a8bc0
...
...
@@ -21,16 +21,18 @@ public class ProducerApplication implements CommandLineRunner {
}
public
void
run
(
String
...
args
)
throws
Exception
{
for
(
int
i
=
0
;
i
<
20
;
i
++)
{
for
(
int
i
=
0
;
i
<
5
;
i
++)
{
try
{
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
(
"I'm delayed message"
).
build
(),
MessageDelayLevel
.
TIME_1M
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
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
(
"I'm delayed message"
).
build
(),
MessageDelayLevel
.
TIME_1M
);
rocketMQTemplate
.
syncSendOrderly
(
"test-topic-4"
,
MessageBuilder
.
withPayload
(
"I'm order message"
).
build
(),
"1234"
);
System
.
out
.
println
(
"send finished!"
);
// rocketMQTemplate.destroy(); // notes: once rocketMQTemplate be destroyed, you can not send any message again with this rocketMQTemplate
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录