python远程通信库

kiwip的Python项目详细描述


kiwipy

Travis CILatest Versionhttps://img.shields.io/pypi/wheel/kiwipy.svghttps://img.shields.io/pypi/pyversions/kiwipy.svghttps://img.shields.io/pypi/l/kiwipy.svg

kiwipy是一个库,它使使用rabbitmq(以及为其编写后端的任何其他协议)进行远程消息传递变得容易。 我不知道你的情况,但我觉得拉比很难。 很容易犯一个配置错误,然后很难调试。 有了kiwipy,就没有这一切了,只是消息传递,变得简单,有了amqp的所有好的属性和保证。

您将得到以下信息:

  • rpc
  • 广播(带过滤器)
  • 任务队列消息

让我们深入讨论一下,举几个来自rmq tutorial的例子。

rpc

客户:

fromkiwipyimportrmqcommunicator=rmq.RmqThreadCommunicator.connect(connection_params={'url':'amqp://localhost'})# Send an RPC messageprint(" [x] Requesting fib(30)")response=communicator.rpc_send('fib',30).result()print((" [.] Got %r"%response))

(rmq_rpc_client.py source)

服务器:

importthreadingfromkiwipyimportrmqdeffib(comm,num):ifnum==0:return0ifnum==1:return1returnfib(comm,num-1)+fib(comm,num-2)communicator=rmq.RmqThreadCommunicator.connect(connection_params={'url':'amqp://localhost'})# Register an RPC subscriber with the name squarecommunicator.add_rpc_subscriber(fib,'fib')# Now wait indefinitely for fibonacci callsthreading.Event().wait()

(rmq_rpc_server.py source)

工人

创建新任务:

importsysfromkiwipyimportrmqmessage=' '.join(sys.argv[1:])or"Hello World!"withrmq.RmqThreadCommunicator.connect(connection_params={'url':'amqp://localhost'})ascommunicator:communicator.task_send(message)

(rmq_new_task.py source)

工人:

importtimeimportthreadingfromkiwipyimportrmqprint(' [*] Waiting for messages. To exit press CTRL+C')defcallback(_comm,task):print((" [x] Received %r"%task))time.sleep(task.count(b'.'))print(" [x] Done")try:withrmq.RmqThreadCommunicator.connect(connection_params={'url':'amqp://localhost'})ascommunicator:communicator.add_task_subscriber(callback)threading.Event().wait()exceptKeyboardInterrupt:pass

(rmq_worker.py source)

版本控制

这个软件遵循Semantic Versioning

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

推荐PyPI第三方库


热门话题
java如何通过解决错误“活动无法转换为片段”将片段传递给类构造函数?   Java中清理Code39条码数据的regex帮助   将java转换为C++   java无法在Android Studio中生成签名的apk,出现错误   从数学方程出发   MySQL和Java内存问题   如何强制Java抛出算术异常?   java为什么JDBC将零端口视为空(默认)端口?   java如何在没有“changelog主题”的情况下加入KStream和KTable   排序我尝试合并两个排序的数组,但得到的是java。lang.ArrayIndexOutofBounds异常:5无法找出原因   如何在java中求大长度矩阵的逆?   基于maven构建的java生成类路径字符串   java每20个字符分割一个字符串,然后将每个部分打印到控制台   将字符串数字字转换为字符串数字:Java   在特定区域使用混合类型的java填充字节数组   尽管java类在开关块中实例化,但它只能调用接口方法