# Shared RPC-mixins

**URL:** <https://discourse.nameko.io/t/shared-rpc-mixins/175>\
**Category:** googlegroup\
**Created:** [March 17, 2017, 1:04pm UTC](https://discourse.nameko.io/t/shared-rpc-mixins/175 "2017-03-17T13:04:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Trikster1911](https://avatars.discourse-cdn.com/v4/letter/t/65b543/32.png) [@Trikster1911](https://discourse.nameko.io/u/Trikster1911)\
**Post date:** [March 17, 2017, 1:04pm UTC](https://discourse.nameko.io/t/shared-rpc-mixins/175/1 "2017-03-17T13:04:36Z")

</div>

Hello there! We're a bunch of microservices on top of nameko and are  
interested in sharing the code-base across multiple instances. Currently we  
have our own library to share the code but we've faced the difficulty in  
creating the base class for all of our microservices. Let me explain, each  
of our services has a well-defined interface (HTTP and RPC endpoints for  
the documentation, health-checks, etc) and we're looking forward to for the  
way to create some kind of the Abstract Base Class for all of our services,  
which defines that interface. So what is the proper way to deal with it in  
nameko if any? Thank you

class BaseService(object):  
&nbsp;&nbsp;&nbsp;@rpc  
&nbsp;&nbsp;&nbsp;def check\_health(self, ...):  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;...

&nbsp;&nbsp;&nbsp;@http('GET', '/api/health')  
&nbsp;&nbsp;&nbsp;def status(self, request):  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;....

class MyService(BaseService):  
&nbsp;&nbsp;&nbsp;&nbsp;# This does not work

---

<div class="post-metadata">

**Author:** ![David\_Szotten](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.nameko.io/david_szotten/32/6_2.png) [@David\_Szotten](https://discourse.nameko.io/u/David_Szotten)\
**Post date:** [March 17, 2017, 5:34pm UTC](https://discourse.nameko.io/t/shared-rpc-mixins/175/2 "2017-03-17T17:34:04Z")

</div>

Hi,

I would expect the above example to work. What happens? Do you have a more  
complete example?

Best,  
David

> **···**
>
> On Friday, 17 March 2017 13:04:36 UTC, trikst...@gmail.com wrote:
> 
> > Hello there! We're a bunch of microservices on top of nameko and are  
> > interested in sharing the code-base across multiple instances. Currently we  
> > have our own library to share the code but we've faced the difficulty in  
> > creating the base class for all of our microservices. Let me explain, each  
> > of our services has a well-defined interface (HTTP and RPC endpoints for  
> > the documentation, health-checks, etc) and we're looking forward to for the  
> > way to create some kind of the Abstract Base Class for all of our services,  
> > which defines that interface. So what is the proper way to deal with it in  
> > nameko if any? Thank you
> > 
> > class BaseService(object):  
> > &nbsp;&nbsp;&nbsp;@rpc  
> > &nbsp;&nbsp;&nbsp;def check\_health(self, ...):  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;...
> > 
> > &nbsp;&nbsp;&nbsp;@http('GET', '/api/health')  
> > &nbsp;&nbsp;&nbsp;def status(self, request):  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;....
> > 
> > class MyService(BaseService):  
> > &nbsp;&nbsp;&nbsp;&nbsp;# This does not work

---

<div class="post-metadata">

**Author:** ![mattbennett](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.nameko.io/mattbennett/32/13_2.png) [@mattbennett](https://discourse.nameko.io/u/mattbennett)\
**Post date:** [March 18, 2017, 11:14am UTC](https://discourse.nameko.io/t/shared-rpc-mixins/175/3 "2017-03-18T11:14:51Z")

</div>

We use this base-class pattern st Student.com. I would also expect your  
example to work, except that you haven't specified a name attribute on the  
`MyService` class.

One note regarding names -- if you put a name attribute on the base class,  
`nameko run` will discover both the base and the subclass and attempt to  
run both unless you explicitly specify the service class (i.e. `nameko run  
module:MyService`)

> **···**
>
> On Friday, March 17, 2017 at 5:34:04 PM UTC, David Szotten wrote:
> 
> > Hi,
> > 
> > I would expect the above example to work. What happens? Do you have a more  
> > complete example?
> > 
> > Best,  
> > David
> > 
> > On Friday, 17 March 2017 13:04:36 UTC, trikst...@gmail.com wrote:
> > 
> > > Hello there! We're a bunch of microservices on top of nameko and are  
> > > interested in sharing the code-base across multiple instances. Currently we  
> > > have our own library to share the code but we've faced the difficulty in  
> > > creating the base class for all of our microservices. Let me explain, each  
> > > of our services has a well-defined interface (HTTP and RPC endpoints for  
> > > the documentation, health-checks, etc) and we're looking forward to for the  
> > > way to create some kind of the Abstract Base Class for all of our services,  
> > > which defines that interface. So what is the proper way to deal with it in  
> > > nameko if any? Thank you
> > > 
> > > class BaseService(object):  
> > > &nbsp;&nbsp;&nbsp;@rpc  
> > > &nbsp;&nbsp;&nbsp;def check\_health(self, ...):  
> > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;...
> > > 
> > > &nbsp;&nbsp;&nbsp;@http('GET', '/api/health')  
> > > &nbsp;&nbsp;&nbsp;def status(self, request):  
> > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;....
> > > 
> > > class MyService(BaseService):  
> > > &nbsp;&nbsp;&nbsp;&nbsp;# This does not work

---

<div class="post-metadata">

**Author:** ![Trikster1911](https://avatars.discourse-cdn.com/v4/letter/t/65b543/32.png) [@Trikster1911](https://discourse.nameko.io/u/Trikster1911)\
**Post date:** [March 20, 2017, 9:45am UTC](https://discourse.nameko.io/t/shared-rpc-mixins/175/4 "2017-03-20T09:45:54Z")

</div>

Thank you, specifying the name for the base class solved all the problems.

> **···**
>
> суббота, 18 марта 2017 г., 14:14:51 UTC+3 пользователь Matt Yule-Bennett написал:
> 
> > We use this base-class pattern st Student.com. I would also expect your  
> > example to work, except that you haven't specified a name attribute on the  
> > `MyService` class.
> > 
> > One note regarding names -- if you put a name attribute on the base class,  
> > `nameko run` will discover both the base and the subclass and attempt to  
> > run both unless you explicitly specify the service class (i.e. `nameko run  
> > module:MyService`)
> > 
> > On Friday, March 17, 2017 at 5:34:04 PM UTC, David Szotten wrote:
> > 
> > > Hi,
> > > 
> > > I would expect the above example to work. What happens? Do you have a  
> > > more complete example?
> > > 
> > > Best,  
> > > David
> > > 
> > > On Friday, 17 March 2017 13:04:36 UTC, trikst...@gmail.com wrote:
> > > 
> > > > Hello there! We're a bunch of microservices on top of nameko and are  
> > > > interested in sharing the code-base across multiple instances. Currently we  
> > > > have our own library to share the code but we've faced the difficulty in  
> > > > creating the base class for all of our microservices. Let me explain, each  
> > > > of our services has a well-defined interface (HTTP and RPC endpoints for  
> > > > the documentation, health-checks, etc) and we're looking forward to for the  
> > > > way to create some kind of the Abstract Base Class for all of our services,  
> > > > which defines that interface. So what is the proper way to deal with it in  
> > > > nameko if any? Thank you
> > > > 
> > > > class BaseService(object):  
> > > > &nbsp;&nbsp;&nbsp;@rpc  
> > > > &nbsp;&nbsp;&nbsp;def check\_health(self, ...):  
> > > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;...
> > > > 
> > > > &nbsp;&nbsp;&nbsp;@http('GET', '/api/health')  
> > > > &nbsp;&nbsp;&nbsp;def status(self, request):  
> > > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;....
> > > > 
> > > > class MyService(BaseService):  
> > > > &nbsp;&nbsp;&nbsp;&nbsp;# This does not work
