1
1
# Reflection service
2
2
3
- This tutorial goes through the steps of adding Reflection service to a
4
- server, running it and testing it using gRPCurl.
3
+ This tutorial goes through the steps of adding Reflection service to a
4
+ server, running it and testing it using gRPCurl.
5
5
6
- The server used in this example is implemented at
6
+ The server used in this example is implemented at
7
7
[ Sources/Examples/ReflectionService/ReflectionServer.swift] [ reflection-server ]
8
- and it supports the "Greeter", "Echo", and "Reflection" services.
8
+ and it supports the "Greeter", "Echo", and "Reflection" services.
9
9
10
10
11
11
## Overview
12
12
13
- The Reflection service provides information about the public RPCs served by a server.
13
+ The Reflection service provides information about the public RPCs served by a server.
14
14
It is specific to services defined using the Protocol Buffers IDL.
15
15
By calling the Reflection service, clients can construct and send requests to services
16
- without needing to generate code and types for them.
16
+ without needing to generate code and types for them.
17
17
18
- You can also use CLI clients such as [ gRPCurl] [ grpcurl-setup ] and the [ gRPC command line tool] [ grpc-cli ] to:
18
+ You can also use CLI clients such as [ gRPCurl] [ grpcurl-setup ] and the [ gRPC command line tool] [ grpc-cli ] to:
19
19
- list services,
20
20
- describe services and their methods,
21
21
- describe symbols,
@@ -28,17 +28,17 @@ gRPC Swift supports both [v1][v1] and [v1alpha][v1alpha] of the reflection servi
28
28
29
29
You can use the Reflection service by adding it as a provider when constructing your server.
30
30
31
- To initialise the Reflection service we will use
31
+ To initialise the Reflection service we will use
32
32
`` GRPCReflectionService/ReflectionService/init(reflectionDataFileURLs:version:) `` .
33
- It receives the URLs of the files containing the reflection data of the proto files
33
+ It receives the URLs of the files containing the reflection data of the proto files
34
34
describing the services of the server and the version of the reflection service.
35
35
36
36
### Generating the reflection data
37
37
38
38
The server from this example uses the ` GreeterProvider ` and the ` EchoProvider ` ,
39
39
besides the ` ReflectionService ` .
40
40
41
- The associated proto files are located at ` Sources/Examples/HelloWorld/Model/helloworld.proto ` , and
41
+ The associated proto files are located at ` Sources/Examples/HelloWorld/Model/helloworld.proto ` , and
42
42
` Sources/Examples/Echo/Model/echo.proto ` respectively.
43
43
44
44
In order to generate the reflection data for the ` helloworld.proto ` , you can run the following command:
@@ -51,8 +51,8 @@ $ protoc Sources/Examples/HelloWorld/Model/helloworld.proto \
51
51
```
52
52
53
53
Let's break the command down:
54
- - The first argument passed to ` protoc ` is the path
55
- to the ` .proto ` file to generate reflection data
54
+ - The first argument passed to ` protoc ` is the path
55
+ to the ` .proto ` file to generate reflection data
56
56
for: [ ` Sources/Examples/HelloWorld/Model/helloworld.proto ` ] [ helloworld-proto ] .
57
57
- The ` proto_path ` flag is the path to search for imports: ` Sources/Examples/HelloWorld/Model ` .
58
58
- The 'grpc-swift_opt' flag allows us to list options for the Swift generator.
@@ -61,18 +61,18 @@ Let's break the command down:
61
61
where the generated file will be located: ` Sources/Examples/ReflectionService/Generated ` .
62
62
63
63
This command assumes that the ` protoc-gen-grpc-swift ` plugin is in your ` $PATH ` environment variable.
64
- You can learn how to get the plugin from this section of the ` grpc-swift ` README:
64
+ You can learn how to get the plugin from this section of the ` grpc-swift ` README:
65
65
https://github.com/grpc/grpc-swift#getting-the-protoc-plugins .
66
66
67
67
The command for generating the reflection data for the ` Echo ` service is similar.
68
68
69
- You can use Swift Package Manager [ resources] [ swiftpm-resources ] to add the generated reflection data to your target.
70
- In our example the reflection data is written into the "Generated" directory within the target
69
+ You can use Swift Package Manager [ resources] [ swiftpm-resources ] to add the generated reflection data to your target.
70
+ In our example the reflection data is written into the "Generated" directory within the target
71
71
so we include the ` .copy("Generated") ` rule in our target's resource list.
72
72
73
- ### Instantiating the Reflection service
73
+ ### Instantiating the Reflection service
74
74
75
- To instantiate the ` ReflectionService ` you need to pass the URLs of the files containing
75
+ To instantiate the ` ReflectionService ` you need to pass the URLs of the files containing
76
76
the generated reflection data and the version to use, in our case ` .v1 ` .
77
77
78
78
Depending on the version of [ gRPCurl] [ grpcurl ] you are using you might need to use the ` .v1alpha ` instead.
@@ -84,9 +84,14 @@ reflection.
84
84
guard
85
85
let greeterURL = Bundle.module.url (
86
86
forResource : " helloworld" ,
87
- withExtension : " grpc.reflection.txt"
87
+ withExtension : " grpc.reflection" ,
88
+ subdirectory : " Generated"
88
89
),
89
- let echoURL = Bundle.module.url (forResource : " echo" , withExtension : " grpc.reflection.txt" )
90
+ let echoURL = Bundle.module.url (
91
+ forResource : " echo" ,
92
+ withExtension : " grpc.reflection" ,
93
+ subdirectory : " Generated"
94
+ )
90
95
else {
91
96
print (" The resource could not be loaded." )
92
97
throw ExitCode.failure
@@ -123,7 +128,7 @@ Please follow the instructions from the [gRPCurl README][grpcurl-setup] to set u
123
128
From a different terminal than the one used for running the server, we will call gRPCurl commands,
124
129
following the format: ` grpcurl [flags] [address] [list|describe] [symbol] ` .
125
130
126
- We use the ` -plaintext ` flag, because the server isn't configured with TLS, and
131
+ We use the ` -plaintext ` flag, because the server isn't configured with TLS, and
127
132
the address is set to ` localhost:1234 ` .
128
133
129
134
0 commit comments