Send a request to Kafka

        Arguments::
            request_id (int): can be any int (used only for debug logging...)
            payload: an encoded kafka packet (see KafkaProtocol)
549161
def send(self, request_id, payload):
        

        log.debug("About to send %d bytes to Kafka, request %d" % (len(payload), request_id))

        # Make sure we have a connection
        if not self._sock:
            self.reinit()

        try:
            self._sock.sendall(payload)
        except socket.error:
            log.exception('Unable to send payload to Kafka')
            self._raise_connection_error()
642234
def send(self, topic, *args, **kwargs):
        
        prefix_topic = self.heroku_kafka.prefix_topic(topic)
        return super(HerokuKafkaProducer, self).send(prefix_topic, *args, **kwargs)
849097
def send_request(params)
      params['response'] = 'json'
      params['apiKey'] = @api_key
      print_debug_output JSON.pretty_generate(params) if @debug

      data = params_to_data(params)
      uri = URI.parse "#{@api_url}?#{data}&signature=#{create_signature(data)}"

      http = Net::HTTP.new(uri.host, uri.port)
      if uri.scheme == 'https'
        http.use_ssl = true
        http.verify_mode = OpenSSL::SSL::VERIFY_NONE
      end

      begin
        response = http.request(Net::HTTP::Get.new(uri.request_uri))
      rescue
        raise ConnectionError, "API URL \'#{@api_url}\' is not reachable."
      end

      begin
        body = JSON.parse(response.body).values.first
      rescue JSON::ParserError
        raise ParseError,
          "Response from server is not readable. Check if the API endpoint (#{@api_url}) is valid and accessible."
      end

      if response.is_a?(Net::HTTPOK)
        return body unless body.respond_to?(:keys)
        if body.size == 2 && body.key?('count')
          return body.reject { |key, _| key == 'count' }.values.first
        elsif body.size == 1 && body.values.first.respond_to?(:keys)
          item = body.values.first
          return (item.is_a?(Array) || item.is_a?(Hash)) ? item : []
        else
          body.reject! { |key, _| key == 'count' } if body.key?('count')
          body.size == 0 ? [] : body
        end
      else
        message = body['errortext'] rescue body
        raise ApiError, "Status #{response.code}: #{message}."
      end
    end
1052619
def encode_request(name, entry_processor, keys):
    
    client_message = ClientMessage(payload_size=calculate_size(name, entry_processor, keys))
    client_message.set_message_type(REQUEST_TYPE)
    client_message.set_retryable(RETRYABLE)
    client_message.append_str(name)
    client_message.append_data(entry_processor)
    client_message.append_int(len(keys))
    for keys_item in keys:
        client_message.append_data(keys_item)
    client_message.update_frame_length()
    return client_message
165421
def _do_request(self, method, *args, **kwargs):
        
        log('Doing HTTP [{3}] request: {0} - headers: {1} - payload: {2}'.format(
            args[0], kwargs.get('headers'), kwargs.get('json'), method,),
            level=logging.DEBUG,)
        requests_method = getattr(requests, method)
        return self._handle_response(requests_method(*args, **kwargs))
965854
def send_pending_requests(self):
        """"""
        try:
            with self._lock:
                if not self._can_send_recv():
                    return Errors.NodeNotReadyError(str(self))
                # In the future we might manage an internal write buffer
                # and send bytes asynchronously. For now, just block
                # sending each request payload
                data = self._protocol.send_bytes()
                total_bytes = self._send_bytes_blocking(data)
            if self._sensors:
                self._sensors.bytes_sent.record(total_bytes)
            return total_bytes
        except ConnectionError as e:
            log.exception("Error sending request data to %s", self)
            error = Errors.KafkaConnectionError("%s: %s" % (self, e))
            self.close(error=error)
            return error
1181130
def send_connect_request(self, connection_id):
        
        connect_message = ConnectionRequest(endpoint=self._public_endpoint)
        self._safe_send(
            validator_pb2.Message.NETWORK_CONNECT,
            connect_message.SerializeToString(),
            connection_id,
            callback=partial(
                self._inbound_connection_request_callback,
                connection_id=connection_id))
761241
async def send(self, request):
        
        body = bytes(request)
        msg_id = self._state._get_new_msg_id()
        await self._connection.send(
            struct.pack('<qqi', 0, msg_id, len(body)) + body
        )

        body = await self._connection.recv()
        if len(body) < 8:
            raise InvalidBufferError(body)

        with BinaryReader(body) as reader:
            auth_key_id = reader.read_long()
            assert auth_key_id == 0, 'Bad auth_key_id'

            msg_id = reader.read_long()
            assert msg_id != 0,  'Bad msg_id'
            # ^ We should make sure that the read ``msg_id`` is greater
            # than our own ``msg_id``. However, under some circumstances
            # (bad system clock/working behind proxies) this seems to not
            # be the case, which would cause endless assertion errors.

            length = reader.read_int()
            assert length > 0,  'Bad length'
            # We could read length bytes and use those in a new reader to read
            # the next TLObject without including the padding, but since the
            # reader isn't used for anything else after this, it's unnecessary.
            return reader.tgread_object()
751032
private synchronized void sendPayloadRequest(final PayloadData payload) {
		ApptentiveLog.v(PAYLOADS, "Sending payload: %s", payload);

		// create request object
		final HttpRequest payloadRequest = requestSender.createPayloadSendRequest(payload, new HttpRequest.Listener<HttpRequest>() {
			@Override
			public void onFinish(HttpRequest request) {
				try {
					String json = StringUtils.isNullOrEmpty(request.getResponseData()) ? "{}" : request.getResponseData();
					final JSONObject responseData = new JSONObject(json);
					handleFinishSendingPayload(payload, false, null, request.getResponseCode(), responseData);
				} catch (Exception e) {
					// TODO: Stop assuming the response is JSON. In fact, just send bytes back, and whatever part of the SDK needs it can try to convert it to the desired format.
					ApptentiveLog.e(PAYLOADS, e, "Exception while handling payload send response");
					logException(e);

					handleFinishSendingPayload(payload, false, null, -1, null);
				}
			}

			@Override
			public void onCancel(HttpRequest request) {
				handleFinishSendingPayload(payload, true, null, request.getResponseCode(), null);
			}

			@Override
			public void onFail(HttpRequest request, String reason) {
				if (request.isAuthenticationFailure()) {
					ApptentiveNotificationCenter.defaultCenter().postNotification(NOTIFICATION_AUTHENTICATION_FAILED, NOTIFICATION_KEY_CONVERSATION_ID, payload.getConversationId(), NOTIFICATION_KEY_AUTHENTICATION_FAILED_REASON, request.getAuthenticationFailedReason());
				}
				handleFinishSendingPayload(payload, false, reason, request.getResponseCode(), null);
			}
		});

		// set 'retry' policy
		payloadRequest.setRetryPolicy(requestRetryPolicy);
		payloadRequest.setCallbackQueue(conversationQueue());
		payloadRequest.start();
	}
64693
def send_message(
        self, request: str, response_expected: bool, **kwargs: Any
    ) -> Response:
        
        payload = str(request) + self.delimiter
        self.socket.send(payload.encode(self.encoding))

        response = bytes()
        decoded = None

        # Receive the response until we find the delimiter.
        # TODO Do not wait for a response if the message sent is a notification.
        while True:
            response += self.socket.recv(1024)

            decoded = response.decode(self.encoding)
            if len(decoded) < self.delimiter_length:
                continue

            # TODO Check that're not in the middle of the response.
            elif decoded[-self.delimiter_length :] == self.delimiter:
                break

        assert decoded is not None
        return Response(decoded[: -self.delimiter_length])
471461
def send_offset_fetch_request(self, group, payloads=None,
                                  fail_on_error=True, callback=None):
        
        encoder = partial(KafkaCodec.encode_offset_fetch_request,
                          group=group)
        decoder = KafkaCodec.decode_offset_fetch_response
        resps = yield self._send_broker_aware_request(
            payloads, encoder, decoder, consumer_group=group)

        returnValue(self._handle_responses(
            resps, fail_on_error, callback, group))
889644
def send_request(self, api_name, *api_args, **api_kwargs):
        
        return self.conn.request(api_name, *api_args, **api_kwargs)
1313591
def send(self, payload, *args, **kwargs):
        
        if isinstance(payload, (list, dict)):
            payload = json.dumps(payload)

        self.sendMessage(payload.encode(), *args, **kwargs)
407710
def handle(self, key, value):
        '''
        
        '''
        # the master dict to return
        master = {}
        master['uuid'] = value
        master['total_pending'] = 0
        master['server_time'] = int(self.get_current_time())

        # break down key
        elements = key.split(":")
        dict = {}
        dict['spiderid'] = elements[1]
        dict['appid'] = elements[2]

        # log we received the info message
        extras = self.get_log_dict('info', dict['appid'],
                                   dict['spiderid'], master['uuid'])

        if len(elements) == 4:
            dict['crawlid'] = elements[3]
            extras = self.get_log_dict('info', dict['appid'],
                                       dict['spiderid'], master['uuid'],
                                       elements[3])
        self.logger.info('Received info request', extra=extras)

        # generate the information requested
        if 'crawlid' in dict:
            master = self._build_crawlid_info(master, dict)
        else:
            master = self._build_appid_info(master, dict)

        if self._send_to_kafka(master):
            extras['success'] = True
            self.logger.info('Sent info to kafka', extra=extras)
        else:
            extras['success'] = False
            self.logger.error('Failed to send info to kafka',
                              extra=extras)
953211
def send_request(payload)
      response = @http.post payload
      raise APIError, response unless response.is_a?(Net::HTTPSuccess)
      response
    end
150185
def _CaptureRequestLogId(self):
    
    # pylint: disable=not-callable
    if callable(request_log_id_collector):
      request_log_id = request_log_id_collector()
      if request_log_id:
        # We have a request_log_id, save it into the breakpoint labels
        self.breakpoint['labels'][
            labels.Breakpoint.REQUEST_LOG_ID] = request_log_id
1347812
def send_fetch_request(self, payloads=None, fail_on_error=True,
                           callback=None,
                           max_wait_time=DEFAULT_FETCH_SERVER_WAIT_MSECS,
                           min_bytes=DEFAULT_FETCH_MIN_BYTES):
        
        if (max_wait_time / 1000) > (self.timeout - 0.1):
            raise ValueError(
                "%r: max_wait_time: %d must be less than client.timeout by "
                "at least 100 milliseconds.", self, max_wait_time)

        encoder = partial(KafkaCodec.encode_fetch_request,
                          max_wait_time=max_wait_time,
                          min_bytes=min_bytes)

        # resps is a list of FetchResponse() objects, each of which can hold
        # 1-n messages.
        resps = yield self._send_broker_aware_request(
            payloads, encoder,
            KafkaCodec.decode_fetch_response)

        returnValue(self._handle_responses(resps, fail_on_error, callback))