pyzmq服务器/客户端基于min-rk启动代码实现异步自由协议

zmqflp的Python项目详细描述


ZMQFLP

对基于自由职业者协议的ZeroMQ服务器/客户端(Python)的改进 客户机和服务器使用cbor2进行对话,因此api接受字典作为输入。

创建zmqflp服务器:

# create the server object (it runs in an asyncio zmq context)self.server=zmqflp_server.ZMQFLPServer(self.config.identity,self.config.zmq_port)# use the following code to process messages received by the server and send them backasyncdefprocess_messages(self):(serialized_request,orig_headers)=awaitself.server.receive()ifserialized_request=='EXIT':awaitself.server.send(orig_headers,'exiting')returnFalseelifserialized_request!="PING":try:request=serialized_requestresponse=self.process_request(request)awaitself.server.send(orig_headers,response)returnTrueexceptExceptionase:logging.exception(e)returnFalsereturnTrue

不使用上下文管理器创建客户端:

# create the client object (this does NOT run in an asyncio context)self.client=zmqflp_client.ZMQFLPClient(self.config.list_of_servers)# to send and receive with the clientmsg_to_send={'message':'hello!','other-key':'stuff goes here'}status=self.client.send_and_receive(msg_to_send)

使用上下文管理器创建客户机(例如,在aws lambda上运行):

# create the client object (this does NOT run in an asyncio context)withzmqflp_client.ZMQFLPClient(self.config.list_of_servers)asclient:# to send and receive with the clientmsg_to_send={'message':'hello!','other-key':'stuff goes here'}status=client.send_and_receive(msg_to_send)

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java需要设置框架。可设置大小(false)以重新绘制()   java我对PDF文件感到困惑   为什么是太阳。jvm。热点。调试器。DebuggerException:无法打开二进制文件`?   设置结果为textview时出现java空指针异常   我应该使用什么同步原语在Java中实现事件驱动程序框架?   java为什么WindowClosing处理程序在退出程序之前不执行后台任务?   如何将“20170712T18:43:04.000Z”转换为安卓或java中的相对时间?   Java,获取按键的时间长度,currentTimeMillies()始终为24   maven构建的java可执行Jar找不到logback。xml   java在其外部的函数中使用for循环中的值   java如何以表格格式将不同长度的数据对齐   java Play 2.5 WebSocket连接构建   maven而非eclipse的java强制转换问题   java如何在JFreeChart中使X轴上的值水平?   构建Java Windows应用程序以访问在线MySQL数据库需要什么   java添加构造函数会出错吗?这没有道理,请帮忙,编程问题   java在一个jframe中的两个JPanel中使用两个绘制方法   java数学或逻辑问题   java如何复制Androids库存摄像头方向更改