def main(): logging.info("Starting...") # Declare the protocol stack used for serialization. # Protocol stacks must match between clients and servers. prot_factory = FProtocolFactory(TBinaryProtocol.TBinaryProtocolFactory()) # Create an HTTP transport for the server URL transport = THttpTransport(URL) transport.open() # Using the configured transport and protocol, create a client # to talk to the music store service. store_client = FStoreClient(FServiceProvider(transport, prot_factory)) album = store_client.buyAlbum(FContext(), str(uuid.uuid4()), "ACT-12345") root.info("Bought an album %s\n", album) store_client.enterAlbumGiveaway(FContext(), "*****@*****.**", "Kevin") # Close the transport transport.close()
def __init__(self): self.context = FContext() self.transport = HttpClient(config.BASE_URL + "/LIFF1") self.protocol_factory = TCompactProtocolAcceleratedFactory() self.wrapper_factory = LegyProtocolFactory(self.protocol_factory) self.service_provider = FServiceProvider(self.transport, self.wrapper_factory) self.client = self.LiffClients()
async def main(): # Declare the protocol stack used for serialization. # Protocol stacks must match between clients and servers. prot_factory = FProtocolFactory(TBinaryProtocol.TBinaryProtocolFactory()) # Open a NATS connection to send requests nats_client = NatsClient() options = {"verbose": True, "servers": ["nats://127.0.0.1:4222"]} await nats_client.connect(**options) # Create a nats transport using the connected client # The transport sends data on the music-service NATS topic nats_transport = FNatsTransport(nats_client, "music-service") try: await nats_transport.open() except TTransportException as ex: root.error(ex) return # Using the configured transport and protocol, create a client # to talk to the music store service. store_client = FStoreClient(FServiceProvider(nats_transport, prot_factory), middleware=logging_middleware) album = await store_client.buyAlbum(FContext(), str(uuid.uuid4()), "ACT-12345") root.info("Bought an album %s\n", album.tracks[0].title) await store_client.enterAlbumGiveaway(FContext(), "*****@*****.**", "Kevin") # Close transport and nats client await nats_transport.close() await nats_client.close()
def main(): parser = argparse.ArgumentParser(description="Run a python tornado client") parser.add_argument('--port', dest='port', default='9090') parser.add_argument('--protocol', dest='protocol_type', default="binary", choices="binary, compact, json") parser.add_argument('--transport', dest='transport_type', default=NATS_NAME, choices="nats, http") args = parser.parse_args() protocol_factory = get_protocol_factory(args.protocol_type) nats_client = NATS() logging.debug("Connecting to NATS") yield nats_client.connect(**get_nats_options()) transport = None if args.transport_type == NATS_NAME: transport = FNatsTransport(nats_client, "frugal.foo.bar.rpc.{}".format(args.port)) elif args.transport_type == HTTP_NAME: # Set request and response capacity to 1mb max_size = 1048576 transport = FHttpTransport("http://localhost:" + str(args.port), request_capacity=max_size, response_capacity=max_size) else: print("Unknown transport type: {}".format(args.transport_type)) sys.exit(1) try: yield transport.open() except TTransportException as ex: logging.error(ex) raise gen.Return() client = FrugalTestClient(FServiceProvider(transport, protocol_factory), client_middleware) ctx = FContext("test") yield test_rpc(client, ctx, args.transport_type) if transport == NATS_NAME: yield test_pub_sub(nats_client, protocol_factory, args.port) global middleware_called if not middleware_called: print("Client middleware never invoked") exit(1) # Cleanup after tests yield nats_client.close()
async def main(): parser = argparse.ArgumentParser(description="Run a python asyncio client") parser.add_argument('--port', dest='port', default='9090') parser.add_argument('--protocol', dest='protocol_type', default="binary", choices="binary, compact, json") parser.add_argument('--transport', dest='transport_type', default=NATS_NAME, choices="nats, http") args = parser.parse_args() protocol_factory = get_protocol_factory(args.protocol_type) nats_client = NatsClient() await nats_client.connect(**get_nats_options()) transport = None if args.transport_type == NATS_NAME: transport = FNatsTransport(nats_client, "frugal.foo.bar.rpc.{}".format(args.port)) await transport.open() elif args.transport_type == HTTP_NAME: # Set request and response capacity to 1mb max_size = 1048576 transport = FHttpTransport( "http://localhost:{port}".format(port=args.port), request_capacity=max_size, response_capacity=max_size) else: print( "Unknown transport type: {type}".format(type=args.transport_type)) sys.exit(1) client = FrugalTestClient(FServiceProvider(transport, protocol_factory), client_middleware) ctx = FContext("test") await test_rpc(client, ctx, args.transport_type) if transport == NATS_NAME: await test_pub_sub(nats_client, protocol_factory, args.port) await nats_client.close()
def get_provider(self, path, headers) -> FServiceProvider: """FServiceProviderクラスを生成する関数 http clientとprotocol factoryを取得し、FServiceProviderに渡す。 Args: path: APIエンドポイントのpath headers: httpヘッダー Return: `FServiceProvider` """ http_client = HttpClientFactory(self.host).get_client(path, headers) protocol_factory = TCompactProtocolAcceleratedFactory() return FServiceProvider(http_client, LineProtocolFactory(protocol_factory))
async def main(): parser = argparse.ArgumentParser(description="Run a python asyncio client") parser.add_argument('--port', dest='port', default='9090') parser.add_argument('--protocol', dest='protocol_type', default="binary", choices="binary, compact, json") parser.add_argument('--transport', dest='transport_type', default="stateless", choices="stateless, stateless-stateful, http") args = parser.parse_args() protocol_factory = get_protocol_factory(args.protocol_type) nats_client = NatsClient() await nats_client.connect(**get_nats_options()) transport = None if args.transport_type in ["stateless", "stateless-stateful"]: transport = FNatsTransport(nats_client, "frugal.foo.bar.rpc.{}".format(args.port)) await transport.open() elif args.transport_type == "http": transport = FHttpTransport( "http://localhost:{port}".format(port=args.port)) else: print( "Unknown transport type: {type}".format(type=args.transport_type)) sys.exit(1) client = FrugalTestClient(FServiceProvider(transport, protocol_factory), client_middleware) ctx = FContext("test") await test_rpc(client, ctx) await test_pub_sub(nats_client, protocol_factory, args.port) await nats_client.close()
async def main(): # Declare the protocol stack used for serialization. # Protocol stacks must match between clients and servers. prot_factory = FProtocolFactory(TBinaryProtocol.TBinaryProtocolFactory()) # Create an HTTP to query the configured server URL transport = FHttpTransport("http://*****:*****@workiva.com", "Kevin") await transport.close()
def main(): parser = argparse.ArgumentParser(description="Run a vanilla python client") parser.add_argument('--port', dest='port', default='9090') parser.add_argument('--protocol', dest='protocol_type', default="binary", choices="binary, compact, json") parser.add_argument('--transport', dest='transport_type', default="http", choices="http") args = parser.parse_args() protocol_factory = get_protocol_factory(args.protocol_type) if args.transport_type == "http": transport = THttpTransport("http://localhost:" + str(args.port)) else: print("Unknown transport type: {}".format(args.transport_type)) sys.exit(1) transport.open() ctx = FContext("test") client = FrugalTestClient(FServiceProvider(transport, protocol_factory), client_middleware) # Scope generation is not currently supported with vanilla python # TODO: Add Pub/Sub test once scopes are supported test_rpc(client, ctx) global middleware_called if not middleware_called: print("Client middleware never invoked") exit(1) transport.close()
# -*- coding: utf-8 -*-