Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
pulsar
提交
e61acc12
pulsar
项目概览
apache
/
pulsar
通知
129
Star
40
Fork
3
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Wiki
1
Wiki
分析
仓库
DevOps
项目成员
Pages
pulsar
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Pages
分析
分析
仓库分析
DevOps
Wiki
1
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
提交
体验新版 GitCode,发现更多精彩内容 >>
提交
e61acc12
编写于
1月 20, 2017
作者:
R
Rajan
提交者:
GitHub
1月 20, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix consumer redelivery should not clear availablePermits (#170)
上级
0569689b
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
84 addition
and
2 deletion
+84
-2
pulsar-broker/src/test/java/com/yahoo/pulsar/client/api/SimpleProducerConsumerTest.java
...m/yahoo/pulsar/client/api/SimpleProducerConsumerTest.java
+83
-0
pulsar-client/src/main/java/com/yahoo/pulsar/client/impl/ConsumerImpl.java
.../main/java/com/yahoo/pulsar/client/impl/ConsumerImpl.java
+1
-2
未找到文件。
pulsar-broker/src/test/java/com/yahoo/pulsar/client/api/SimpleProducerConsumerTest.java
浏览文件 @
e61acc12
...
...
@@ -1773,4 +1773,87 @@ public class SimpleProducerConsumerTest extends ProducerConsumerBase {
}
}
@Test
public
void
testRedeliveryFailOverConsumer
()
throws
Exception
{
log
.
info
(
"-- Starting {} test --"
,
methodName
);
final
int
receiverQueueSize
=
10
;
ConsumerConfiguration
conf
=
new
ConsumerConfiguration
();
conf
.
setReceiverQueueSize
(
receiverQueueSize
);
conf
.
setSubscriptionType
(
SubscriptionType
.
Failover
);
// Only subscribe consumer
ConsumerImpl
consumer
=
(
ConsumerImpl
)
pulsarClient
.
subscribe
(
"persistent://my-property/use/my-ns/unacked-topic"
,
"subscriber-1"
,
conf
);
ProducerConfiguration
producerConf
=
new
ProducerConfiguration
();
Producer
producer
=
pulsarClient
.
createProducer
(
"persistent://my-property/use/my-ns/unacked-topic"
,
producerConf
);
// (1) First round to produce-consume messages
int
consumeMsgInParts
=
4
;
for
(
int
i
=
0
;
i
<
receiverQueueSize
;
i
++)
{
String
message
=
"my-message-"
+
i
;
producer
.
send
(
message
.
getBytes
());
Thread
.
sleep
(
10
);
}
// (1.a) consume first consumeMsgInParts msgs and trigger redeliver
Message
msg
=
null
;
List
<
Message
>
messages1
=
Lists
.
newArrayList
();
for
(
int
i
=
0
;
i
<
consumeMsgInParts
;
i
++)
{
msg
=
consumer
.
receive
(
1
,
TimeUnit
.
SECONDS
);
if
(
msg
!=
null
)
{
messages1
.
add
(
msg
);
consumer
.
acknowledge
(
msg
);
log
.
info
(
"Received message: "
+
new
String
(
msg
.
getData
()));
}
else
{
break
;
}
}
assertEquals
(
messages1
.
size
(),
consumeMsgInParts
);
consumer
.
redeliverUnacknowledgedMessages
();
// (1.b) consume second consumeMsgInParts msgs and trigger redeliver
messages1
.
clear
();
for
(
int
i
=
0
;
i
<
consumeMsgInParts
;
i
++)
{
msg
=
consumer
.
receive
(
1
,
TimeUnit
.
SECONDS
);
if
(
msg
!=
null
)
{
messages1
.
add
(
msg
);
consumer
.
acknowledge
(
msg
);
log
.
info
(
"Received message: "
+
new
String
(
msg
.
getData
()));
}
else
{
break
;
}
}
assertEquals
(
messages1
.
size
(),
consumeMsgInParts
);
consumer
.
redeliverUnacknowledgedMessages
();
// (2) Second round to produce-consume messages
for
(
int
i
=
0
;
i
<
receiverQueueSize
;
i
++)
{
String
message
=
"my-message-"
+
i
;
producer
.
send
(
message
.
getBytes
());
Thread
.
sleep
(
100
);
}
int
remainingMsgs
=
(
2
*
receiverQueueSize
)
-
(
2
*
consumeMsgInParts
);
messages1
.
clear
();
for
(
int
i
=
0
;
i
<
remainingMsgs
;
i
++)
{
msg
=
consumer
.
receive
(
1
,
TimeUnit
.
SECONDS
);
if
(
msg
!=
null
)
{
messages1
.
add
(
msg
);
consumer
.
acknowledge
(
msg
);
log
.
info
(
"Received message: "
+
new
String
(
msg
.
getData
()));
}
else
{
break
;
}
}
assertEquals
(
messages1
.
size
(),
remainingMsgs
);
producer
.
close
();
consumer
.
close
();
log
.
info
(
"-- Exiting {} test --"
,
methodName
);
}
}
pulsar-client/src/main/java/com/yahoo/pulsar/client/impl/ConsumerImpl.java
浏览文件 @
e61acc12
...
...
@@ -902,13 +902,12 @@ public class ConsumerImpl extends ConsumerBase {
synchronized
(
this
)
{
currentSize
=
incomingMessages
.
size
();
incomingMessages
.
clear
();
availablePermits
.
set
(
0
);
unAckedMessageTracker
.
clear
();
batchMessageAckTracker
.
clear
();
}
cnx
.
ctx
().
writeAndFlush
(
Commands
.
newRedeliverUnacknowledgedMessages
(
consumerId
),
cnx
.
ctx
().
voidPromise
());
if
(
currentSize
>
0
)
{
sendFlowPermitsToBroker
(
cnx
,
currentSize
);
increaseAvailablePermits
(
cnx
,
currentSize
);
}
if
(
log
.
isDebugEnabled
())
{
log
.
debug
(
"[{}] [{}] [{}] Redeliver unacked messages and send {} permits"
,
subscription
,
topic
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录