use of org.apache.kafka.clients.consumer.internals.NoOpConsumerRebalanceListener in project open-kilda by telstra.
the class KafkaUtils method getStateDumpsFromBolts.
public DumpStateManager getStateDumpsFromBolts() {
long timestamp = System.currentTimeMillis();
String correlationId = String.format("atdd-%d", timestamp);
CtrlRequest dumpRequest = new CtrlRequest("*", new RequestData("dump"), timestamp, correlationId, WFM_CTRL);
try {
RecordMetadata postedMessage = postMessage(settings.getControlTopic(), dumpRequest);
KafkaConsumer<String, String> consumer = createConsumer();
try {
consumer.subscribe(Collections.singletonList(settings.getControlTopic()), new NoOpConsumerRebalanceListener() {
@Override
public void onPartitionsAssigned(Collection<TopicPartition> partitions) {
System.out.println("Seek to offset: " + postedMessage.offset());
for (TopicPartition topicPartition : partitions) {
consumer.seek(topicPartition, postedMessage.offset());
}
}
});
List<CtrlResponse> buffer = new ArrayList<>();
final int BOLT_COUNT = 4;
final int NUMBER_OF_ATTEMPTS = 5;
int attempt = 0;
while (buffer.size() < BOLT_COUNT && attempt++ < NUMBER_OF_ATTEMPTS) {
for (ConsumerRecord<String, String> record : consumer.poll(1000)) {
System.out.println("Received message: (" + record.key() + ", " + record.value() + ") at offset " + record.offset());
Message message = MAPPER.readValue(record.value(), Message.class);
if (message.getDestination() == CTRL_CLIENT && message.getCorrelationId().equals(correlationId)) {
buffer.add((CtrlResponse) message);
}
}
}
return DumpStateManager.fromResponsesList(buffer);
} finally {
consumer.close();
}
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
use of org.apache.kafka.clients.consumer.internals.NoOpConsumerRebalanceListener in project kafka by apache.
the class KafkaConsumerTest method testSubscriptionOnNullPattern.
@Test(expected = IllegalArgumentException.class)
public void testSubscriptionOnNullPattern() {
KafkaConsumer<byte[], byte[]> consumer = newConsumer();
Pattern pattern = null;
try {
consumer.subscribe(pattern, new NoOpConsumerRebalanceListener());
} finally {
consumer.close();
}
}
Aggregations