Search in sources :

Example 1 with DescribeProducersResponseData

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

the class DescribeProducersRequest method getErrorResponse.

@Override
public DescribeProducersResponse getErrorResponse(int throttleTimeMs, Throwable e) {
    Errors error = Errors.forException(e);
    DescribeProducersResponseData response = new DescribeProducersResponseData();
    for (TopicRequest topicRequest : data.topics()) {
        TopicResponse topicResponse = new TopicResponse().setName(topicRequest.name());
        for (int partitionId : topicRequest.partitionIndexes()) {
            topicResponse.partitions().add(new PartitionResponse().setPartitionIndex(partitionId).setErrorCode(error.code()));
        }
        response.topics().add(topicResponse);
    }
    return new DescribeProducersResponse(response);
}
Also used : Errors(org.apache.kafka.common.protocol.Errors) PartitionResponse(org.apache.kafka.common.message.DescribeProducersResponseData.PartitionResponse) TopicRequest(org.apache.kafka.common.message.DescribeProducersRequestData.TopicRequest) TopicResponse(org.apache.kafka.common.message.DescribeProducersResponseData.TopicResponse) DescribeProducersResponseData(org.apache.kafka.common.message.DescribeProducersResponseData)

Example 2 with DescribeProducersResponseData

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

the class KafkaAdminClientTest method buildDescribeProducersResponse.

private DescribeProducersResponse buildDescribeProducersResponse(TopicPartition topicPartition, List<ProducerState> producerStates) {
    DescribeProducersResponseData response = new DescribeProducersResponseData();
    DescribeProducersResponseData.TopicResponse topicResponse = new DescribeProducersResponseData.TopicResponse().setName(topicPartition.topic());
    response.topics().add(topicResponse);
    DescribeProducersResponseData.PartitionResponse partitionResponse = new DescribeProducersResponseData.PartitionResponse().setPartitionIndex(topicPartition.partition()).setErrorCode(Errors.NONE.code());
    topicResponse.partitions().add(partitionResponse);
    partitionResponse.setActiveProducers(producerStates.stream().map(producerState -> new DescribeProducersResponseData.ProducerState().setProducerId(producerState.producerId()).setProducerEpoch(producerState.producerEpoch()).setCoordinatorEpoch(producerState.coordinatorEpoch().orElse(-1)).setLastSequence(producerState.lastSequence()).setLastTimestamp(producerState.lastTimestamp()).setCurrentTxnStartOffset(producerState.currentTransactionStartOffset().orElse(-1L))).collect(Collectors.toList()));
    return new DescribeProducersResponse(response);
}
Also used : ReassignablePartitionResponse(org.apache.kafka.common.message.AlterPartitionReassignmentsResponseData.ReassignablePartitionResponse) DescribeProducersResponseData(org.apache.kafka.common.message.DescribeProducersResponseData) DescribeProducersResponse(org.apache.kafka.common.requests.DescribeProducersResponse)

Example 3 with DescribeProducersResponseData

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

the class DescribeProducersHandlerTest method describeProducersResponse.

private DescribeProducersResponse describeProducersResponse(Map<TopicPartition, PartitionResponse> partitionResponses) {
    DescribeProducersResponseData response = new DescribeProducersResponseData();
    Map<String, Map<Integer, PartitionResponse>> partitionResponsesByTopic = CollectionUtils.groupPartitionDataByTopic(partitionResponses);
    for (Map.Entry<String, Map<Integer, PartitionResponse>> topicEntry : partitionResponsesByTopic.entrySet()) {
        String topic = topicEntry.getKey();
        Map<Integer, PartitionResponse> topicPartitionResponses = topicEntry.getValue();
        TopicResponse topicResponse = new TopicResponse().setName(topic);
        response.topics().add(topicResponse);
        for (Map.Entry<Integer, PartitionResponse> partitionEntry : topicPartitionResponses.entrySet()) {
            Integer partitionId = partitionEntry.getKey();
            PartitionResponse partitionResponse = partitionEntry.getValue();
            topicResponse.partitions().add(partitionResponse.setPartitionIndex(partitionId));
        }
    }
    return new DescribeProducersResponse(response);
}
Also used : PartitionResponse(org.apache.kafka.common.message.DescribeProducersResponseData.PartitionResponse) TopicResponse(org.apache.kafka.common.message.DescribeProducersResponseData.TopicResponse) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) Collections.emptyMap(java.util.Collections.emptyMap) DescribeProducersResponseData(org.apache.kafka.common.message.DescribeProducersResponseData) DescribeProducersResponse(org.apache.kafka.common.requests.DescribeProducersResponse)

Example 4 with DescribeProducersResponseData

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

the class RequestResponseTest method createDescribeProducersResponse.

private DescribeProducersResponse createDescribeProducersResponse() {
    DescribeProducersResponseData data = new DescribeProducersResponseData();
    DescribeProducersResponseData.TopicResponse topicResponse = new DescribeProducersResponseData.TopicResponse();
    topicResponse.partitions().add(new DescribeProducersResponseData.PartitionResponse().setErrorCode(Errors.NONE.code()).setPartitionIndex(0).setActiveProducers(asList(new DescribeProducersResponseData.ProducerState().setProducerId(1234L).setProducerEpoch(15).setLastTimestamp(13490218304L).setCurrentTxnStartOffset(5000), new DescribeProducersResponseData.ProducerState().setProducerId(9876L).setProducerEpoch(32).setLastTimestamp(13490218399L))));
    data.topics().add(topicResponse);
    return new DescribeProducersResponse(data);
}
Also used : ListOffsetsPartitionResponse(org.apache.kafka.common.message.ListOffsetsResponseData.ListOffsetsPartitionResponse) ListOffsetsTopicResponse(org.apache.kafka.common.message.ListOffsetsResponseData.ListOffsetsTopicResponse) DescribeProducersResponseData(org.apache.kafka.common.message.DescribeProducersResponseData)

Aggregations

DescribeProducersResponseData (org.apache.kafka.common.message.DescribeProducersResponseData)4 PartitionResponse (org.apache.kafka.common.message.DescribeProducersResponseData.PartitionResponse)2 TopicResponse (org.apache.kafka.common.message.DescribeProducersResponseData.TopicResponse)2 DescribeProducersResponse (org.apache.kafka.common.requests.DescribeProducersResponse)2 Collections.emptyMap (java.util.Collections.emptyMap)1 Collections.singletonMap (java.util.Collections.singletonMap)1 Map (java.util.Map)1 ReassignablePartitionResponse (org.apache.kafka.common.message.AlterPartitionReassignmentsResponseData.ReassignablePartitionResponse)1 TopicRequest (org.apache.kafka.common.message.DescribeProducersRequestData.TopicRequest)1 ListOffsetsPartitionResponse (org.apache.kafka.common.message.ListOffsetsResponseData.ListOffsetsPartitionResponse)1 ListOffsetsTopicResponse (org.apache.kafka.common.message.ListOffsetsResponseData.ListOffsetsTopicResponse)1 Errors (org.apache.kafka.common.protocol.Errors)1