# Multiple instances of same service, different args/options?

**URL:** <https://discourse.nameko.io/t/multiple-instances-of-same-service-different-args-options/384>\
**Category:** Uncategorized\
**Created:** [December 20, 2018, 9:40pm UTC](https://discourse.nameko.io/t/multiple-instances-of-same-service-different-args-options/384 "2018-12-20T21:40:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![afischbein](https://avatars.discourse-cdn.com/v4/letter/a/e47774/32.png) [@afischbein](https://discourse.nameko.io/u/afischbein)\
**Post date:** [December 20, 2018, 9:40pm UTC](https://discourse.nameko.io/t/multiple-instances-of-same-service-different-args-options/384/1 "2018-12-20T21:40:37Z")

</div>

Hi,

I am trying to write a service that will subscribe to some external streaming data source, and publish that data in RabbitMQ. I already wrote an Entrypoint class that subscribes to the external data source and triggers an event for each incoming message, so all the service class does is publish this message to Rabbit.  
This all works fine.  
However, in the next phase, this will be a LOT of data, far too much for one instance of the service to handle. I was thinking of spinning up many instances of the service, and [somehow] indicate to each instance which subset of external data it should listen to and publish. (Identifying the subsets of data is easy, and can be identified by a simple string). I was thinking perhaps a command line param could be passed to the service when starting up, but I don’t know if/how that can be done.  
Do you have any suggestions? Thanks very much in advance.

---

<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:** [December 21, 2018, 10:09am UTC](https://discourse.nameko.io/t/multiple-instances-of-same-service-different-args-options/384/2 "2018-12-21T10:09:34Z")

</div>

It’s pretty simple to do exactly as you’ve described.

Your custom extension can read whatever is parsed from the [config file](https://nameko.readthedocs.io/en/stable/cli.html?highlight=config.yaml#running-a-service) through the `ServiceContainer`. In your extension, simply add:

```python
def setup(self): #probably want to do it in setup
    subset_identifier = self.container.config.get("SUBSET_IDENTIFIER")
    ...

```

You can put any arbitrary information you like into `config.yaml`

---

<div class="post-metadata">

**Author:** ![afischbein](https://avatars.discourse-cdn.com/v4/letter/a/e47774/32.png) [@afischbein](https://discourse.nameko.io/u/afischbein)\
**Post date:** [December 21, 2018, 1:16pm UTC](https://discourse.nameko.io/t/multiple-instances-of-same-service-different-args-options/384/3 "2018-12-21T13:16:24Z")

</div>

Hi Matt,  
Thanks for the quick response. I was considering this. I noticed in the docs that environment variables can be set and then the config file can reference those environment variables. Is there a particular reason the entrypoint couldn’t just read the environment variable directly at startup? We’ve been trying to avoid config files until now because it complicates deployment. (We compile the service project into a conda package that is deployed whole, so knowing the exact path to the config file to reference it on the command line at startup is not trivial…)  
Thanks again for your help, and for making an awesome product - looking forward to the new version!

- Alan

---

<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:** [December 21, 2018, 3:12pm UTC](https://discourse.nameko.io/t/multiple-instances-of-same-service-different-args-options/384/4 "2018-12-21T15:12:40Z")

</div>

You can read directly from `os.environ` if that’s easier for you.

Note the changes in [this PR](https://github.com/nameko/nameko/pull/520) too, which should land soon. This makes the parsed config available as a global variable. It also introduces the `--define` argument, which allows you to specify config values directly on the command line.

---

<div class="post-metadata">

**Author:** ![afischbein](https://avatars.discourse-cdn.com/v4/letter/a/e47774/32.png) [@afischbein](https://discourse.nameko.io/u/afischbein)\
**Post date:** [December 21, 2018, 3:13pm UTC](https://discourse.nameko.io/t/multiple-instances-of-same-service-different-args-options/384/5 "2018-12-21T15:13:45Z")

</div>

awesome, thanks Matt.

- Alan
