• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python tornado.TChannel类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中tchannel.tornado.TChannel的典型用法代码示例。如果您正苦于以下问题:Python TChannel类的具体用法?Python TChannel怎么用?Python TChannel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了TChannel类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: send

    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)
开发者ID:encrylife,项目名称:tchannel-python,代码行数:60,代码来源:patch.py


示例2: test_retry_on_error_success

def test_retry_on_error_success():

    endpoint = b'tchannelretrytest'
    tchannel = chain(2, endpoint)

    tchannel_success = TChannel(name='test', hostport='localhost:0')
    tchannel_success.register(endpoint, 'raw', handler_success)
    tchannel_success.listen()
    tchannel.peers.get(tchannel_success.hostport)

    with (
        patch(
            'tchannel.tornado.Request.should_retry_on_error',
            autospec=True)
    ) as mock_should_retry_on_error:
        mock_should_retry_on_error.return_value = True
        response = yield tchannel.request(
            score_threshold=0
        ).send(
            endpoint,
            "test",
            "test",
            headers={
                're': RetryType.CONNECTION_ERROR_AND_TIMEOUT,
            },
            ttl=0.01,
            attempt_times=3,
            retry_delay=0.01,
        )

        header = yield response.get_header()
        body = yield response.get_body()
        assert body == "success"
        assert header == ""
开发者ID:jonasrosland,项目名称:tchannel,代码行数:34,代码来源:test_retry.py


示例3: test_zipkin_trace

def test_zipkin_trace(trace_server):
    endpoint = b'endpoint1'
    zipkin_tracer = ZipkinTraceHook(dst=trace_buf)
    tchannel = TChannel(name='test')
    tchannel.hooks.register(zipkin_tracer)

    hostport = 'localhost:%d' % trace_server.port

    response = yield tchannel.request(hostport).send(InMemStream(endpoint),
                                                     InMemStream(hostport),
                                                     InMemStream(),
                                                     traceflag=True)
    header = yield response.get_header()
    body = yield response.get_body()
    assert header == "from handler1"
    assert body == "from handler2"
    traces = []
    for trace in trace_buf.getvalue().split("\n"):
        if trace:
            traces.append(json.loads(trace))

    trace_id = traces[0][0][u'trace_id']
    for trace in traces:
        assert trace_id == trace[0][u'trace_id']
        if trace[0][u'name'] == u'endpoint2':
            parent_span_id = trace[0][u'parent_span_id']
        else:
            span_id = trace[0][u'span_id']

    assert parent_span_id == span_id
开发者ID:Willyham,项目名称:tchannel-python,代码行数:30,代码来源:test_zipkin_trace.py


示例4: test_retry_on_error_success

def test_retry_on_error_success(mock_should_retry_on_error):
    mock_should_retry_on_error.return_value = True

    endpoint = b'tchannelretrytest'
    tchannel = yield chain(2, endpoint)
    hook = MyTestHook()
    tchannel.hooks.register(hook)

    tchannel_success = TChannel(name='test', hostport='localhost:0')
    tchannel_success.register(endpoint, 'raw', handler_success)
    tchannel_success.listen()
    tchannel.peers.get(tchannel_success.hostport)

    response = yield tchannel.request().send(
        endpoint,
        "test",
        "test",
        headers={
            're': retry.CONNECTION_ERROR_AND_TIMEOUT,
        },
        ttl=1,
        retry_limit=2,
    )

    header = yield response.get_header()
    body = yield response.get_body()
    assert body == "success"
    assert header == ""

    assert hook.received_response == 1
    assert hook.received_error == 2
开发者ID:dnathe4th,项目名称:tchannel-python,代码行数:31,代码来源:test_retry.py


示例5: main

def main():  # pragma: no cover
    import sys

    parser = argparse.ArgumentParser()
    parser.add_argument(
        "--port",
        dest="port", default=8888, type=int,
    )
    parser.add_argument(
        "--host",
        dest="host", default="127.0.0.1"
    )
    args = parser.parse_args()

    client = TChannel('%s:%d' % (args.host, args.port))

    # TODO: service=test_as_raw
    handler = RequestDispatcher()
    client.host(handler)

    # TODO: do we need to implement these differently?
    handler.register("echo", echo)
    handler.register("streaming_echo", echo)

    client.listen()
    print 'listening on', client.hostport
    sys.stdout.flush()

    tornado.ioloop.IOLoop.instance().start()
