支持MessagePack的signarcore异步分叉:一个Python信号器核心客户机,具有调用授权和双向流。与azure/serverless功能兼容。还有自动重新连接和手动重新连接。
signalrcore-async的Python项目详细描述
信号器核心客户端
这个signaler核心客户端是从mandrewcito派生出来的。主要区别在于用异步websockets
库替换同步websocket-client
库。此外,所有方法都是异步的。在
有关一般介绍,请参见https://github.com/mandrewcito/signalrcore。在
请参阅以下示例以了解这些更改:
importasynciofromsignalrcore_async.hub_connection_builderimportHubConnectionBuilderfromsignalrcore_async.protocol.msgpackimportMessagePackHubProtocolasyncdefmain():protocol="ws"host="localhost"port="8080"hub="hub"hub_url=f"{protocol}://{host}:{port}/{hub}"connection=HubConnectionBuilder()\ .with_url(hub_url)\ # optional: use MessagePack instead of json protocol.with_hub_protocol(MessagePackHubProtocol())\ .build()try:# start connectionawaitconnection.start()# send (fire and forget)connection.send("SendName","R2D2")# invoke (wait for return value)sum_value=awaitconnection.invoke("Sum",[1,2])print(sum_value)# register callbackconnection.on("OnProgressChanged",_on_progress_changed)# streamawaitconnection.stream("StreamData",[1,2],_on_next)finally:# close connectionawaitconnection.stop()def_on_next(data):pass# do something with the streamed datadef_on_progress_changed(self,args):progress=args[0]print(f"Progress: {progress*100:.0f}%")# run main taskasyncio.run(main())
- 项目
标签: