异步的Cometd客户端
aiocometd的Python项目详细描述
aiocometd
aiocometd是一个CometD客户端,使用asyncio构建,实现Bayeux 协议。
CometD是一个可伸缩的websocket和基于http的事件和消息路由总线。 CometD利用WebSocket和HTTP推送技术Comet来 从服务器向浏览器和客户端应用程序提供低延迟数据。
功能
- 支持的传输:
- long-polling
- websocket
- 网络故障后自动重新连接
- 扩展名
使用量
importasynciofromaiocometdimportClientasyncdefchat():nickname="John"# connect to the serverasyncwithClient("http://example.com/cometd")asclient:# subscribe to channels to receive chat messages and# notifications about new membersawaitclient.subscribe("/chat/demo")awaitclient.subscribe("/members/demo")# send initial messageawaitclient.publish("/chat/demo",{"user":nickname,"membership":"join","chat":nickname+" has joined"})# add the user to the chat room's membersawaitclient.publish("/service/members",{"user":nickname,"room":"/chat/demo"})# listen for incoming messagesasyncformessageinclient:ifmessage["channel"]=="/chat/demo":data=message["data"]print(f"{data['user']}: {data['chat']}")if__name__=="__main__":loop=asyncio.get_event_loop()loop.run_until_complete(chat())
有关更详细的用法示例,请查看 command line chat example或者更复杂的例子 一个GUI查看aiocometd-chat-demo
变更日志
0.4.5(2019-03-14)
- 修复与基于cookie的反向代理服务器一起使用时的连接问题 粘性会话
0.4.4(2019-02-26)
- 重构WebSocket传输实现以使用单个连接 每位客户
0.4.3(2019-02-12)
- 修复Salesforce流式API上的重新连接问题
0.4.2(2019-01-15)
- 修复对无效websocket传输响应的处理
- 修复对失败订阅响应的处理
0.4.1(2019-01-04)
- 添加文档链接
0.4.0(2019-01-04)
- 添加类型提示
- 添加集成测试
0.3.1(2018-06-15)
- 修复过早的请求超时问题
0.3.0(2018-05-04)
- 启用第三方json库的使用
- 修复网络故障的检测和恢复
0.2.3(2018-04-24)
- 修复RST渲染问题
0.2.2(2018-04-24)
- 修复文档错误
- 改进示例
- 重组文档
0.2.1(2018-04-21)
- 将pypi徽章添加到自述文件
0.2.0(2018-04-21)
- 支持的传输:
- long-polling
- websocket
- 网络故障后自动重新连接
- 扩展名