开发者ID:jonasrosland,项目名称:tchannel,代码行数:29,代码来源:test_server.py


示例6: main

def main():  # pragma: no cover
    args = get_args()

    client = TChannel('localhost:%d' % args.port)
    register_example_endpoints(client)
    client.listen()

    tornado.ioloop.IOLoop.instance().start()
开发者ID:jonasrosland,项目名称:tchannel,代码行数:8,代码来源:tchannel_server.py


示例7: test_request

def test_request():
    channel = TChannel(name="test")
    hyperbahn.advertise(channel, "foo", ["127.0.0.1:23000"])

    # Just want to make sure all the plumbing fits together.

    with pytest.raises(NoAvailablePeerError):
        yield channel.request(service="bar").send(arg1="baz", arg2="bam", arg3="boo", headers={"as": "qux"})
开发者ID:webmaven,项目名称:tchannel-python,代码行数:8,代码来源:test_hyperbahn.py


示例8: test_endpoint_not_found

def test_endpoint_not_found(tchannel_server):
    endpoint = b"tchanneltest"
    tchannel_server.expect_call(endpoint).and_write(headers=endpoint, body="world")
    tchannel = TChannel(name="test")

    hostport = "localhost:%d" % (tchannel_server.port)

    with pytest.raises(TChannelError):
        yield tchannel.request(hostport).send(InMemStream(), InMemStream(), InMemStream())
开发者ID:pengzhai,项目名称:tchannel,代码行数:9,代码来源:test_client_server.py


示例9: send_stream

def send_stream(arg1, arg2, arg3, host):
    tchannel = TChannel()
    response = yield tchannel.request(host).send(
        arg1,
        arg2,
        arg3)

    yield print_arg(response, 0)
    yield print_arg(response, 1)
    yield print_arg(response, 2)
开发者ID:jonasrosland,项目名称:tchannel,代码行数:10,代码来源:stream_client.py


示例10: send_stream

def send_stream(arg1, arg2, arg3, host):
    tchannel = TChannel(
        name='stream-client',
    )

    yield tchannel.request(host).send(
        arg1,
        arg2,
        arg3,
    )
开发者ID:invincible1388,项目名称:tchannel-python,代码行数:10,代码来源:stream_client.py


示例11: test_endpoint_not_found

def test_endpoint_not_found(mock_server):
    endpoint = b'tchanneltest'
    mock_server.expect_call(endpoint).and_write(
        headers=endpoint,
        body='world'
    )
    tchannel = TChannel(name='test')

    with pytest.raises(TChannelError):
        yield tchannel.request(
            mock_server.hostport
        ).send(InMemStream(), InMemStream(), InMemStream())
开发者ID:Willyham,项目名称:tchannel-python,代码行数:12,代码来源:test_client_server.py


示例12: main

def main():  # pragma: no cover
    args = get_args()

    client = TChannel(
        name='tchannel_server',
        hostport='%s:%d' % (args.host, args.port),
    )

    register_example_endpoints(client)
    client.listen()

    tornado.ioloop.IOLoop.instance().start()
开发者ID:pengzhai,项目名称:tchannel,代码行数:12,代码来源:tchannel_server.py


示例13: test_request

def test_request():
    channel = TChannel()
    hyperbahn.advertise(channel, 'foo', ['127.0.0.1:23000'])

    # Just want to make sure all the plumbing fits together.
    with pytest.raises(ConnectionClosedError):
        yield channel.request(service='bar').send(
            arg1='baz',
            arg2='bam',
            arg3='boo',
            headers={'as': 'qux'},
        )
开发者ID:oibe,项目名称:tchannel,代码行数:12,代码来源:test_hyperbahn.py


示例14: main

def main():

    args = get_args()

    tchannel = TChannel(name="raw-client")

    request = tchannel.request(hostport="%s:%s" % (args.host, args.port))

    response = yield request.send("hi", None, None)

    body = yield response.get_body()

    print body
开发者ID:invincible1388,项目名称:tchannel-python,代码行数:13,代码来源:raw_client.py


示例15: test_endpoint_not_found

def test_endpoint_not_found(tchannel_server):
    endpoint = b'tchanneltest'
    tchannel_server.expect_call(endpoint).and_write(
        headers=endpoint,
        body='world'
    )
    tchannel = TChannel()

    hostport = 'localhost:%d' % (tchannel_server.port)

    with pytest.raises(TChannelError):
        yield tchannel.request(hostport).send(InMemStream(),
                                              InMemStream(),
                                              InMemStream())
开发者ID:oibe,项目名称:tchannel,代码行数:14,代码来源:test_client_server.py


示例16: test_tchannel_call_request_fragment

def test_tchannel_call_request_fragment(tchannel_server, arg2, arg3):
    endpoint = b"tchannelpeertest"

    tchannel_server.expect_call(endpoint).and_write(headers=endpoint, body=arg3)

    tchannel = TChannel(name="test")

    hostport = "localhost:%d" % (tchannel_server.port)

    response = yield tchannel.request(hostport).send(InMemStream(endpoint), InMemStream(arg2), InMemStream(arg3))
    header = yield response.get_header()
    body = yield response.get_body()
    assert header == endpoint
    assert body == arg3
    assert response.headers["as"] == "raw"
开发者ID:pengzhai,项目名称:tchannel,代码行数:15,代码来源:test_client_server.py


示例17: main

def main():
    args = get_args()

    app = TChannel(
        name='raw-server',
        hostport='%s:%d' % (args.host, args.port),
    )

    register_example_endpoints(app)

    app.listen()

    print("listening on %s" % app.hostport)
    sys.stdout.flush()

    tornado.ioloop.IOLoop.instance().start()
开发者ID:invincible1388,项目名称:tchannel-python,代码行数:16,代码来源:raw_server.py


示例18: test_tchannel_call_request_fragment

def test_tchannel_call_request_fragment(mock_server,
                                        arg2, arg3):
    endpoint = b'tchannelpeertest'

    mock_server.expect_call(endpoint).and_write(
        headers=endpoint, body=arg3
    )

    tchannel = TChannel(name='test')
    response = yield tchannel.request(mock_server.hostport).send(
        InMemStream(endpoint), InMemStream(arg2), InMemStream(arg3)
    )
    header = yield response.get_header()
    body = yield response.get_body()
    assert header == endpoint
    assert body == arg3
    assert response.headers['as'] == 'raw'
开发者ID:Willyham,项目名称:tchannel-python,代码行数:17,代码来源:test_client_server.py


示例19: main

def main():
    args = get_args()

    app = TChannel(
        name='json-server',
        hostport='%s:%d' % (args.host, args.port),
    )

    register_example_endpoints(app)

    def say_hi_json(request, response, proxy):
        response.write_body({'hi': 'Hello, world!'})

    app.register(endpoint="hi-json", scheme="json", handler=say_hi_json)

    app.listen()

    tornado.ioloop.IOLoop.instance().start()
开发者ID:invincible1388,项目名称:tchannel-python,代码行数:18,代码来源:json_server.py


示例20: test_false_result

def test_false_result(thrift_service):
    # Verify that we aren't treating False as None.

    app = TChannel(name='app')

    @app.register(thrift_service)
    def healthy(request, response):
        return False

    app.listen()

    client = TChannel(name='client')
    response = yield client.request(
        hostport=app.hostport, arg_scheme='thrift'
    ).send('Service::healthy', '\x00\x00', '\x00')

    body = yield response.get_body()
    assert body == '\x02\x00\x00\x00\x00'
开发者ID:encrylife,项目名称:tchannel-python,代码行数:18,代码来源:test_tornado_client.py



注:本文中的tchannel.tornado.TChannel类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python tcmessages.TeamcityServiceMessages类代码示例发布时间:2022-05-27
下一篇:
Python thrift.load函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap