@@ -9,6 +9,8 @@ This section describes how you can configure your grpc-spring-boot-starter clien
9
9
- [ Configuration via Properties] ( #configuration-via-properties )
10
10
- [ Choosing the Target] ( #choosing-the-target )
11
11
- [ Configuration via Beans] ( #configuration-via-beans )
12
+ - [ GrpcClientBean] ( #grpcclientbean )
13
+ - [ GrpcClientBeans] ( #grpcclientbeans )
12
14
- [ GrpcChannelConfigurer] ( #grpcchannelconfigurer )
13
15
- [ ClientInterceptor] ( #clientinterceptor )
14
16
- [ StubFactory] ( #stubfactory )
@@ -115,6 +117,93 @@ First of all most of the beans can be replaced by custom ones, that you can conf
115
117
If you don't wish to go that far, you can use classes such as ` GrpcChannelConfigurer ` and ` StubTransformer ` to configure
116
118
the channels, stubs and other components without losing the features provided by this library.
117
119
120
+ ### GrpcClientBean
121
+
122
+ This should significantly help with `` @Autowire `` and `` @Qualifier `` because default annotation`` @GrpcClient `` is
123
+ not designed for usage with spring 'injection' annotations.
124
+ `` @GrpcClientBean `` require annotation `` @Cofiguration `` or inherited, for example `` @TestConfiguraiton `` .
125
+ It is definitely not recommended using `` @GrpcClientBean `` and field annotated with `` @GrpcClient `` for same
126
+ configuration class, but it`s still possible.
127
+
128
+ ```` java
129
+ @Configuration
130
+ @GrpcClientBean (
131
+ clazz = TestServiceGrpc . TestServiceBlockingStub . class,
132
+ beanName = " blockingStub" ,
133
+ client = @GrpcClient (" test" )
134
+ )
135
+ public static class YourCustomConfiguration {
136
+
137
+ @Bean
138
+ FoobarService (@Autowired TestServiceGrpc .TestServiceBlockingStub blockingStub ) {
139
+ return new FoobarService (blockingStub);
140
+ }
141
+ }
142
+
143
+ @Service
144
+ @AllArgsConsturtor
145
+ public class FoobarService {
146
+ private TestServiceBlockingStub blockingStub;
147
+
148
+ public String receiveGreeting (String name ) {
149
+ HelloRequest request = HelloRequest . newBuilder()
150
+ .setName(name)
151
+ .build();
152
+ return blockingStub. sayHello(request). getMessage();
153
+ }
154
+
155
+ }
156
+ ````
157
+
158
+ ### GrpcClientBeans
159
+
160
+ `` @GrpcClientBeans `` designed for registration multiple stubs to the spring context from single configuration class.
161
+
162
+ ```` java
163
+ @Configuration
164
+ @GrpcClientBeans (value = {
165
+ @GrpcClientBean (
166
+ clazz = TestServiceGrpc . TestServiceBlockingStub . class,
167
+ beanName = " blockingStub" ,
168
+ client = @GrpcClient (" test" )),
169
+ @GrpcClientBean (
170
+ clazz = TestServiceGrpc . FactoryMethodAccessibleStub . class,
171
+ beanName = " accessibleStub" ,
172
+ client = @GrpcClient (" test" ))
173
+ })
174
+ public static class YourCustomConfiguration {
175
+
176
+ @Bean
177
+ FoobarService (@Autowired TestServiceGrpc .TestServiceBlockingStub blockingStub ,
178
+ @Autowired TestServiceGrpc .FactoryMethodAccessibleStub accessibleStub ) {
179
+ return new FoobarService (blockingStub, accessibleStub);
180
+ }
181
+ }
182
+
183
+ @Service
184
+ @AllArgsConsturtor
185
+ public class FoobarService {
186
+
187
+ private TestServiceBlockingStub blockingStub;
188
+ private FactoryMethodAccessibleStub accessibleStub;
189
+
190
+ public String receiveGreeting (String name ) {
191
+ HelloRequest request = HelloRequest . newBuilder()
192
+ .setName(name)
193
+ .build();
194
+ return blockingStub. sayHello(request). getMessage();
195
+ }
196
+
197
+ public String receiveAnotherGreeting (String name ) {
198
+ HelloRequest request = HelloRequest . newBuilder()
199
+ .setName(name)
200
+ .build();
201
+ return accessibleStub. sayHi(request). getMessage();
202
+ }
203
+
204
+ }
205
+ ````
206
+
118
207
### GrpcChannelConfigurer
119
208
120
209
The grpc client configurer allows you to add your custom configuration to grpc's ` ManagedChannelBuilder ` s.
0 commit comments