def _process_response(self, read_buffer):
        recv_correlation_id = Int32.decode(read_buffer)
        log.debug("Received correlation id: %d", recv_correlation_id)

        if not self.in_flight_requests:
            raise Errors.CorrelationIdError(
                "No in-flight-request found for server response"
                " with correlation ID %d" % (recv_correlation_id, ))

        (correlation_id, request) = self.in_flight_requests.popleft()

        # 0.8.2 quirk
        if (recv_correlation_id == 0 and correlation_id != 0
                and request.RESPONSE_TYPE is GroupCoordinatorResponse[0] and
            (self._api_version == (0, 8, 2) or self._api_version is None)):
            log.warning("Kafka 0.8.2 quirk -- GroupCoordinatorResponse"
                        " Correlation ID does not match request. This"
                        " should go away once at least one topic has been"
                        " initialized on the broker.")

        elif correlation_id != recv_correlation_id:
            # return or raise?
            raise Errors.CorrelationIdError(
                "Correlation IDs do not match: sent %d, recv %d" %
                (correlation_id, recv_correlation_id))

        # decode response
        log.debug("Processing response %s", request.RESPONSE_TYPE.__name__)
        try:
            response = request.RESPONSE_TYPE.decode(read_buffer)
        except ValueError:
            read_buffer.seek(0)
            buf = read_buffer.read()
            log.error(
                "Response %d [ResponseType: %s Request: %s]:"
                " Unable to decode %d-byte buffer: %r",
                correlation_id,
                request.RESPONSE_TYPE,
                request,
                len(buf),
                buf,
            )
            raise Errors.KafkaProtocolError("Unable to decode response")

        return (correlation_id, response)
Beispiel #2
0
    def _process_response(self, read_buffer):
        if not self.in_flight_requests:
            raise Errors.CorrelationIdError(
                'No in-flight-request found for server response')
        (correlation_id, request) = self.in_flight_requests.popleft()
        response_header = request.parse_response_header(read_buffer)
        recv_correlation_id = response_header.correlation_id
        log.debug('Received correlation id: %d', recv_correlation_id)
        # 0.8.2 quirk
        if (recv_correlation_id == 0 and
            correlation_id != 0 and
            request.RESPONSE_TYPE is GroupCoordinatorResponse[0] and
                (self._api_version == (0, 8, 2) or self._api_version is None)):
            log.warning('Kafka 0.8.2 quirk -- GroupCoordinatorResponse'
                        ' Correlation ID does not match request. This'
                        ' should go away once at least one topic has been'
                        ' initialized on the broker.')

        elif correlation_id != recv_correlation_id:
            # return or raise?
            raise Errors.CorrelationIdError(
                'Correlation IDs do not match: sent %d, recv %d'
                % (correlation_id, recv_correlation_id))

        # decode response
        log.debug('Processing response %s', request.RESPONSE_TYPE.__name__)
        try:
            response = request.RESPONSE_TYPE.decode(read_buffer)
        except ValueError:
            read_buffer.seek(0)
            buf = read_buffer.read()
            log.error('Response %d [ResponseType: %s Request: %s]:'
                      ' Unable to decode %d-byte buffer: %r',
                      correlation_id, request.RESPONSE_TYPE,
                      request, len(buf), buf)
            raise Errors.KafkaProtocolError('Unable to decode response')

        return (correlation_id, response)