Skip to content

Commit

Permalink
docs: translate multiple service guide (#870)
Browse files Browse the repository at this point in the history
Co-authored-by: YangruiEmma <[email protected]>
  • Loading branch information
GuangmingLuo and YangruiEmma authored Dec 1, 2023
1 parent 38f4965 commit 228621b
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@ keywords: ["Kitex", "Multi Services", "gRPC"]
description: Kitex supports multiple service registration on a server.
---

## Multiple Services
Kitex supports multiple service registration on a server.

Currently, the feature is only available for **gRPC** transport protocol.
Note: currently, the feature is only available for **gRPC** transport protocol.

## Usage

### gRPC
For instance, suppose you have two proto files, each containing one service.
### gRPC service definition
For instance, suppose you have two proto files as follows, each containing one service.
By running the kitex command, you can automatically generate the code.

```protobuf
Expand Down Expand Up @@ -58,7 +55,7 @@ message ReplyB {
}
```

#### Register multi-service on a server
### Register multi-service on a server

Registering services on a server is a straightforward process.

Expand All @@ -71,7 +68,6 @@ package main

import (
"github.com/cloudwego/kitex/pkg/server"
"github.com/cloudwego/kitex/pkg/serviceinfo"

servicea "your_servicea_kitex_gen_path"
serviceb "your_serviceb_kitex_gen_path"
Expand Down
89 changes: 89 additions & 0 deletions content/zh/docs/kitex/Tutorials/advanced-feature/multi_service.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
---
title: "单 Server 多 Service"
date: 2023-11-30
weight: 10
keywords: ["Kitex", "多 Service", "单端口多Service", "gRPC"]
description: Kitex 支持在一个 Server 上注册多个 Service。
---

注:当前这个功能仅支持 **gRPC** 传输协议。

## 使用

### gRPC service 定义

例如,假设您有两个 proto 文件(如下所示),每个包含一个 service。
通过执行 kitex 命令,可以自动生成对应的代码。

```protobuf
// File1:servicea.proto
syntax = "proto3";
option go_package = "myservice";
package myservice;
service ServiceA {
rpc EchoA (stream RequestA) returns (stream ReplyA) {}
}
message RequestA {
...
}
message ReplyA {
...
}
// File2:serviceb.proto
syntax = "proto3";
option go_package = "myservice";
package myservice;
service ServiceB {
rpc EchoB (stream RequestB) returns (stream ReplyB) {}
}
message RequestB {
...
}
message ReplyB {
...
}
```

### 如何在一个 Server 上注册多个 Service

在一个 server 上注册多个 service 是一个简单的过程。

首先,创建一个 server。然后,通过调用该 server 上的 `RegisterService` 函数,就可以注册 service 了。

```golang
package main

import (
"github.com/cloudwego/kitex/pkg/server"

servicea "your_servicea_kitex_gen_path"
serviceb "your_serviceb_kitex_gen_path"
)

func main() {
// create a server by calling server.NewServer
svr := server.NewServer(your_server_option)
// register multi-service on a server
err := svr.RegisterService(servicea.NewServiceInfo(), new(ServiceAImpl))
err := svr.RegisterService(serviceb.NewServiceInfo(), new(ServiceBImpl))

err := svr.Run()

if err != nil {
logs.Error("%s", err.Error())
}
logs.Stop()
}
```

1 comment on commit 228621b

@vercel
Copy link

@vercel vercel bot commented on 228621b Dec 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.