Last active
June 27, 2024 15:55
-
-
Save HelloGrayson/ca4f6b9c17861327aa8a to your computer and use it in GitHub Desktop.
tchannel .call api change
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # raw | |
| response = yield tchannel.call( | |
| argscheme="raw", | |
| service="someservice", | |
| endpoint="something", | |
| body="RAWRESPONSE", | |
| headers={ | |
| 'X-Source': 'geo' | |
| }, | |
| ttl=1000 | |
| ) | |
| # json | |
| response = yield tchannel.call( | |
| argscheme = "json" | |
| service="someservice", | |
| endpoint="maps", | |
| body="{ | |
| 'lat': 100, | |
| 'lng': 140 | |
| }", | |
| headers={ | |
| 'X-Source': 'geo' | |
| }, | |
| ttl=1000 | |
| ) | |
| # thrift | |
| Foo = get_tchannel_thrift(FooThrift, 'fooservice') | |
| response = yield tchannel.call( | |
| argscheme="thrift", | |
| "some_binary", | |
| headers={ | |
| 'X-Source': 'geo' | |
| }, | |
| ttl=1000 | |
| ) | |
| response = yield tchannel.call_thrift( | |
| Foo.getBar(Foo.BarResponse("hi")), | |
| headers={ | |
| 'X-Source': 'geo' | |
| }, | |
| timeout=5000 | |
| ) | |
| response = yield tchannel.as_thrift().call( | |
| Foo.getBar(Foo.BarResponse("hi")), | |
| headers={ | |
| 'X-Source': 'geo' | |
| }, | |
| timeout=5000 | |
| ) | |
| response = yield tchannel.thrift.call( | |
| Foo.getBar(Foo.BarResponse("hi")), | |
| headers={ | |
| 'X-Source': 'geo' | |
| }, | |
| timeout=5000 | |
| ) | |
| future = tchannel_sync.call( | |
| Foo.baz(True), | |
| headers={ | |
| 'X-Source': 'geo' | |
| }, | |
| ttl=1000 | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Based on discussion earlier, this is how we expect the client-side streaming API to look:
Response streaming
We'll introduce a
streammethod on theTChannelobject and its argscheme-specific proxies that will accept the same arguments ascall. Instead of a standard response, it'll return a streaming response object which provides a.read()method.Request streaming
We'll have a
body_producerparameter on bothcallandstream.body_producermay be passed in lieu of thebody. It will be a function that accepts awritefunction and calls it to write to the stream. The function must be a coroutine, or return a function that resolves to None when it finishes writing.