Skip to content

Commit

Permalink
Merge 8d2c493 into 581eb50
Browse files Browse the repository at this point in the history
  • Loading branch information
little-cui committed Mar 6, 2018
2 parents 581eb50 + 8d2c493 commit 8cab874
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 4 deletions.
6 changes: 4 additions & 2 deletions docs/README.md
@@ -1,9 +1,11 @@
## Documentation Index

#### [Api Documentation](https://rawcdn.githack.com/ServiceComb/service-center/master/docs/api-docs.html)

#### [Design](/docs/design.md)

#### [Development Guide](/docs/dev-guide.md)

- [Api Documentation](https://rawcdn.githack.com/ServiceComb/service-center/master/docs/api-docs.html)

#### [Contribution Guide](/docs/contribution.md)

#### [Docker Image Guide](/docs/create-docker-image.md)
Expand Down
96 changes: 96 additions & 0 deletions docs/dev-guide.md
@@ -0,0 +1,96 @@
# Development Guide

This chapter is about how to implement the feature of micro-service discovery with ServiceCenter,
and you can get more detail at [here](/server/core/swagger/v3.yaml)

## Micro-service registration
```bash
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": "DemoService",
"version":"1.0.0"
}
}'
```

and then you can get the 'DemoService' ID like below:

```json
{
"serviceId": "a3fae679211211e8a831286ed488fc1b"
}
```

## Instance registration

mark down the micro-service ID and call the instance registration API:

```bash
curl -X POST \
http://127.0.0.1:30100/registry/v3/microservices/a3fae679211211e8a831286ed488fc1b/instances \
-H 'content-type: application/json' \
-H 'x-domain-name: default' \
-d '{
"instance":
{
"hostName":"demo-pc",
"endpoints": [
"rest://127.0.0.1:8080"
]
}
}'
```

the successful response like below:

```json
{
"instanceId": "288ad703211311e8a831286ed488fc1b"
}
```

if all are successful, it means you have completed the micro-service registration and instance publish

## Discovery

the next step is that discovery the micro-service instance by service name and version rule

```bash
curl -X GET \
'http://127.0.0.1:30100/registry/v3/instances?appId=default&serviceName=DemoService&version=latest' \
-H 'content-type: application/json' \
-H 'x-consumerid: a3fae679211211e8a831286ed488fc1b' \
-H 'x-domain-name: default'
```

here, you can get the information from the response

```json
{
"instances": [
{
"instanceId": "b4c9e57f211311e8a831286ed488fc1b",
"serviceId": "a3fae679211211e8a831286ed488fc1b",
"version": "1.0.0",
"hostName": "demo-pc",
"endpoints": [
"rest://127.0.0.1:8080"
],
"status": "UP",
"healthCheck": {
"mode": "push",
"interval": 30,
"times": 3
},
"timestamp": "1520322915",
"modTimestamp": "1520322915"
}
]
}
```
4 changes: 2 additions & 2 deletions server/infra/registry/registry.go
Expand Up @@ -201,11 +201,11 @@ func (op PluginOp) FormatUrlParams() string {
var buf bytes.Buffer
buf.WriteString("action=")
buf.WriteString(op.Action.String())
buf.WriteString("&mode=true")
buf.WriteString("&mode=")
buf.WriteString(op.Mode.String())
buf.WriteString("&key=")
buf.Write(op.Key)
buf.WriteString(fmt.Sprintf("&value=%d", len(op.Value)))
buf.WriteString(fmt.Sprintf("&len=%d", len(op.Value)))
if len(op.EndKey) > 0 {
buf.WriteString("&end=")
buf.Write(op.EndKey)
Expand Down

0 comments on commit 8cab874

Please sign in to comment.