mirror of
https://github.com/alibaba/canal.git
synced 2026-11-04 00:30:15 +08:00
fixed rocketmq partition out of range
This commit is contained in:
@@ -107,12 +107,11 @@ public class CanalRocketMQProducer implements CanalMQProducer {
|
|||||||
@Override
|
@Override
|
||||||
public MessageQueue select(List<MessageQueue> mqs, Message msg, Object arg) {
|
public MessageQueue select(List<MessageQueue> mqs, Message msg, Object arg) {
|
||||||
if (index > mqs.size()) {
|
if (index > mqs.size()) {
|
||||||
throw new CanalServerException("partition number is error,config num:"
|
return mqs.get(index % mqs.size());
|
||||||
+ destination.getPartitionsNum()
|
} else {
|
||||||
+ ", mq num: " + mqs.size());
|
|
||||||
}
|
|
||||||
return mqs.get(index);
|
return mqs.get(index);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}, null);
|
}, null);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("send flat message to hashed partition error", e);
|
logger.error("send flat message to hashed partition error", e);
|
||||||
@@ -134,8 +133,12 @@ public class CanalRocketMQProducer implements CanalMQProducer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MessageQueue select(List<MessageQueue> mqs, Message msg, Object arg) {
|
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);
|
return mqs.get(partition);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}, null);
|
}, null);
|
||||||
}
|
}
|
||||||
} catch (MQClientException | RemotingException | MQBrokerException | InterruptedException e) {
|
} catch (MQClientException | RemotingException | MQBrokerException | InterruptedException e) {
|
||||||
@@ -168,12 +171,11 @@ public class CanalRocketMQProducer implements CanalMQProducer {
|
|||||||
@Override
|
@Override
|
||||||
public MessageQueue select(List<MessageQueue> mqs, Message msg, Object arg) {
|
public MessageQueue select(List<MessageQueue> mqs, Message msg, Object arg) {
|
||||||
if (index > mqs.size()) {
|
if (index > mqs.size()) {
|
||||||
throw new CanalServerException("partition number is error,config num:"
|
return mqs.get(index % mqs.size());
|
||||||
+ destination.getPartitionsNum()
|
} else {
|
||||||
+ ", mq num: " + mqs.size());
|
|
||||||
}
|
|
||||||
return mqs.get(index);
|
return mqs.get(index);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}, null);
|
}, null);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("send flat message to hashed partition error", e);
|
logger.error("send flat message to hashed partition error", e);
|
||||||
@@ -196,8 +198,12 @@ public class CanalRocketMQProducer implements CanalMQProducer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MessageQueue select(List<MessageQueue> mqs, Message msg, Object arg) {
|
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);
|
return mqs.get(partition);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}, null);
|
}, null);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("send flat message to fixed partition error", e);
|
logger.error("send flat message to fixed partition error", e);
|
||||||
|
|||||||
Reference in New Issue
Block a user