Python RPC呼び出しのメソッドは?
Pythonでよく使われているRPCの呼び出し方法を以下に示します。
- XML-RPC クライアント
import xmlrpc.client
server = xmlrpc.client.ServerProxy('http://localhost:8000')
result = server.method_name(arg1, arg2)
- パ JasonRPC
from pyjsonrpc import HttpClient
client = HttpClient(url='http://localhost:8000')
result = client.call('method_name', arg1, arg2)
- パイレート
import Pyro4
uri = "PYRO:obj_123456@localhost:8000"
remote_obj = Pyro4.Proxy(uri)
result = remote_obj.method_name(arg1, arg2)
- gRPC ネイティブ
import grpc
import service_pb2
import service_pb2_grpc
channel = grpc.insecure_channel('localhost:50051')
stub = service_pb2_grpc.ServiceStub(channel)
response = stub.MethodName(service_pb2.RequestType(arg1=arg1, arg2=arg2))
result = response.result
これらの手法は、具体的なRPCフレームワークとニーズに合わせて選択・活用できます。