You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2020/08/19 14:56:38 UTC
[GitHub] [flink-statefun] igalshilman opened a new pull request #134: [FLINK-18518] Add AsyncRequestReplyHandler for the Python SDK
igalshilman opened a new pull request #134:
URL: https://github.com/apache/flink-statefun/pull/134
This PR allows registering asynchronous python functions as stateful functions, by introducing a new handler: `AsyncRequestReplyHandler`.
Invocation of `AsyncRequestReplyHandler` handler produces a future that can be `await`ed on, which makes this handler usable in completely asynchronous web frameworks (like `aiohttp`)
Here is an example remote function implementation that uses `aiohttp` with the new async handler:
```
import aiohttp
import asyncio
...
async def fetch(session, url):
async with session.get(url) as response:
return await response.text()
@function.bind("example/hello")
async def hello(context, message):
async with aiohttp.ClientSession() as session:
html = await fetch(session, 'http://python.org')
context.pack_and_reply(SomeProtobufMessage(html))
from aiohttp import webhandler
handler = AsyncRequestReplyHandler(functions)
async def handle(request):
req = await request.read()
res = await handler(req)
return web.Response(body=res, content_type="application/octet-stream'")
app = web.Application()
app.add_routes([web.post('/statefun', handle)])
if __name__ == '__main__':
web.run_app(app, port=5000)
```
The changes in this PR are as follows:
* Refactoring common functionally between an async-handler and sync-handler into a common handler
* add an async handler
* add an example and IT test.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink-statefun] sjwiesman commented on pull request #134: [FLINK-18518] Add AsyncRequestReplyHandler for the Python SDK
Posted by GitBox <gi...@apache.org>.
sjwiesman commented on pull request #134:
URL: https://github.com/apache/flink-statefun/pull/134#issuecomment-677802701
#docs
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink-statefun] igalshilman commented on pull request #134: [FLINK-18518] Add AsyncRequestReplyHandler for the Python SDK
Posted by GitBox <gi...@apache.org>.
igalshilman commented on pull request #134:
URL: https://github.com/apache/flink-statefun/pull/134#issuecomment-678976248
Would be followed on the docs sprint, thanks for the reminder.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink-statefun] tzulitai closed pull request #134: [FLINK-18518] Add AsyncRequestReplyHandler for the Python SDK
Posted by GitBox <gi...@apache.org>.
tzulitai closed pull request #134:
URL: https://github.com/apache/flink-statefun/pull/134
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org