Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to make rpc call via TAsyncClient #29

Closed
icoco opened this issue Aug 12, 2019 · 6 comments
Closed

how to make rpc call via TAsyncClient #29

icoco opened this issue Aug 12, 2019 · 6 comments

Comments

@icoco
Copy link

icoco commented Aug 12, 2019

seem TAsyncClient is not completed yet ?

@wyland
Copy link
Collaborator

wyland commented Aug 13, 2019

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
Copy link
Author

icoco commented Aug 14, 2019

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

@wyland
Copy link
Collaborator

wyland commented Aug 14, 2019

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
Copy link
Author

icoco commented Aug 14, 2019

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

@wyland
Copy link
Collaborator

wyland commented Aug 14, 2019

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
Copy link
Author

icoco commented Aug 14, 2019

I see, thanks a lots

@wyland wyland closed this as completed Aug 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants