@@ -119,11 +119,6 @@ public class DaprClientImpl extends AbstractDaprClient {
119
119
*/
120
120
private final GrpcChannelFacade channel ;
121
121
122
- /**
123
- * The timeout policy.
124
- */
125
- private final TimeoutPolicy timeoutPolicy ;
126
-
127
122
/**
128
123
* The retry policy.
129
124
*/
@@ -141,9 +136,10 @@ public class DaprClientImpl extends AbstractDaprClient {
141
136
*/
142
137
private final DaprHttp httpClient ;
143
138
139
+ private final DaprClientGrpcInterceptors grpcInterceptors ;
140
+
144
141
/**
145
- * Default access level constructor, in order to create an instance of this
146
- * class use io.dapr.client.DaprClientBuilder
142
+ * Default access level constructor, in order to create an instance of this class use io.dapr.client.DaprClientBuilder
147
143
*
148
144
* @param channel Facade for the managed GRPC channel
149
145
* @param asyncStub async gRPC stub
@@ -157,7 +153,27 @@ public class DaprClientImpl extends AbstractDaprClient {
157
153
DaprHttp httpClient ,
158
154
DaprObjectSerializer objectSerializer ,
159
155
DaprObjectSerializer stateSerializer ) {
160
- this (channel , asyncStub , httpClient , objectSerializer , stateSerializer , null );
156
+ this (channel , asyncStub , httpClient , objectSerializer , stateSerializer , null , null );
157
+ }
158
+
159
+ /**
160
+ * Default access level constructor, in order to create an instance of this class use io.dapr.client.DaprClientBuilder
161
+ *
162
+ * @param channel Facade for the managed GRPC channel
163
+ * @param asyncStub async gRPC stub
164
+ * @param objectSerializer Serializer for transient request/response objects.
165
+ * @param stateSerializer Serializer for state objects.
166
+ * @param daprApiToken Dapr API Token.
167
+ * @see DaprClientBuilder
168
+ */
169
+ DaprClientImpl (
170
+ GrpcChannelFacade channel ,
171
+ DaprGrpc .DaprStub asyncStub ,
172
+ DaprHttp httpClient ,
173
+ DaprObjectSerializer objectSerializer ,
174
+ DaprObjectSerializer stateSerializer ,
175
+ String daprApiToken ) {
176
+ this (channel , asyncStub , httpClient , objectSerializer , stateSerializer , null , daprApiToken );
161
177
}
162
178
163
179
/**
@@ -169,6 +185,7 @@ public class DaprClientImpl extends AbstractDaprClient {
169
185
* @param objectSerializer Serializer for transient request/response objects.
170
186
* @param stateSerializer Serializer for state objects.
171
187
* @param resiliencyOptions Client-level override for resiliency options.
188
+ * @param daprApiToken Dapr API Token.
172
189
* @see DaprClientBuilder
173
190
*/
174
191
DaprClientImpl (
@@ -177,15 +194,47 @@ public class DaprClientImpl extends AbstractDaprClient {
177
194
DaprHttp httpClient ,
178
195
DaprObjectSerializer objectSerializer ,
179
196
DaprObjectSerializer stateSerializer ,
180
- ResiliencyOptions resiliencyOptions ) {
197
+ ResiliencyOptions resiliencyOptions ,
198
+ String daprApiToken ) {
199
+ this (
200
+ channel ,
201
+ asyncStub ,
202
+ httpClient ,
203
+ objectSerializer ,
204
+ stateSerializer ,
205
+ new TimeoutPolicy (resiliencyOptions == null ? null : resiliencyOptions .getTimeout ()),
206
+ new RetryPolicy (resiliencyOptions == null ? null : resiliencyOptions .getMaxRetries ()),
207
+ daprApiToken );
208
+ }
209
+
210
+ /**
211
+ * Instantiates a new DaprClient.
212
+ *
213
+ * @param channel Facade for the managed GRPC channel
214
+ * @param asyncStub async gRPC stub
215
+ * @param httpClient client for http service invocation
216
+ * @param objectSerializer Serializer for transient request/response objects.
217
+ * @param stateSerializer Serializer for state objects.
218
+ * @param timeoutPolicy Client-level timeout policy.
219
+ * @param retryPolicy Client-level retry policy.
220
+ * @param daprApiToken Dapr API Token.
221
+ * @see DaprClientBuilder
222
+ */
223
+ private DaprClientImpl (
224
+ GrpcChannelFacade channel ,
225
+ DaprGrpc .DaprStub asyncStub ,
226
+ DaprHttp httpClient ,
227
+ DaprObjectSerializer objectSerializer ,
228
+ DaprObjectSerializer stateSerializer ,
229
+ TimeoutPolicy timeoutPolicy ,
230
+ RetryPolicy retryPolicy ,
231
+ String daprApiToken ) {
181
232
super (objectSerializer , stateSerializer );
182
233
this .channel = channel ;
183
234
this .asyncStub = asyncStub ;
184
235
this .httpClient = httpClient ;
185
- this .timeoutPolicy = new TimeoutPolicy (
186
- resiliencyOptions == null ? null : resiliencyOptions .getTimeout ());
187
- this .retryPolicy = new RetryPolicy (
188
- resiliencyOptions == null ? null : resiliencyOptions .getMaxRetries ());
236
+ this .retryPolicy = retryPolicy ;
237
+ this .grpcInterceptors = new DaprClientGrpcInterceptors (daprApiToken , timeoutPolicy );
189
238
}
190
239
191
240
private CommonProtos .StateOptions .StateConsistency getGrpcStateConsistency (StateOptions options ) {
@@ -215,7 +264,7 @@ private CommonProtos.StateOptions.StateConcurrency getGrpcStateConcurrency(State
215
264
*/
216
265
public <T extends AbstractStub <T >> T newGrpcStub (String appId , Function <Channel , T > stubBuilder ) {
217
266
// Adds Dapr interceptors to populate gRPC metadata automatically.
218
- return DaprClientGrpcInterceptors . intercept (appId , stubBuilder .apply (this .channel .getGrpcChannel ()), timeoutPolicy );
267
+ return this . grpcInterceptors . intercept (appId , stubBuilder .apply (this .channel .getGrpcChannel ()));
219
268
}
220
269
221
270
/**
@@ -425,7 +474,8 @@ private <T> Subscription<T> buildSubscription(
425
474
SubscriptionListener <T > listener ,
426
475
TypeRef <T > type ,
427
476
DaprProtos .SubscribeTopicEventsRequestAlpha1 request ) {
428
- Subscription <T > subscription = new Subscription <>(this .asyncStub , request , listener , response -> {
477
+ var interceptedStub = this .grpcInterceptors .intercept (this .asyncStub );
478
+ Subscription <T > subscription = new Subscription <>(interceptedStub , request , listener , response -> {
429
479
if (response .getEventMessage () == null ) {
430
480
return null ;
431
481
}
@@ -1268,7 +1318,7 @@ private ConfigurationItem buildConfigurationItem(
1268
1318
* @return Client after adding interceptors.
1269
1319
*/
1270
1320
private DaprGrpc .DaprStub intercept (ContextView context , DaprGrpc .DaprStub client ) {
1271
- return DaprClientGrpcInterceptors . intercept (client , this . timeoutPolicy , context );
1321
+ return this . grpcInterceptors . intercept (client , context );
1272
1322
}
1273
1323
1274
1324
/**
@@ -1281,7 +1331,7 @@ private DaprGrpc.DaprStub intercept(ContextView context, DaprGrpc.DaprStub clien
1281
1331
*/
1282
1332
private DaprGrpc .DaprStub intercept (
1283
1333
ContextView context , DaprGrpc .DaprStub client , Consumer <Metadata > metadataConsumer ) {
1284
- return DaprClientGrpcInterceptors . intercept (client , this . timeoutPolicy , context , metadataConsumer );
1334
+ return this . grpcInterceptors . intercept (client , context , metadataConsumer );
1285
1335
}
1286
1336
1287
1337
private <T > Mono <T > createMono (Consumer <StreamObserver <T >> consumer ) {
0 commit comments