Search in sources :

Example 6 with SchemaException

use of org.apache.kafka.common.protocol.types.SchemaException in project kafka by apache.

the class ConsumerProtocol method deserializeSubscription.

public static Subscription deserializeSubscription(final ByteBuffer buffer, short version) {
    version = checkSubscriptionVersion(version);
    try {
        ConsumerProtocolSubscription data = new ConsumerProtocolSubscription(new ByteBufferAccessor(buffer), version);
        List<TopicPartition> ownedPartitions = new ArrayList<>();
        for (ConsumerProtocolSubscription.TopicPartition tp : data.ownedPartitions()) {
            for (Integer partition : tp.partitions()) {
                ownedPartitions.add(new TopicPartition(tp.topic(), partition));
            }
        }
        return new Subscription(data.topics(), data.userData() != null ? data.userData().duplicate() : null, ownedPartitions);
    } catch (BufferUnderflowException e) {
        throw new SchemaException("Buffer underflow while parsing consumer protocol's subscription", e);
    }
}
Also used : SchemaException(org.apache.kafka.common.protocol.types.SchemaException) TopicPartition(org.apache.kafka.common.TopicPartition) ConsumerProtocolSubscription(org.apache.kafka.common.message.ConsumerProtocolSubscription) ArrayList(java.util.ArrayList) ByteBufferAccessor(org.apache.kafka.common.protocol.ByteBufferAccessor) Subscription(org.apache.kafka.clients.consumer.ConsumerPartitionAssignor.Subscription) ConsumerProtocolSubscription(org.apache.kafka.common.message.ConsumerProtocolSubscription) BufferUnderflowException(java.nio.BufferUnderflowException)

Aggregations

SchemaException (org.apache.kafka.common.protocol.types.SchemaException)6 BufferUnderflowException (java.nio.BufferUnderflowException)3 TopicPartition (org.apache.kafka.common.TopicPartition)3 AbstractResponse (org.apache.kafka.common.requests.AbstractResponse)3 ArrayList (java.util.ArrayList)2 IllegalSaslStateException (org.apache.kafka.common.errors.IllegalSaslStateException)2 ByteBufferAccessor (org.apache.kafka.common.protocol.ByteBufferAccessor)2 HashMap (java.util.HashMap)1 Assignment (org.apache.kafka.clients.consumer.ConsumerPartitionAssignor.Assignment)1 Subscription (org.apache.kafka.clients.consumer.ConsumerPartitionAssignor.Subscription)1 KafkaConsumer (org.apache.kafka.clients.consumer.KafkaConsumer)1 OffsetAndMetadata (org.apache.kafka.clients.consumer.OffsetAndMetadata)1 AuthenticationException (org.apache.kafka.common.errors.AuthenticationException)1 ConsumerProtocolAssignment (org.apache.kafka.common.message.ConsumerProtocolAssignment)1 ConsumerProtocolSubscription (org.apache.kafka.common.message.ConsumerProtocolSubscription)1 NetworkReceive (org.apache.kafka.common.network.NetworkReceive)1 ApiKeys (org.apache.kafka.common.protocol.ApiKeys)1 ByteArrayDeserializer (org.apache.kafka.common.serialization.ByteArrayDeserializer)1