카프카의 일시 정지 및 재개 소비자 소비

// 일시 정지 카프카 소비자 중단 유통 파티션 
consumer.unsubscribe (); // 여기에하지 않습니다 탈퇴 일시 중지 너무 오래 구독 시간 오류
consumer.pause (consumer.assignment ());



// 다시 파티션 소비,이 재 할당에 잘못 갈 수 없어
this.open (NULL, NULL, NULL);
    IF (소비자 == NULL) { 
속성은 소품 = 새로운 새로운 속성 ();
props.put ( "bootstrap.servers", PropertiesUtil.getValue ( "bootstrap.servers"));
// 소비자 그룹 ID
props.put ( " group.id ", constant.kafka_groupName); // Spider2의
props.put ("enable.auto.commit ",") "는 false;
// max.poll.interval.ms (기본을 얻을 수있는 공식 웹 사이트) 3000 평균이다 우리가 kafkaServer 끝에서 메시지를 폴링 할 때입니다, 여론 조사에 대한 호출 사이의 최대 지연은 ()이다.
소비자가 이상의 레코드가 유휴 상태가 될 수 도착하기 전에 //이 시간의 상한을 제공한다. 이 설문 조사가 호출되지되기 전에 타임 아웃) (만료되면 사용자가 실패로 간주되며, 소비자
// 재 균형 때문에 파티션이 우리가 Thread.sleep를 설정 정확히 어디에 어떤 다른 소비자에게 재 할당됩니다 것 '의 그룹 (6000) > max.poll.interval.ms 값,
// 우리가 수동으로 제출 한 경우, 사실, 파티션이 다른 소비자 내부의 전체 소비자 그룹에 할당 된되는
auto.commit.interval props.put ( ". MS ","3000 ");

props.put ( "session.timeout.ms", "100000");
props.put ( "request.timeout.ms", "200000");
props.put ( "max.poll.records", "2");
// 설문 조사的数量限制
// props.put ( "max.poll.records", "100");
/ * props.put ( "key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
props.put ( "value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer"); * /
props.put ( "key.deserializer"StringDeserializer.class.getName ());
props.put ( "value.deserializer", StringDeserializer.class.getName ());
props.put ( "group.name" ., UUID.randomUUID의 toString () () 완전히 대체 ( "-", "")).;
소비자가 새로운 KafkaConsumer = <문자열, 문자열> (버팀대);

//订阅主题列表주제
//consumer.subscribe(Arrays.asList("test_input "));
}
//注册카프카 rebalanceListener
//consumer.subscribe(Arrays.asList("test_etl "), 새로운 ConsumerRebalanceListener () {

청취자 = 새로운 ConsumerRebalanceListener는 () {
@Override
공개 무효가 (컬렉션 <TopicPartition> 파티션) {onPartitionsRevoked
System.out을한다. 인 printf ( "threadId = {} onPartitionsRevoked."는 Thread.currentThread () getID () 현재의 소재지.)
consumer.commitSync (offsetsMap)
consumer.commitSync는 ();
}
@Override
공개 무효가 onPartitionsAssigned (
모음 <TopicPartition>
System.out.printf ( "threadId = {} onPartitionsAssigned."는 Thread.currentThread () getId ().);
consumer.commitSync ();
offsetsMap.clear ();
}};

consumer.subscribe (Arrays.asList (topicName.split ( ",") [0] topicName.split ( ",") [1] topicName.split ( ",") [2]), 수신기);
consumer.resume (consumer.assignment ());

추천

출처www.cnblogs.com/yaohaitao/p/12172867.html