Search in sources :

Example 6 with ProduceResponseData

use of org.apache.kafka.common.message.ProduceResponseData in project kafka by apache.

the class ProduceResponse method toData.

private static ProduceResponseData toData(Map<TopicPartition, PartitionResponse> responses, int throttleTimeMs) {
    ProduceResponseData data = new ProduceResponseData().setThrottleTimeMs(throttleTimeMs);
    responses.forEach((tp, response) -> {
        ProduceResponseData.TopicProduceResponse tpr = data.responses().find(tp.topic());
        if (tpr == null) {
            tpr = new ProduceResponseData.TopicProduceResponse().setName(tp.topic());
            data.responses().add(tpr);
        }
        tpr.partitionResponses().add(new ProduceResponseData.PartitionProduceResponse().setIndex(tp.partition()).setBaseOffset(response.baseOffset).setLogStartOffset(response.logStartOffset).setLogAppendTimeMs(response.logAppendTime).setErrorMessage(response.errorMessage).setErrorCode(response.error.code()).setRecordErrors(response.recordErrors.stream().map(e -> new ProduceResponseData.BatchIndexAndErrorMessage().setBatchIndex(e.batchIndex).setBatchIndexErrorMessage(e.message)).collect(Collectors.toList())));
    });
    return data;
}
Also used : TopicPartition(org.apache.kafka.common.TopicPartition) ByteBufferAccessor(org.apache.kafka.common.protocol.ByteBufferAccessor) HashMap(java.util.HashMap) ApiKeys(org.apache.kafka.common.protocol.ApiKeys) Collectors(java.util.stream.Collectors) ByteBuffer(java.nio.ByteBuffer) Objects(java.util.Objects) List(java.util.List) RecordBatch(org.apache.kafka.common.record.RecordBatch) Map(java.util.Map) Errors(org.apache.kafka.common.protocol.Errors) Collections(java.util.Collections) ProduceResponseData(org.apache.kafka.common.message.ProduceResponseData) ProduceResponseData(org.apache.kafka.common.message.ProduceResponseData)

Aggregations

ProduceResponseData (org.apache.kafka.common.message.ProduceResponseData)6 ProduceResponse (org.apache.kafka.common.requests.ProduceResponse)4 ByteBuffer (java.nio.ByteBuffer)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 TopicPartition (org.apache.kafka.common.TopicPartition)2 ProduceRequestData (org.apache.kafka.common.message.ProduceRequestData)2 NetworkReceive (org.apache.kafka.common.network.NetworkReceive)2 ProduceRequest (org.apache.kafka.common.requests.ProduceRequest)2 Collections (java.util.Collections)1 IdentityHashMap (java.util.IdentityHashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Objects (java.util.Objects)1 Collectors (java.util.stream.Collectors)1 ApiKeys (org.apache.kafka.common.protocol.ApiKeys)1 ByteBufferAccessor (org.apache.kafka.common.protocol.ByteBufferAccessor)1 Errors (org.apache.kafka.common.protocol.Errors)1 RecordBatch (org.apache.kafka.common.record.RecordBatch)1 Test (org.junit.jupiter.api.Test)1