クイックスタート¶
Python で書いた CORBA のサーバとクライアントを動かします。必要なのは Python 3.9 以降か Docker だけです。そのあとチュートリアルで、同じことをすべての言語で、ネーミングサービスを使って行います。
1. rustorb の入ったシェルを用意する¶
rustorb が ORB 本体(Rust のコアをビルド済みの wheel。Linux、macOS、Windows 用)、rustorb-idl が IDL コンパイラです。
2. インタフェースを書く¶
次の内容を Echo.idl として保存します。
ここから Python のコードを生成します。
Echo_idl.py と、パッケージ Example(クライアント用スタブ)、Example__POA(サーバ用スケルトン)ができます。
3. サーバを書く¶
server.py はインタフェースを実装し、オブジェクトを活性化して、その参照(IOR)をファイルに書きます。
import sys
from rustorb import CORBA, PortableServer
import Example, Example__POA
class EchoImpl(Example__POA.Echo):
def echo(self, message):
print("server got:", message, flush=True)
return message
orb = CORBA.ORB_init(sys.argv)
poa = orb.resolve_initial_references("RootPOA")
poa._get_the_POAManager().activate()
ref = EchoImpl()._this()
with open("echo.ior", "w") as f:
f.write(orb.object_to_string(ref))
print("server ready, IOR in echo.ior", flush=True)
orb.run()
4. クライアントを書く¶
client.py は参照を読み込んで、オブジェクトを呼び出します。
import sys
from rustorb import CORBA
import Example
orb = CORBA.ORB_init(sys.argv)
ior = open("echo.ior").read()
echo = orb.string_to_object(ior)._narrow(Example.Echo)
print(echo.echo("hello, rustorb"))
orb.destroy()
5. 動かす¶
サーバは kill %1(または fg して Ctrl+C)で止めます。
2 つのプロセスは TCP 上の GIOP で通信しています。そのため、このサーバはどの CORBA クライアントからも呼べ、このクライアントはどの CORBA サーバでも呼べます。omniORB、omniORBpy、JacORB、別の言語の rustorb のどれでも構いません。