{% include toc %}
In a microservices architecture, an application consists of a set of services with a single responsibility, and each service is dynamically deployed to a different node. How should we manage the dependencies between this set of services?
The service registry has solved this problem. It allows the service of provider to register its information to the service-center; the service of consumer can discover the provider information from the service-center. The service registry has several advantages:
The service registration and discovery process in Service-Center has the following steps:
The Service-Center registration and discovery interface is implemented based on the RESTful standard. It is not restricted by the development language. For the interface definition, please refer to API Document
This chapter is about how to implement the feature of micro-service discovery with ServiceCenter.
$ curl -X POST \ http://127.0.0.1:30100/registry/v3/microservices \ -H 'content-type: application/json' \ -H 'x-domain-name: default' \ -d '{ "service": { "appId": "default", "serviceName": "ProviderDemoService", "version":"1.0.0" } }'And then you can get the ‘ProviderDemoService’ ID like below:
{"serviceId":"fa82132706a6b75a13393d8cf48800f9689b2603"}
$ curl -X POST \ http://127.0.0.1:30100/registry/v3/microservices/fa82132706a6b75a13393d8cf48800f9689b2603/instances \ -H 'content-type: application/json' \ -H 'x-domain-name: default' \ -d '{ "instance": { "hostName":"provider-demo", "endpoints": [ "rest://127.0.0.1:8080" ] } }'The successful response like below:
{"instanceId":"6e160fb0196e11e9b8b50242ac110005"}
$ curl -X POST \ http://127.0.0.1:30100/registry/v3/microservices \ -H 'content-type: application/json' \ -H 'x-domain-name: default' \ -d '{ "service": { "appId": "default", "serviceName": "ConsumerDemoService", "version":"1.0.0" } }'if all are successful, it means you have completed the micro-service registration and instance publish
{"serviceId":"d08d29edbeaa372c5be88407aa9adb00b4cb6099"}
$ curl -X GET \ 'http://127.0.0.1:30100/registry/v3/instances?appId=default&serviceName=ProviderDemoService&version=latest' \ -H 'content-type: application/json' \ -H 'x-consumerid: d08d29edbeaa372c5be88407aa9adb00b4cb6099' \ -H 'x-domain-name: default' { "instances": [ { "instanceId": "c23da577197111e9b8b50242ac110005", "serviceId": "fa82132706a6b75a13393d8cf48800f9689b2603", "endpoints": [ "rest://127.0.0.1:8080" ], "hostName": "provider-demo", "status": "UP", "healthCheck": { "mode": "push", "interval": 30, "times": 3 }, "timestamp": "1547631199", "modTimestamp": "1547631199", "version": "1.0.0" } ] }