Run nameko service with multiple names (Multiple queues)

Is there is a way to run single service class multiple times with different
names and get service name inside called class function.
* class MessageService:*
* @rpc*
* def message(self, message):*
* return self.name*
*class TestRunner:*
* MessageService.name="service_1"*
* self.runner.add_service(MessageService)*
* MessageService.name="service_2"*
* self.runner.add_service(MessageService)*
*.....*

Above code achieved running single service multiple times but I can't get
service name inside message function (both service queues return *service_1*

Best Regards,
Mahmoud Seif-eldin

You can do this with inheritance.

# msg.py

class MessageService:

    @rpc
    def message(self):
        return self.name

class MessageServiceA(MessageService):
    name = 'a'

class MessageServiceB(MessageService):
    name = 'b'

Note that to run the services you have to explicitly select just the
subclasses (i.e. "nameko run msg:MessageServiceA msg:MessageServiceB")
otherwise the runner will try to run the base class too and complain about
a missing name attribute.

···

On Thursday, October 19, 2017 at 3:05:59 PM UTC+1, msd8...@gmail.com wrote:

Is there is a way to run single service class multiple times with
different names and get service name inside called class function.
* class MessageService:*
* @rpc*
* def message(self, message):*
* return self.name <http://self.name>*
*class TestRunner:*
* MessageService.name="service_1"*
* self.runner.add_service(MessageService)*
* MessageService.name="service_2"*
* self.runner.add_service(MessageService)*
*.....*

Above code achieved running single service multiple times but I can't get
service name inside message function (both service queues return
*service_1*

Best Regards,
Mahmoud Seif-eldin

It is working perfectly, Thanks for your help :slight_smile:

···

On Thursday, 19 October 2017 16:05:59 UTC+2, msd8...@gmail.com wrote:

Is there is a way to run single service class multiple times with
different names and get service name inside called class function.
* class MessageService:*
* @rpc*
* def message(self, message):*
* return self.name <http://self.name>*
*class TestRunner:*
* MessageService.name="service_1"*
* self.runner.add_service(MessageService)*
* MessageService.name="service_2"*
* self.runner.add_service(MessageService)*
*.....*

Above code achieved running single service multiple times but I can't get
service name inside message function (both service queues return
*service_1*

Best Regards,
Mahmoud Seif-eldin