-
Notifications
You must be signed in to change notification settings - Fork 227
Expand file tree
/
Copy pathDaprPreviewClient.java
More file actions
358 lines (326 loc) · 15.4 KB
/
DaprPreviewClient.java
File metadata and controls
358 lines (326 loc) · 15.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
/*
* Copyright 2022 The Dapr Authors
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
limitations under the License.
*/
package io.dapr.client;
import io.dapr.client.domain.BulkPublishEntry;
import io.dapr.client.domain.BulkPublishRequest;
import io.dapr.client.domain.BulkPublishResponse;
import io.dapr.client.domain.BulkPublishResponseFailedEntry;
import io.dapr.client.domain.CloudEvent;
import io.dapr.client.domain.ConversationRequest;
import io.dapr.client.domain.ConversationRequestAlpha2;
import io.dapr.client.domain.ConversationResponse;
import io.dapr.client.domain.ConversationResponseAlpha2;
import io.dapr.client.domain.DecryptRequestAlpha1;
import io.dapr.client.domain.DeleteJobRequest;
import io.dapr.client.domain.EncryptRequestAlpha1;
import io.dapr.client.domain.GetJobRequest;
import io.dapr.client.domain.GetJobResponse;
import io.dapr.client.domain.LockRequest;
import io.dapr.client.domain.QueryStateRequest;
import io.dapr.client.domain.QueryStateResponse;
import io.dapr.client.domain.ScheduleJobRequest;
import io.dapr.client.domain.UnlockRequest;
import io.dapr.client.domain.UnlockResponseStatus;
import io.dapr.client.domain.query.Query;
import io.dapr.utils.TypeRef;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import java.util.List;
import java.util.Map;
/**
* Generic client interface for preview or alpha APIs in Dapr, regardless of GRPC or HTTP.
*
* @see io.dapr.client.DaprClientBuilder for information on how to make instance for this interface.
*/
public interface DaprPreviewClient extends AutoCloseable {
/**
* Query for states using a query string.
*
* @param storeName Name of the state store to query.
* @param query String value of the query.
* @param metadata Optional metadata passed to the state store.
* @param clazz The type needed as return for the call.
* @param <T> The Type of the return, use byte[] to skip serialization.
* @return A Mono of QueryStateResponse of type T.
*/
<T> Mono<QueryStateResponse<T>> queryState(String storeName, String query,
Map<String, String> metadata, Class<T> clazz);
/**
* Query for states using a query string.
*
* @param storeName Name of the state store to query.
* @param query String value of the query.
* @param metadata Optional metadata passed to the state store.
* @param type The type needed as return for the call.
* @param <T> The Type of the return, use byte[] to skip serialization.
* @return A Mono of QueryStateResponse of type T.
*/
<T> Mono<QueryStateResponse<T>> queryState(String storeName, String query,
Map<String, String> metadata, TypeRef<T> type);
/**
* Query for states using a query string.
*
* @param storeName Name of the state store to query.
* @param query String value of the query.
* @param clazz The type needed as return for the call.
* @param <T> The Type of the return, use byte[] to skip serialization.
* @return A Mono of QueryStateResponse of type T.
*/
<T> Mono<QueryStateResponse<T>> queryState(String storeName, String query, Class<T> clazz);
/**
* Query for states using a query string.
*
* @param storeName Name of the state store to query.
* @param query String value of the query.
* @param type The type needed as return for the call.
* @param <T> The Type of the return, use byte[] to skip serialization.
* @return A Mono of QueryStateResponse of type T.
*/
<T> Mono<QueryStateResponse<T>> queryState(String storeName, String query, TypeRef<T> type);
/**
* Query for states using a query domain object.
*
* @param storeName Name of the state store to query.
* @param query Query value domain object.
* @param metadata Optional metadata passed to the state store.
* @param clazz The type needed as return for the call.
* @param <T> The Type of the return, use byte[] to skip serialization.
* @return A Mono of QueryStateResponse of type T.
*/
<T> Mono<QueryStateResponse<T>> queryState(String storeName, Query query,
Map<String, String> metadata, Class<T> clazz);
/**
* Query for states using a query domain object.
*
* @param storeName Name of the state store to query.
* @param query Query value domain object.
* @param metadata Optional metadata passed to the state store.
* @param type The type needed as return for the call.
* @param <T> The Type of the return, use byte[] to skip serialization.
* @return A Mono of QueryStateResponse of type T.
*/
<T> Mono<QueryStateResponse<T>> queryState(String storeName, Query query,
Map<String, String> metadata, TypeRef<T> type);
/**
* Query for states using a query domain object.
*
* @param storeName Name of the state store to query.
* @param query Query value domain object.
* @param clazz The type needed as return for the call.
* @param <T> The Type of the return, use byte[] to skip serialization.
* @return A Mono of QueryStateResponse of type T.
*/
<T> Mono<QueryStateResponse<T>> queryState(String storeName, Query query, Class<T> clazz);
/**
* Query for states using a query domain object.
*
* @param storeName Name of the state store to query.
* @param query Query value domain object.
* @param type The type needed as return for the call.
* @param <T> The Type of the return, use byte[] to skip serialization.
* @return A Mono of QueryStateResponse of type T.
*/
<T> Mono<QueryStateResponse<T>> queryState(String storeName, Query query, TypeRef<T> type);
/**
* Query for states using a query request.
*
* @param request Query request object.
* @param clazz The type needed as return for the call.
* @param <T> The Type of the return, use byte[] to skip serialization.
* @return A Mono of QueryStateResponse of type T.
*/
<T> Mono<QueryStateResponse<T>> queryState(QueryStateRequest request, Class<T> clazz);
/**
* Query for states using a query request.
*
* @param request Query request object.
* @param type The type needed as return for the call.
* @param <T> The Type of the return, use byte[] to skip serialization.
* @return A Mono of QueryStateResponse of type T.
*/
<T> Mono<QueryStateResponse<T>> queryState(QueryStateRequest request, TypeRef<T> type);
/**
* Publish multiple events to Dapr in a single request.
*
* @param request {@link BulkPublishRequest} object.
* @return A Mono of {@link BulkPublishResponse} object.
* @param <T> The type of events to publish in the call.
*/
<T> Mono<BulkPublishResponse<T>> publishEvents(BulkPublishRequest<T> request);
/**
* Publish multiple events to Dapr in a single request.
*
* @param pubsubName the pubsub name we will publish the event to.
* @param topicName the topicName where the event will be published.
* @param events the {@link List} of events to be published.
* @param contentType the content type of the event. Use Mime based types.
* @return the {@link BulkPublishResponse} containing publish status of each event.
* The "entryID" field in {@link BulkPublishEntry} in {@link BulkPublishResponseFailedEntry} will be
* generated based on the order of events in the {@link List}.
* @param <T> The type of the events to publish in the call.
*/
<T> Mono<BulkPublishResponse<T>> publishEvents(String pubsubName, String topicName, String contentType,
List<T> events);
/**
* Publish multiple events to Dapr in a single request.
*
* @param pubsubName the pubsub name we will publish the event to.
* @param topicName the topicName where the event will be published.
* @param events the varargs of events to be published.
* @param contentType the content type of the event. Use Mime based types.
* @return the {@link BulkPublishResponse} containing publish status of each event.
* The "entryID" field in {@link BulkPublishEntry} in {@link BulkPublishResponseFailedEntry} will be
* generated based on the order of events in the {@link List}.
* @param <T> The type of the events to publish in the call.
*/
<T> Mono<BulkPublishResponse<T>> publishEvents(String pubsubName, String topicName, String contentType,
T... events);
/**
* Publish multiple events to Dapr in a single request.
*
* @param pubsubName the pubsub name we will publish the event to.
* @param topicName the topicName where the event will be published.
* @param events the {@link List} of events to be published.
* @param contentType the content type of the event. Use Mime based types.
* @param requestMetadata the metadata to be set at the request level for the {@link BulkPublishRequest}.
* @return the {@link BulkPublishResponse} containing publish status of each event.
* The "entryID" field in {@link BulkPublishEntry} in {@link BulkPublishResponseFailedEntry} will be
* generated based on the order of events in the {@link List}.
* @param <T> The type of the events to publish in the call.
*/
<T> Mono<BulkPublishResponse<T>> publishEvents(String pubsubName, String topicName, String contentType,
Map<String,String> requestMetadata, List<T> events);
/**
* Publish multiple events to Dapr in a single request.
*
* @param pubsubName the pubsub name we will publish the event to.
* @param topicName the topicName where the event will be published.
* @param events the varargs of events to be published.
* @param contentType the content type of the event. Use Mime based types.
* @param requestMetadata the metadata to be set at the request level for the {@link BulkPublishRequest}.
* @return the {@link BulkPublishResponse} containing publish status of each event.
* The "entryID" field in {@link BulkPublishEntry} in {@link BulkPublishResponseFailedEntry} will be
* generated based on the order of events in the {@link List}.
* @param <T> The type of the events to publish in the call.
*/
<T> Mono<BulkPublishResponse<T>> publishEvents(String pubsubName, String topicName, String contentType,
Map<String,String> requestMetadata, T... events);
/**
* Tries to get a lock with an expiry.
* @param storeName Name of the store
* @param resourceId Lock key
* @param lockOwner The identifier of lock owner
* @param expiryInSeconds The time before expiry
* @return Whether the lock is successful
*/
Mono<Boolean> tryLock(String storeName, String resourceId, String lockOwner, Integer expiryInSeconds);
/**
* Tries to get a lock with an expiry.
* @param request The request to lock
* @return Whether the lock is successful
*/
Mono<Boolean> tryLock(LockRequest request);
/**
* Unlocks a lock.
* @param storeName Name of the store
* @param resourceId Lock key
* @param lockOwner The identifier of lock owner
* @return Unlock result
*/
Mono<UnlockResponseStatus> unlock(String storeName, String resourceId, String lockOwner);
/**
* Unlocks a lock.
* @param request The request to unlock
* @return Unlock result
*/
Mono<UnlockResponseStatus> unlock(UnlockRequest request);
/**
* Subscribe to pubsub via streaming.
* @param pubsubName Name of the pubsub component.
* @param topic Name of the topic to subscribe to.
* @param listener Callback methods to process events.
* @param type Type for object deserialization.
* @param <T> Type of object deserialization.
* @return An active subscription.
* @deprecated Use {@link #subscribeToEvents(String, String, TypeRef)} instead for a more reactive approach.
*/
@Deprecated
<T> Subscription subscribeToEvents(
String pubsubName, String topic, SubscriptionListener<T> listener, TypeRef<T> type);
/**
* Subscribe to pubsub via streaming.
* @param pubsubName Name of the pubsub component.
* @param topic Name of the topic to subscribe to.
* @param listener Callback methods to process events.
* @param deadLetterTopic Topic to send dead letter messages to.
* @param type Type for object deserialization.
* @param <T> Type of object deserialization.
* @return An active subscription.
* @deprecated Use {@link #subscribeToEvents(String, String, TypeRef)} instead for a more reactive approach.
*/
@Deprecated
<T> Subscription subscribeToEvents(
String pubsubName, String topic, SubscriptionListener<T> listener, String deadLetterTopic, TypeRef<T> type);
/**
* Subscribe to pubsub events via streaming using Project Reactor Flux.
* @param pubsubName Name of the pubsub component.
* @param topic Name of the topic to subscribe to.
* @param type Type for object deserialization.
* @return A Flux of CloudEvents containing deserialized event payloads and metadata.
* @param <T> Type of the event payload.
*/
<T> Flux<CloudEvent<T>> subscribeToEvents(String pubsubName, String topic, TypeRef<T> type);
/**
* Subscribe to pubsub events via streaming using Project Reactor Flux.
* @param pubsubName Name of the pubsub component.
* @param topic Name of the topic to subscribe to.
* @param deadLetterTopic Topic to send dead letter messages to.
* @param type Type for object deserialization.
* @return A Flux of CloudEvents containing deserialized event payloads and metadata.
* @param <T> Type of the event payload.
*/
<T> Flux<CloudEvent<T>> subscribeToEvents(String pubsubName, String topic, String deadLetterTopic, TypeRef<T> type);
/*
* Converse with an LLM.
*
* @param conversationRequest request to be passed to the LLM.
* @return {@link ConversationResponse}.
*/
@Deprecated
public Mono<ConversationResponse> converse(ConversationRequest conversationRequest);
/*
* Converse with an LLM using Alpha2 API.
*
* @param conversationRequestAlpha2 request to be passed to the LLM with Alpha2 features.
* @return {@link ConversationResponseAlpha2}.
*/
public Mono<ConversationResponseAlpha2> converseAlpha2(ConversationRequestAlpha2 conversationRequestAlpha2);
/**
* Encrypt data using the Dapr cryptography building block.
* This method uses streaming to handle large payloads efficiently.
*
* @param request The encryption request containing component name, key information, and plaintext stream.
* @return A Flux of encrypted byte arrays (ciphertext chunks).
* @throws IllegalArgumentException if required parameters are missing.
*/
Flux<byte[]> encrypt(EncryptRequestAlpha1 request);
/**
* Decrypt data using the Dapr cryptography building block.
* This method uses streaming to handle large payloads efficiently.
*
* @param request The decryption request containing component name, optional key name, and ciphertext stream.
* @return A Flux of decrypted byte arrays (plaintext chunks).
* @throws IllegalArgumentException if required parameters are missing.
*/
Flux<byte[]> decrypt(DecryptRequestAlpha1 request);
}