本文整理汇总了Python中tchannel.tornado.TChannel.thrift方法的典型用法代码示例。如果您正苦于以下问题:Python TChannel.thrift方法的具体用法?Python TChannel.thrift怎么用?Python TChannel.thrift使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tchannel.tornado.TChannel
的用法示例。
在下文中一共展示了TChannel.thrift方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: send
# 需要导入模块: from tchannel.tornado import TChannel [as 别名]
# 或者: from tchannel.tornado.TChannel import thrift [as 别名]
def send(self, arg1, arg2, arg3,
headers=None,
traceflag=None,
retry_limit=None,
ttl=None):
arg1, arg2, arg3 = map(maybe_stream, [arg1, arg2, arg3])
endpoint = yield read_full(arg1)
headers = headers or {}
headers.setdefault('as', self.arg_scheme)
vcr_request = proxy.Request(
serviceName=self.service.encode('utf-8'),
hostPort=self.hostport,
knownPeers=self.original_tchannel.peers.hosts,
endpoint=endpoint,
headers=(yield read_full(arg2)),
body=(yield read_full(arg3)),
argScheme=getattr(proxy.ArgScheme, self.arg_scheme.upper()),
transportHeaders=[
proxy.TransportHeader(bytes(k), bytes(v))
for k, v in headers.items()
],
)
# TODO what to do with traceflag, attempt-times, ttl
# TODO catch protocol errors
from tchannel import TChannel
tchannel = TChannel('proxy-client')
with force_reset():
vcr_response_future = tchannel.thrift(
proxy.VCRProxy.send(vcr_request),
hostport=self.vcr_hostport,
)
try:
vcr_response = yield vcr_response_future
except proxy.RemoteServiceError as e:
raise TChannelError.from_code(
e.code,
description=(
"The remote service threw a protocol error: %s" %
e.message
)
)
response = Response(
code=vcr_response.body.code,
argstreams=[
maybe_stream(endpoint),
maybe_stream(vcr_response.body.headers),
maybe_stream(vcr_response.body.body),
],
# TODO headers=vcr_response.transportHeaders,
)
raise gen.Return(response)