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

call service not using py.test. rpc process can't get response. #286

Closed
jiamo opened this issue Oct 14, 2015 · 3 comments
Closed

call service not using py.test. rpc process can't get response. #286

jiamo opened this issue Oct 14, 2015 · 3 comments

Comments

@jiamo
Copy link

jiamo commented Oct 14, 2015

I write a test_server and test_client to simple use nameko:
here is my repo : https://github.com/jiamo/nameko_research

python test_service_server.py

The test_service_client.py get some codes from cli module.

python test_service_client.py

can't get response.

So is there some misunderstandings in my repo.

@mattbennett
Copy link
Member

Your server script starts and then immediately stops the service https://github.com/jiamo/nameko_research/blob/master/test_service_server.py#L32

You don't need to create a ServiceRunner yourself. You can use the nameko command line to run your service:

$ nameko run test_service_server --config nameko_server.conf
('config is ', {'AMQP_URI_CONFIG_KEY': 'amqp://guest:guest@localhost', 'max_workers': 10, 'AMQP_URI': 'amqp://guest:guest@localhost', 'parent_calls_tracked': 10, 'rpc_exchange': 'nameko-rpc'})
starting services: helloworld
Connected to amqp://guest:**@127.0.0.1:5672//

Also there is no need to implement the service client as you have. Just use the nameko command line:

nameko shell --config nameko_server.conf
>>> n.rpc.helloworld.hello(name='John')
u'Hello, John!'

@jiamo
Copy link
Author

jiamo commented Oct 14, 2015

Thanks. Some times we need run without nameko command.
After using nameko run test_service_server --config nameko_server.conf
my client py can work now.
But after comment the runner.stop(), python test_service_server.py still can' t work.

@mattbennett
Copy link
Member

You need to both apply the eventlet monkey patch and call wait() on the runner to block until it exits.

index e764db8..8597563 100644
--- a/test_service_server.py
+++ b/test_service_server.py
@@ -1,3 +1,6 @@
+import eventlet
+eventlet.monkey_patch()
+
 from nameko.rpc import rpc
 from nameko.runners import ServiceRunner
 from nameko.testing.utils import get_container
@@ -29,7 +32,7 @@ def main():
     # start both services
     runner.start()

-    runner.stop()
+    runner.wait()
     # container = ServiceContainer(HelloWorldService, config=config)
     # service_extensions = list(container.extensions)
     # print ("service_extensions is ", service_extensions)

You should really consider using the code from nameko.cli.run even if you don't use the command line script, because the signal handing is non-trivial. For example, see https://github.com/onefinestay/nameko/blob/master/nameko/cli/run.py#L134

I'm going to close this issue now. If you have more questions about how to use nameko please post them to the (new!) google group.

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