Beispiel #1
0
    def send_offset_request(
        self,
        payloads=None,
        fail_on_error=True,
        callback=None
    ):
        if payloads is None:
            payloads = []

        resps = []
        for req in payloads:
            if req.time == -1:
                offset = self.high_offsets[req.topic].get(req.partition, -1)
            else:
                offset = self.low_offsets[req.topic].get(req.partition, -1)
            if self.offset_request_error:
                error_code = NotLeaderForPartitionError.errno
            elif req.partition not in self.topics[req.topic]:
                error_code = UnknownTopicOrPartitionError.errno
            else:
                error_code = 0
            resps.append(OffsetResponsePayload(
                req.topic,
                req.partition,
                error_code,
                (offset,)
            ))

        return [resp if not callback else callback(resp) for resp in resps]
Beispiel #2
0
def _check_fetch_response_error(resp):
    try:
        check_error(resp)
    except BrokerResponseError:
        # In case of error we set the offset to (-1,)
        return OffsetResponsePayload(
            resp.topic,
            resp.partition,
            resp.error,
            (-1, ),
        )
    return resp