Service registry
This page serves as a documentation on what the service registry does and how it works.
Design
Purpose
- Provide authentication keys for microservices (as opposed to user-based authentication keys)
- This allows microservices to communicate between each other without the approval of a user (action). This is useful (needed) for things such as cron tasks.
- Categorize microservices together
- Provides ways to register and query as such a category
- This allows things such as front-ends to know which services are available and only show those in the user interface. TODO discuss this
- In the case of the application microservice, this allows for several microservice of the category "application" to be grouped together and used interchangeably for the same thing within oms-events
- In the case of the notification pipeline, we will also have several microservices of the category "notification" which either send notifications via mail or push or smoke signals or whatever
- Provides ways to register and query as such a category
- Query for frontend modules/pages
- Each microservice can register modules/pages/whatever-we-call-them to be displayed additionally in the menu bar and also be loaded upon frontend load. The registry gathers these by a registered getModules.json (the path to this file is set with a label, see "Use"
- Currently it uses a hack to register these pages to the core
- In the future it might take over the modules functionality from the core, doing effectively the same thing TODO discuss this
Use
You can add different labels on a container that the registry will read and that can be queried through the api
Label | Default | Description |
---|---|---|
registry.port | traefik.port or 80 | The port which the service exposes as the main endpoint |
registry.frontend | traefik.frontend.rule parsed | The frontend url under which this service is reachable |
registry.enable | traefik.enable or false | Whether the service is reachable through the frontend |
registry.categories | [ ] | An array of strings and priorities which determines the categories this microservice belongs to Example: "registry.categories=(events, 10);(notifications, 10)" |
registry.description | "" | A description for this service |
servicename | The servicename is parsed directly from what is set as a servicename in docker-compose.yml and cannot be altered | |
registry.modules | "" | If this service wants to register frontend pages, this should be the relative path where it serves a getModules.json. Do not prepend http://<servicename>:<port> this will be added automatically from the above fields Example: /frontend/getModules.json → registry queries http://omsevents-frontend:8083/frontend/getModules.json How to use getModules.json is described here |
registry.status | "/status" | An endpoint that upon a GET request delivers whether the service is up and healthy or not. Connection refused is interpreted as a no. Extra information can be delivered, but the success field is indicating the actual status response {success: 1, data: <extra information>} |
Code
API
Questions
I (Derk Snijders) read Micro service - communication, went through the code and looked at the API, yet still had some questions. Answering these should provide solid documentation as to how to use the registry.
- Why seperate authentication for microservices and users?
- I would propose splitting Users and Members. This way you can have Members being a User, but also services being a User and do all authentication for Users the same.
- Answer Nico: I love that idea, this would solve it in a more elegant fashion!
- Doesn't docker already offer the ability to categorize services using labels?
- Still might need someway to query this, but...
- Answer Nico: Still needs some way to query it. Effectively the registry does query docker for it and then provides a nicer interface. But we could also rationalize it away and maybe provide a code snippet which queries docker and parses the response but somehow having a small service for it feels nicer.
- Still might need someway to query this, but...
- Doesn't traefik already gives you the ability to query services using categories?
- Isn't this feature taken directly from the traefik website what we need? '* Round Robin, rebalancer load-balancers'
- Answer Nico: The loadbalancing only happens for instances of the same service, traefik has no notion of category in our sense where different services provide somewhat same functionalities.
- What are categories?
- Are multiple instances of the same service (image) a category? Or are multiple services that do approximately the same, but not exactly, a category?
- I believe Traefik (or even docker?) can handle the first case, I do not see the use case / priority of the second case.
- Answer Nico: The second case, for examples see Purpose -> 2.a.ii. and 2.a.iii. above
- I believe Traefik (or even docker?) can handle the first case, I do not see the use case / priority of the second case.
- Are multiple instances of the same service (image) a category? Or are multiple services that do approximately the same, but not exactly, a category?
- Isn't it solely up to the frontend to decide which pages to show? (since we dropped the concept of modules)
- Meaning integration with the service registry for backend-only services would solely be for authentication?
- Answer Nico: We should rediscuss this, I had some insights when splitting off the frontend.