Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to bind multiple classes ? #265

Open
wangyan2048 opened this issue Sep 20, 2024 · 2 comments
Open

How to bind multiple classes ? #265

wangyan2048 opened this issue Sep 20, 2024 · 2 comments

Comments

@wangyan2048
Copy link

server:

class A:
@staticmethod
def test_a(n):
return n

class B:
@staticmethod
def test_b(n):
return n * 2

server = zerorpc.Server()
server.register(A(), 'a')
server.register(B(), 'b')

server.bind("tcp://127.0.0.1:80")
server.run()

client:
client = zerorpc.Client()
client.connect("tcp://127.0.0.1:80")
print(client.a.test_a(1))
print(client.b.test_b(2))

@bombela
Copy link
Member

bombela commented Sep 20, 2024

See the doc to expose one service: https://github.com/0rpc/zerorpc-python?tab=readme-ov-file#exposing-a-zeroservice-programmatically

Exposing multiple instances of classes can be done in two ways:

  • Merge the two classes
    • either by merging the code directly
    • or via inheritance
  • Expose two services (bind on two different ports)

@wangyan2048
Copy link
Author

thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants