-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
187 additions
and
32 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
cmd/layotto_multiple_api/advanced_queue/advanced_queue.proto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
syntax = "proto3"; | ||
|
||
option go_package = "github.com/mosn/layotto/cmd/layotto_multiple_api/advanced_queue;advanced_queue"; | ||
|
||
package cmd.layotto_multiple_api.advanced_queue; | ||
|
||
/* @exclude skip sdk_generator */ | ||
/* @exclude extends pub_subs */ | ||
// AdvancedQueue is advanced pubsub API | ||
service AdvancedQueue { | ||
|
||
// Publish a transactional message | ||
rpc PublishTransactionalMessage(TransactionalMessageRequest) returns (TransactionalMessageResponse); | ||
|
||
} | ||
|
||
// TransactionalMessageRequest | ||
message TransactionalMessageRequest { | ||
// Required | ||
string store_name = 1; | ||
// Required | ||
string content = 2; | ||
} | ||
|
||
// TransactionalMessageResponse | ||
message TransactionalMessageResponse { | ||
|
||
// message_id is identifier of a message | ||
string message_id = 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Generate API plugin automatically | ||
|
||
Writing the API plugin yourself is boring. You can use code generator to generate all the code. | ||
|
||
Let's say you want to add a `PublishTransactionalMessage` method to existing pubsub API. You write a new proto file `cmd/layotto_multiple_api/advanced_queue/advanced_queue.proto` : | ||
|
||
```protobuf | ||
// ...... | ||
/* @exclude extends pub_subs */ | ||
// AdvancedQueue is advanced pubsub API | ||
service AdvancedQueue { | ||
rpc PublishTransactionalMessage(TransactionalMessageRequest) returns (TransactionalMessageResponse); | ||
} | ||
message TransactionalMessageRequest { | ||
string store_name = 1; | ||
string content = 2; | ||
} | ||
message TransactionalMessageResponse { | ||
string message_id = 1; | ||
} | ||
``` | ||
|
||
and run the generator: | ||
|
||
```protobuf | ||
protoc -I . \ | ||
--go_out . --go_opt=paths=source_relative \ | ||
--go-grpc_out=. \ | ||
--go-grpc_opt=require_unimplemented_servers=false,paths=source_relative \ | ||
--p6_out ./cmd/layotto_multiple_api/advanced_queue --p6_opt=paths=source_relative \ | ||
cmd/layotto_multiple_api/advanced_queue/advanced_queue.proto | ||
``` | ||
|
||
then you get the code: | ||
|
||
<img src="https://user-images.githubusercontent.com/26001097/189822603-c4c9d0c6-86a1-4a66-bba8-3d01758808e7.png" width="30%" height="30%" /> | ||
|
||
Fix the path error and then you can register this API plugin in you `main`. | ||
|
||
## Reference | ||
|
||
[How to generate code and documentation from the .proto files](en/api_reference/how_to_generate_api_doc) | ||
|
||
[protoc-gen-p6](https://github.com/seeflood/protoc-gen-p6) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# 自动生成 API 插件 | ||
|
||
Writing the API plugin yourself is boring. You can use code generator to generate all the code. | ||
|
||
Let's say you want to add a `PublishTransactionalMessage` method to existing pubsub API. You write a new proto file `cmd/layotto_multiple_api/advanced_queue/advanced_queue.proto` : | ||
|
||
```protobuf | ||
// ...... | ||
/* @exclude extends pub_subs */ | ||
// AdvancedQueue is advanced pubsub API | ||
service AdvancedQueue { | ||
rpc PublishTransactionalMessage(TransactionalMessageRequest) returns (TransactionalMessageResponse); | ||
} | ||
message TransactionalMessageRequest { | ||
string store_name = 1; | ||
string content = 2; | ||
} | ||
message TransactionalMessageResponse { | ||
string message_id = 1; | ||
} | ||
``` | ||
|
||
and run the generator: | ||
|
||
```protobuf | ||
protoc -I . \ | ||
--go_out . --go_opt=paths=source_relative \ | ||
--go-grpc_out=. \ | ||
--go-grpc_opt=require_unimplemented_servers=false,paths=source_relative \ | ||
--p6_out ./cmd/layotto_multiple_api/advanced_queue --p6_opt=paths=source_relative \ | ||
cmd/layotto_multiple_api/advanced_queue/advanced_queue.proto | ||
``` | ||
|
||
then you get the code: | ||
|
||
<img src="https://user-images.githubusercontent.com/26001097/189822603-c4c9d0c6-86a1-4a66-bba8-3d01758808e7.png" width="30%" height="30%" /> | ||
|
||
Fix the path error and then you can register this API plugin in you `main`. | ||
|
||
## Reference | ||
|
||
[How to generate code and documentation from the .proto files](zh/api_reference/how_to_generate_api_doc) | ||
|
||
[protoc-gen-p6](https://github.com/seeflood/protoc-gen-p6) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters