基于ZeroMQ的高性能分布式RPC框架:Zerorpc

jopen 10年前發布 | 37K 次閱讀 Zerorpc 消息系統

Zerorpc是一個基于ZeroMQ和MessagePack開發的遠程過程調用協議(RPC)實現。和 Zerorpc 一起使用的 Service API 被稱為 zeroservice。Zerorpc 可以通過編程或命令行方式調用。

它允許你:

  • 不用修改代碼即可顯露python模塊
  • 通過命令行遠程調用這些模塊

如何把你代碼中的對象暴露為一個zeroservice?

class Cooler(object):
    """ Various convenience methods to make things cooler. """

    def add_man(self, sentence):
        """ End a sentence with ", man!" to make it sound cooler, and
        return the result. """
        return sentence + ", man!"

    def add_42(self, n):
        """ Add 42 to an integer argument to make it cooler, and return the
        result. """
        return n + 42

    def boat(self, sentence):
        """ Replace a sentence with "I'm on a boat!", and return that,
        because it's cooler. """
        return "I'm on a boat!"

import zerorpc

s = zerorpc.Server(Cooler())
s.bind("tcp://0.0.0.0:4242")
s.run()

運行以上代碼,在另一個終端,嘗試連接這個zeroservice

$ zerorpc -j tcp://localhost:4242 add_42 1
43
$ zerorpc tcp://localhost:4242 add_man 'I own a mint-condition Volkswagen Golf'
"I own a mint-condition Volkswagen Golf, man!"
$ zerorpc tcp://localhost:4242 boat 'I own a mint-condition Volkswagen Golf, man!'
"I'm on a boat!"

github主頁:https://github.com/dotcloud/zerorpc-python

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!