apocolipse/Thrift-Swift

how to make rpc call via TAsyncClient

Closed this issue · 6 comments

icoco commented

seem TAsyncClient is not completed yet ?

When you are generating the source code of a service for swift, make sure you use the async flag.

thrift --gen swift:async_clients,safe_enums service.thrift

That will generate the necessary code for you to start using an AsyncClient for your service.

icoco commented

AsyncClient can generated now, but trouble to use it via TAsyncTransportFactory,

the protocol TAsyncTransport also need implemented or else TAsyncTransportFactory can not be instance, anyone can show a example code that make AsyncClient call thrift service ... thanks

For the async client, you can do something like this assuming a service called Service that has a function ping(param)

private let client: ServiceAsyncClient<TBinaryProtocol, THTTPSessionTransport.Factory>? = {
  let url = URL(string: "https://someservice.com:8443/")! // any port here, matches server
  let session = URLSession.shared
  let factory = THTTPSessionTransport.Factory(session: session, url: url)
  return ServiceAsyncClient(with: TBinaryProtocol.self, factory: factory)
}()

Then you can call the ping function by doing something like:

let param = ...
self.client?.ping(param, completion: { (result) in
  do {
    let value = try result.value()
    // ...
  } catch let e {
    print(e)
  }
})
icoco commented

problem is my thrift server provide "ThriftProcessPoolServer" ... it seem also does not support THTTPSessionTransport

Ah ok, check our README for the supported list of Transports and Protocols.

Whichever transport and protocol you decide in your server, the client will have to match.
In my example above, the Server will have conformed to the Binary protocol over the HTTPSession transport, and can only server up traffic to clients that match.

icoco commented

I see, thanks a lots