2

I am using nameko to build an ETL pipeline with a micro-service architecture, and I do not want to wait for a reply after making a RPC request.

from nameko.rpc import rpc, RpcProxy

class Scheduler(object):
  name = "scheduler"

  task_runner = RpcProxy('task_runner')

  @rpc
  def schedule(self, task_type, group_id, time):
     return self.task_runner.start.async(task_type, group_id)

This code throws an error:

Traceback (most recent call last):
  File "/home/satnam-sandhu/.anaconda3/envs/etl/bin/nameko", line 8, in <module>
    sys.exit(main())
  File "/home/satnam-sandhu/.anaconda3/envs/etl/lib/python3.8/site-packages/nameko/cli/main.py", line 112, in main
    args.main(args)
  File "/home/satnam-sandhu/.anaconda3/envs/etl/lib/python3.8/site-packages/nameko/cli/commands.py", line 110, in main
    main(args)
  File "/home/satnam-sandhu/.anaconda3/envs/etl/lib/python3.8/site-packages/nameko/cli/run.py", line 181, in main
    import_service(path)
  File "/home/satnam-sandhu/.anaconda3/envs/etl/lib/python3.8/site-packages/nameko/cli/run.py", line 46, in import_service
    __import__(module_name)
  File "./scheduler/service.py", line 15
    return self.task_runner.start.async(task_type, group_id)
                                  ^
SyntaxError: invalid syntax

I am new with microservices and Nameko, and also I am using RabbitMQ as the queuing service.

Satnam Sandhu
  • 610
  • 1
  • 10
  • 25

2 Answers2

2

I had the same problem; you need to replace the async method with the call_async one, and retrieve the data with result().

Documentation
GitHub issue

Das_Geek
  • 2,775
  • 7
  • 20
  • 26
Paulo
  • 36
  • 1
  • 1
    Hey @Paulo your answer was correct, but I feel if you update the answer a little bit explaining the reason why it got changed then answer would feel a bit more complete and I would accept the answer. – Satnam Sandhu Dec 31 '19 at 09:08
1

use call_async instead async or for better result use event

from nameko.events import EventDispatcher, event_handler

@event_handler("service_a", "event_emit_name")
    def get_result(self, payload):
      #do_something...

and in other service

from nameko.events import EventDispatcher, event_handler
@event_handler("service_a", "event_emit_name")
    def return_result(self, payload):
       #get payload and work over there
Vijay
  • 141
  • 7