增加kafka get的超时时间

This commit is contained in:
mcy
2018-09-04 09:39:02 +08:00
parent 17f345bfe5
commit 81c216f1c1
3 changed files with 25 additions and 2 deletions

View File

@@ -3,7 +3,11 @@ retries: 0
batchSize: 16384
lingerMs: 1
bufferMemory: 33554432
canalBatchSize: 50 # Canal的batch size, 默认50K, 由于kafka最大消息体限制请勿超过1M(900K以下)
# Canal的batch size, 默认50K, 由于kafka最大消息体限制请勿超过1M(900K以下)
canalBatchSize: 50
# Canal get数据的超时时间, 单位: 毫秒, 空为不限超时
canalGetTimeout: 100
canalDestinations:
- canalDestination: example

View File

@@ -4,6 +4,7 @@ import java.io.FileInputStream;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
@@ -117,7 +118,16 @@ public class CanalKafkaStarter implements CanalServerStarter {
logger.info("## the canal consumer {} is running now ......", destination.getCanalDestination());
while (running) {
Message message = server.getWithoutAck(clientIdentity, kafkaProperties.getCanalBatchSize()); // 获取指定数量的数据
Message message;
if (kafkaProperties.getCanalGetTimeout() != null) {
message = server.getWithoutAck(clientIdentity,
kafkaProperties.getCanalBatchSize(),
kafkaProperties.getCanalGetTimeout(),
TimeUnit.MILLISECONDS);
} else {
message = server.getWithoutAck(clientIdentity, kafkaProperties.getCanalBatchSize());
}
final long batchId = message.getId();
try {
int size = message.isRaw() ? message.getRawEntries().size() : message.getEntries().size();

View File

@@ -20,6 +20,7 @@ public class KafkaProperties {
private long bufferMemory = 33554432L;
private boolean filterTransactionEntry = true;
private int canalBatchSize = 50;
private Long canalGetTimeout;
private List<CanalDestination> canalDestinations = new ArrayList<CanalDestination>();
@@ -151,6 +152,14 @@ public class KafkaProperties {
this.canalBatchSize = canalBatchSize;
}
public Long getCanalGetTimeout() {
return canalGetTimeout;
}
public void setCanalGetTimeout(Long canalGetTimeout) {
this.canalGetTimeout = canalGetTimeout;
}
public List<CanalDestination> getCanalDestinations() {
return canalDestinations;
}