fixed rocketmq partition out of range

This commit is contained in:
agapple
2019-04-03 11:26:31 +08:00
parent d3195ac973
commit 82ed9db8ae

View File

@@ -107,12 +107,11 @@ public class CanalRocketMQProducer implements CanalMQProducer {
@Override
public MessageQueue select(List<MessageQueue> mqs, Message msg, Object arg) {
if (index > mqs.size()) {
throw new CanalServerException("partition number is error,config num:"
+ destination.getPartitionsNum()
+ ", mq num: " + mqs.size());
}
return mqs.get(index % mqs.size());
} else {
return mqs.get(index);
}
}
}, null);
} catch (Exception e) {
logger.error("send flat message to hashed partition error", e);
@@ -134,8 +133,12 @@ public class CanalRocketMQProducer implements CanalMQProducer {
@Override
public MessageQueue select(List<MessageQueue> mqs, Message msg, Object arg) {
if (partition > mqs.size()) {
return mqs.get(partition % mqs.size());
} else {
return mqs.get(partition);
}
}
}, null);
}
} catch (MQClientException | RemotingException | MQBrokerException | InterruptedException e) {
@@ -168,12 +171,11 @@ public class CanalRocketMQProducer implements CanalMQProducer {
@Override
public MessageQueue select(List<MessageQueue> mqs, Message msg, Object arg) {
if (index > mqs.size()) {
throw new CanalServerException("partition number is error,config num:"
+ destination.getPartitionsNum()
+ ", mq num: " + mqs.size());
}
return mqs.get(index % mqs.size());
} else {
return mqs.get(index);
}
}
}, null);
} catch (Exception e) {
logger.error("send flat message to hashed partition error", e);
@@ -196,8 +198,12 @@ public class CanalRocketMQProducer implements CanalMQProducer {
@Override
public MessageQueue select(List<MessageQueue> mqs, Message msg, Object arg) {
if (partition > mqs.size()) {
return mqs.get(partition % mqs.size());
} else {
return mqs.get(partition);
}
}
}, null);
} catch (Exception e) {
logger.error("send flat message to fixed partition error", e);