Skip to content

Instantly share code, notes, and snippets.

@parachvte
Created March 15, 2017 02:37
Show Gist options
  • Select an option

  • Save parachvte/ef898d155b824d29e7d710dc01da2bff to your computer and use it in GitHub Desktop.

Select an option

Save parachvte/ef898d155b824d29e7d710dc01da2bff to your computer and use it in GitHub Desktop.
Nameko Demo
# -*- coding: UTF-8 -*-
import logging
from nameko.constants import AMQP_URI_CONFIG_KEY
from nameko.standalone.rpc import ServiceRpcProxy
from tornado.options import parse_command_line
def main():
config = {
'AMQP_URI': 'amqp://192.168.0.13:5672',
}
with ServiceRpcProxy('test', config) as service:
for i in range(100):
logging.info('%s %s', i, service.work.call_async(pid=i))
if __name__ == '__main__':
parse_command_line() # only for pretty logging
main()
[I 170315 10:37:32 runners:83] starting services: test
[I 170315 10:37:33 mixins:231] Connected to amqp://guest:**@192.168.0.13:5672//
[I 170315 10:37:33 main:20] hello
[I 170315 10:37:34 main:20] hello
[I 170315 10:37:35 main:20] hello
[I 170315 10:37:36 main:20] hello
[I 170315 10:37:37 main:20] hello
[I 170315 10:37:38 main:20] hello
[I 170315 10:37:39 main:20] hello
...
# -*- coding: UTF-8 -*-
import eventlet
# Call monkey_patch() before any other imports
eventlet.monkey_patch()
import logging
from nameko.rpc import rpc
from nameko.cli.run import run
from tornado.options import parse_command_line
class Consumer(object):
name = 'test'
@rpc
def work(self, *args, **kwargs):
logging.info('hello')
return 42
def main():
config = {
'AMQP_URI': 'amqp://192.168.0.13:5672',
'max_workers': 1,
}
run([Consumer], config)
if __name__ == '__main__':
parse_command_line() # only for pretty logging
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment