コード例 #1
0
ファイル: base.py プロジェクト: nKey/brubeckservices
    def send(self, service_req):
        """Send will wait for a response with a listener and is async
        """
        service_req.conn_id = uuid4().hex

        header = "%s %s %s %s %s %s %s %s %s" % (self.sender_id, 
            t(service_req.conn_id), 
            t(service_req.request_timestamp),
            t(self.passphrase),
            t(service_req.origin_sender_id),
            t(service_req.origin_conn_id),
            t(service_req.origin_out_addr),
            t(service_req.path),
            t(service_req.method),
        )
        arguments = to_bytes(json.dumps(service_req.arguments))
        headers = to_bytes(json.dumps(service_req.headers))
        body = to_bytes(json.dumps(service_req.body))

        msg = ' %s %s%s%s' % (header, t(arguments),t(headers), t(body))
        logging.debug(
            "ServiceClientConnection send (%s:%s): %s" % (self.sender_id, service_req.conn_id, msg)
        )
        self.out_sock.send(msg)

        return service_req
コード例 #2
0
    def process_message(self, application, environ, callback):
        request = Request.parse_wsgi_request(environ)
        handler = application.route_message(request)
        result = handler()

        wsgi_status = ' '.join([str(result['status_code']), result['status_msg']])
        headers = [(k, v) for k,v in result['headers'].items()]
        print [to_bytes(result['body'])]
        #print inspect.getargspec(callback)
        print wsgi_status, headers
        callback(str(wsgi_status), headers)
        #from werkzeug.wrappers import Response
        #print result
        #return Response(response=result['body'], status=str(wsgi_status), headers=headers, mimetype=None, content_type='text/plain', direct_passthrough=False)
        #return Response(''.join([to_unicode(result['body'])]))
        return [to_bytes(result['body'])]
コード例 #3
0
ファイル: base.py プロジェクト: nKey/brubeckservices
    def send(self, service_response):
        """uuid = unique ID that both the client and server need to match
           conn_id = connection id from this request needed to wake up handler on response
           origin_uuid = unique ID from the original request
           origin_conn_id = the connection id from the original request
           origin_out_addr = the socket address that expects the final result
           msg = the payload (a JSON object)
           path = the path used to route to the proper response handler
        """

        service_response.end_timestamp = int(time.time() * 1000)

        header = "%s %s %s %s %s %s %s %s %s %s %s" % ( service_response.sender,
            t(service_response.conn_id),
            t(service_response.request_timestamp),
            t(service_response.start_timestamp),
            t(service_response.end_timestamp),
            t(self.passphrase),
            t(service_response.origin_sender_id),
            t(service_response.origin_conn_id),
            t(service_response.origin_out_addr),
            t(service_response.path),
            t(service_response.method),
        )
        status_code = to_bytes(str(json.dumps(service_response.status_code)))
        status_msg = to_bytes(json.dumps(service_response.status_msg))
        arguments = to_bytes(json.dumps(service_response.arguments))
        headers = to_bytes(json.dumps(service_response.headers))
        body = to_bytes(json.dumps(service_response.body))
        msg = '%s %s%s%s%s%s' % (header,
            t(status_code),
            t(status_msg),
            t(arguments),
            t(headers),
            t(body),
        )
        
        logging.debug("ServiceConnection send (%s) : \"%s\"" % (service_response.sender, msg))

        self.out_sock.send(service_response.sender, self.zmq.SNDMORE)
        self.out_sock.send("", self.zmq.SNDMORE)
        self.out_sock.send(msg, self.zmq.NOBLOCK)
        return