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 toString()是否在toString中包含类名?   java多路复用程序   java Google map群集不适用于少量Cordinate   java如何在Android中设置和自定义不同的字体样式   Java版本比较   Spring引导升级后的java“未找到提供程序com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule”   java如何重新定位小程序查看器窗口?   java在适配器处于同一活动时在回收器视图中添加搜索视图   在Java中使用COM程序集   java在ListView中选择了什么操作?   java Hangman屏蔽字符串,取消隐藏字符   java为什么检查多个条件会返回不正确的结果   spring由:java引起。lang.ClassCastException:$ProxyX不能强制转换为my。包裹DefaultCustomerProviderImpl   java想要一些建议来清理一系列if语句   Java使用多个参数对对象进行排序