From 8280388917c466d030ffb774a2474ca8e4144811 Mon Sep 17 00:00:00 2001 From: vsair Date: Fri, 26 May 2017 15:13:29 +0800 Subject: [PATCH] =?UTF-8?q?[ROCKETMQ-175]=20Consumer=20may=20miss=20messag?= =?UTF-8?q?es=20because=20of=20inconsistent=20sub=E2=80=A6=20=20closes=20a?= =?UTF-8?q?pache/incubator-rocketmq#92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../client/impl/consumer/RebalancePushImpl.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/client/src/main/java/org/apache/rocketmq/client/impl/consumer/RebalancePushImpl.java b/client/src/main/java/org/apache/rocketmq/client/impl/consumer/RebalancePushImpl.java index 1730c992..509c9a46 100644 --- a/client/src/main/java/org/apache/rocketmq/client/impl/consumer/RebalancePushImpl.java +++ b/client/src/main/java/org/apache/rocketmq/client/impl/consumer/RebalancePushImpl.java @@ -30,6 +30,7 @@ import org.apache.rocketmq.common.consumer.ConsumeFromWhere; import org.apache.rocketmq.common.message.MessageQueue; import org.apache.rocketmq.common.protocol.heartbeat.ConsumeType; import org.apache.rocketmq.common.protocol.heartbeat.MessageModel; +import org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData; public class RebalancePushImpl extends RebalanceImpl { private final static long UNLOCK_DELAY_TIME_MILLS = Long.parseLong(System.getProperty("rocketmq.client.unlockDelayTimeMills", "20000")); @@ -47,6 +48,16 @@ public class RebalancePushImpl extends RebalanceImpl { @Override public void messageQueueChanged(String topic, Set mqAll, Set mqDivided) { + /** + * When rebalance result changed, should update subscription's version to notify broker. + * Fix: inconsistency subscription may lead to consumer miss messages. + */ + SubscriptionData subscriptionData = this.subscriptionInner.get(topic); + long newVersion = System.currentTimeMillis(); + log.info("{} Rebalance changed, also update version: {}, {}", topic, subscriptionData.getSubVersion(), newVersion); + subscriptionData.setSubVersion(newVersion); + // notify broker + this.getmQClientFactory().sendHeartbeatToAllBrokerWithLock(); } @Override -- GitLab