mirror of https://github.com/dapr/java-sdk.git
Fix doc references to preview for configuration API. (#896)
Signed-off-by: Artur Souza <asouza.pro@gmail.com> Signed-off-by: Artur Souza <artursouza.ms@outlook.com>
This commit is contained in:
parent
14d836310c
commit
6759f19f83
|
|
@ -107,6 +107,189 @@ Put the Dapr Java SDK to the test. Walk through the Java quickstarts and tutoria
|
|||
| [Quickstarts]({{< ref quickstarts >}}) | Experience Dapr's API building blocks in just a few minutes using the Java SDK. |
|
||||
| [SDK samples](https://github.com/dapr/java-sdk/tree/master/examples) | Clone the SDK repo to try out some examples and get started. |
|
||||
|
||||
## More information
|
||||
```java
|
||||
import io.dapr.client.DaprClient;
|
||||
import io.dapr.client.DaprClientBuilder;
|
||||
|
||||
try (DaprClient client = (new DaprClientBuilder()).build()) {
|
||||
// sending a class with message; BINDING_OPERATION="create"
|
||||
client.invokeBinding(BINDING_NAME, BINDING_OPERATION, myClass).block();
|
||||
|
||||
// sending a plain string
|
||||
client.invokeBinding(BINDING_NAME, BINDING_OPERATION, message).block();
|
||||
}
|
||||
```
|
||||
|
||||
- For a full guide on output bindings visit [How-To: Output bindings]({{< ref howto-bindings.md >}}).
|
||||
- Visit [Java SDK examples](https://github.com/dapr/java-sdk/tree/master/examples/src/main/java/io/dapr/examples/bindings/http) for code samples and instructions to try out output bindings.
|
||||
|
||||
### Interact with input bindings
|
||||
|
||||
```java
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/")
|
||||
public class myClass {
|
||||
private static final Logger log = LoggerFactory.getLogger(myClass);
|
||||
@PostMapping(path = "/checkout")
|
||||
public Mono<String> getCheckout(@RequestBody(required = false) byte[] body) {
|
||||
return Mono.fromRunnable(() ->
|
||||
log.info("Received Message: " + new String(body)));
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
- For a full guide on input bindings, visit [How-To: Input bindings]({{< ref howto-triggers >}}).
|
||||
- Visit [Java SDK examples](https://github.com/dapr/java-sdk/tree/master/examples/src/main/java/io/dapr/examples/bindings/http) for code samples and instructions to try out input bindings.
|
||||
|
||||
### Retrieve secrets
|
||||
|
||||
```java
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.dapr.client.DaprClient;
|
||||
import io.dapr.client.DaprClientBuilder;
|
||||
import java.util.Map;
|
||||
|
||||
try (DaprClient client = (new DaprClientBuilder()).build()) {
|
||||
Map<String, String> secret = client.getSecret(SECRET_STORE_NAME, secretKey).block();
|
||||
System.out.println(JSON_SERIALIZER.writeValueAsString(secret));
|
||||
}
|
||||
```
|
||||
|
||||
- For a full guide on secrets visit [How-To: Retrieve secrets]({{< ref howto-secrets.md >}}).
|
||||
- Visit [Java SDK examples](https://github.com/dapr/java-sdk/tree/master/examples/src/main/java/io/dapr/examples/secrets) for code samples and instructions to try out retrieving secrets
|
||||
|
||||
### Actors
|
||||
An actor is an isolated, independent unit of compute and state with single-threaded execution. Dapr provides an actor implementation based on the [Virtual Actor pattern](https://www.microsoft.com/en-us/research/project/orleans-virtual-actors/), which provides a single-threaded programming model and where actors are garbage collected when not in use. With Dapr's implementaiton, you write your Dapr actors according to the Actor model, and Dapr leverages the scalability and reliability that the underlying platform provides.
|
||||
|
||||
```java
|
||||
import io.dapr.actors.ActorMethod;
|
||||
import io.dapr.actors.ActorType;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@ActorType(name = "DemoActor")
|
||||
public interface DemoActor {
|
||||
|
||||
void registerReminder();
|
||||
|
||||
@ActorMethod(name = "echo_message")
|
||||
String say(String something);
|
||||
|
||||
void clock(String message);
|
||||
|
||||
@ActorMethod(returns = Integer.class)
|
||||
Mono<Integer> incrementAndGet(int delta);
|
||||
}
|
||||
```
|
||||
|
||||
- For a full guide on actors visit [How-To: Use virtual actors in Dapr]({{< ref howto-actors.md >}}).
|
||||
- Visit [Java SDK examples](https://github.com/dapr/java-sdk/tree/master/examples/src/main/java/io/dapr/examples/actors) for code samples and instructions to try actors
|
||||
|
||||
### Get & Subscribe to application configurations
|
||||
|
||||
> Note this is a preview API and thus will only be accessible via the DaprPreviewClient interface and not the normal DaprClient interface
|
||||
|
||||
```java
|
||||
import io.dapr.client.DaprClient;
|
||||
import io.dapr.client.DaprClientBuilder;
|
||||
import io.dapr.client.domain.ConfigurationItem;
|
||||
import io.dapr.client.domain.GetConfigurationRequest;
|
||||
import io.dapr.client.domain.SubscribeConfigurationRequest;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
try (DaprClient client = (new DaprClientBuilder()).build()) {
|
||||
// Get configuration for a single key
|
||||
Mono<ConfigurationItem> item = client.getConfiguration(CONFIG_STORE_NAME, CONFIG_KEY).block();
|
||||
|
||||
// Get configurations for multiple keys
|
||||
Mono<Map<String, ConfigurationItem>> items =
|
||||
client.getConfiguration(CONFIG_STORE_NAME, CONFIG_KEY_1, CONFIG_KEY_2);
|
||||
|
||||
// Subscribe to configuration changes
|
||||
Flux<SubscribeConfigurationResponse> outFlux = client.subscribeConfiguration(CONFIG_STORE_NAME, CONFIG_KEY_1, CONFIG_KEY_2);
|
||||
outFlux.subscribe(configItems -> configItems.forEach(...));
|
||||
|
||||
// Unsubscribe from configuration changes
|
||||
Mono<UnsubscribeConfigurationResponse> unsubscribe = client.unsubscribeConfiguration(SUBSCRIPTION_ID, CONFIG_STORE_NAME)
|
||||
}
|
||||
```
|
||||
|
||||
- For a full list of configuration operations visit [How-To: Manage configuration from a store]({{< ref howto-manage-configuration.md >}}).
|
||||
- Visit [Java SDK examples](https://github.com/dapr/java-sdk/tree/master/examples/src/main/java/io/dapr/examples/configuration) for code samples and instructions to try out different configuration operations.
|
||||
|
||||
### Query saved state
|
||||
|
||||
> Note this is a preview API and thus will only be accessible via the DaprPreviewClient interface and not the normal DaprClient interface
|
||||
|
||||
```java
|
||||
import io.dapr.client.DaprClient;
|
||||
import io.dapr.client.DaprClientBuilder;
|
||||
import io.dapr.client.DaprPreviewClient;
|
||||
import io.dapr.client.domain.QueryStateItem;
|
||||
import io.dapr.client.domain.QueryStateRequest;
|
||||
import io.dapr.client.domain.QueryStateResponse;
|
||||
import io.dapr.client.domain.query.Query;
|
||||
import io.dapr.client.domain.query.Sorting;
|
||||
import io.dapr.client.domain.query.filters.EqFilter;
|
||||
|
||||
try (DaprClient client = builder.build(); DaprPreviewClient previewClient = builder.buildPreviewClient()) {
|
||||
String searchVal = args.length == 0 ? "searchValue" : args[0];
|
||||
|
||||
// Create JSON data
|
||||
Listing first = new Listing();
|
||||
first.setPropertyType("apartment");
|
||||
first.setId("1000");
|
||||
...
|
||||
Listing second = new Listing();
|
||||
second.setPropertyType("row-house");
|
||||
second.setId("1002");
|
||||
...
|
||||
Listing third = new Listing();
|
||||
third.setPropertyType("apartment");
|
||||
third.setId("1003");
|
||||
...
|
||||
Listing fourth = new Listing();
|
||||
fourth.setPropertyType("apartment");
|
||||
fourth.setId("1001");
|
||||
...
|
||||
Map<String, String> meta = new HashMap<>();
|
||||
meta.put("contentType", "application/json");
|
||||
|
||||
// Save state
|
||||
SaveStateRequest request = new SaveStateRequest(STATE_STORE_NAME).setStates(
|
||||
new State<>("1", first, null, meta, null),
|
||||
new State<>("2", second, null, meta, null),
|
||||
new State<>("3", third, null, meta, null),
|
||||
new State<>("4", fourth, null, meta, null)
|
||||
);
|
||||
client.saveBulkState(request).block();
|
||||
|
||||
|
||||
// Create query and query state request
|
||||
|
||||
Query query = new Query()
|
||||
.setFilter(new EqFilter<>("propertyType", "apartment"))
|
||||
.setSort(Arrays.asList(new Sorting("id", Sorting.Order.DESC)));
|
||||
QueryStateRequest request = new QueryStateRequest(STATE_STORE_NAME)
|
||||
.setQuery(query);
|
||||
|
||||
// Use preview client to call query state API
|
||||
QueryStateResponse<MyData> result = previewClient.queryState(request, MyData.class).block();
|
||||
|
||||
// View Query state response
|
||||
System.out.println("Found " + result.getResults().size() + " items.");
|
||||
for (QueryStateItem<Listing> item : result.getResults()) {
|
||||
System.out.println("Key: " + item.getKey());
|
||||
System.out.println("Data: " + item.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
- For a full list of configuration operations visit [How-To: Query state]({{< ref howto-state-query-api.md >}}).
|
||||
- Visit [Java SDK examples](https://github.com/dapr/java-sdk/tree/master/examples/src/main/java/io/dapr/examples/querystate) for complete code sample.
|
||||
|
||||
Learn more about the [Dapr Java SDK packages available to add to your Java applications](https://dapr.github.io/java-sdk/).
|
||||
|
|
@ -15,23 +15,18 @@ package io.dapr.examples.configuration.grpc;
|
|||
|
||||
import io.dapr.client.DaprClient;
|
||||
import io.dapr.client.DaprClientBuilder;
|
||||
import io.dapr.client.DaprPreviewClient;
|
||||
import io.dapr.client.domain.ConfigurationItem;
|
||||
import io.dapr.client.domain.GetConfigurationRequest;
|
||||
import io.dapr.client.domain.SubscribeConfigurationRequest;
|
||||
import io.dapr.client.domain.SubscribeConfigurationResponse;
|
||||
import io.dapr.client.domain.UnsubscribeConfigurationResponse;
|
||||
import reactor.core.Disposable;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
public class ConfigurationClient {
|
||||
|
||||
|
|
@ -55,7 +50,7 @@ public class ConfigurationClient {
|
|||
/**
|
||||
* Gets configurations for a list of keys.
|
||||
*
|
||||
* @param client DaprPreviewClient object
|
||||
* @param client DaprClient object
|
||||
*/
|
||||
public static void getConfigurations(DaprClient client) {
|
||||
System.out.println("*******trying to retrieve configurations for a list of keys********");
|
||||
|
|
@ -75,7 +70,7 @@ public class ConfigurationClient {
|
|||
/**
|
||||
* Subscribe to a list of keys.Optional to above iterator way of retrieving the changes
|
||||
*
|
||||
* @param client DaprPreviewClient object
|
||||
* @param client DaprClient object
|
||||
*/
|
||||
public static void subscribeConfigurationRequest(DaprClient client) {
|
||||
System.out.println("Subscribing to key: myconfig1");
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ docker exec dapr_redis redis-cli MSET myconfig1 "val1||1" myconfig2 "val2||1" my
|
|||
|
||||
This example uses the Java SDK Dapr client in order to **Get, Subscribe and Unsubscribe** from configuration items, and utilizes `Redis` as configuration store.
|
||||
`ConfigurationClient.java` is the example class demonstrating all 3 features.
|
||||
Kindly check [DaprPreviewClient.java](https://github.com/dapr/java-sdk/blob/master/sdk/src/main/java/io/dapr/client/DaprPreviewClient.java) for a detailed description of the supported APIs.
|
||||
Kindly check [DaprClient.java](https://github.com/dapr/java-sdk/blob/master/sdk/src/main/java/io/dapr/client/DaprClient.java) for a detailed description of the supported APIs.
|
||||
|
||||
```java
|
||||
public class ConfigurationClient {
|
||||
|
|
@ -72,7 +72,7 @@ public class ConfigurationClient {
|
|||
* @throws Exception throws Exception
|
||||
*/
|
||||
public static void main(String[] args) throws Exception {
|
||||
try (DaprPreviewClient client = (new DaprClientBuilder()).buildPreviewClient()) {
|
||||
try (DaprClient client = (new DaprClientBuilder()).build()) {
|
||||
System.out.println("Using Dapr client...");
|
||||
getConfigurations(client);
|
||||
subscribeConfigurationRequestWithSubscribe(client);
|
||||
|
|
@ -83,9 +83,9 @@ public class ConfigurationClient {
|
|||
/**
|
||||
* Gets configurations for a list of keys.
|
||||
*
|
||||
* @param client DaprPreviewClient object
|
||||
* @param client DaprClient object
|
||||
*/
|
||||
public static void getConfigurations(DaprPreviewClient client) {
|
||||
public static void getConfigurations(DaprClient client) {
|
||||
System.out.println("*******trying to retrieve configurations for a list of keys********");
|
||||
List<String> keys = new ArrayList<>();
|
||||
// ...
|
||||
|
|
@ -99,9 +99,9 @@ public class ConfigurationClient {
|
|||
/**
|
||||
* Subscribe to a list of keys.Optional to above iterator way of retrieving the changes
|
||||
*
|
||||
* @param client DaprPreviewClient object
|
||||
* @param client DaprClient object
|
||||
*/
|
||||
public static void subscribeConfigurationRequestWithSubscribe(DaprPreviewClient client) {
|
||||
public static void subscribeConfigurationRequestWithSubscribe(DaprClient client) {
|
||||
System.out.println("Subscribing to key: myconfig1");
|
||||
// ...
|
||||
Runnable subscribeTask = () -> {
|
||||
|
|
@ -114,9 +114,9 @@ public class ConfigurationClient {
|
|||
/**
|
||||
* Unsubscribe using subscription id.
|
||||
*
|
||||
* @param client DaprPreviewClient object
|
||||
* @param client DaprClient object
|
||||
*/
|
||||
public static void unsubscribeConfigurationItems(DaprPreviewClient client) {
|
||||
public static void unsubscribeConfigurationItems(DaprClient client) {
|
||||
System.out.println("Subscribing to key: myconfig2");
|
||||
// ..
|
||||
Runnable subscribeTask = () -> {
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ package io.dapr.examples.configuration.http;
|
|||
import io.dapr.client.DaprApiProtocol;
|
||||
import io.dapr.client.DaprClient;
|
||||
import io.dapr.client.DaprClientBuilder;
|
||||
import io.dapr.client.DaprPreviewClient;
|
||||
import io.dapr.client.domain.ConfigurationItem;
|
||||
import io.dapr.client.domain.GetConfigurationRequest;
|
||||
import io.dapr.client.domain.SubscribeConfigurationRequest;
|
||||
|
|
@ -53,7 +52,7 @@ public class ConfigurationClient {
|
|||
/**
|
||||
* Gets configurations for a list of keys.
|
||||
*
|
||||
* @param client DaprPreviewClient object
|
||||
* @param client DaprClient object
|
||||
*/
|
||||
public static void getConfigurations(DaprClient client) {
|
||||
System.out.println("*******trying to retrieve configurations for a list of keys********");
|
||||
|
|
@ -78,7 +77,7 @@ public class ConfigurationClient {
|
|||
/**
|
||||
* Subscribe to a list of keys.
|
||||
*
|
||||
* @param client DaprPreviewClient object
|
||||
* @param client DaprClient object
|
||||
*/
|
||||
public static void subscribeConfigurationRequest(DaprClient client) throws InterruptedException {
|
||||
System.out.println("Subscribing to key: myconfig2");
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
## Retrieve Configurations via Configuration API
|
||||
|
||||
This example provides the different capabilities provided by Dapr Java SDK for Configuration. For further information about Configuration APIs please refer to [this link](https://docs.dapr.io/developing-applications/building-blocks/configuration/)
|
||||
**This API is available in Preview Mode**.
|
||||
|
||||
### Using the ConfigurationAPI
|
||||
|
||||
|
|
@ -62,7 +61,7 @@ docker exec dapr_redis redis-cli MSET myconfig1 "val1||1" myconfig2 "val2||1" my
|
|||
|
||||
This example uses the Java SDK Dapr client in order to **Get, Subscribe and Unsubscribe** from configuration items and utilizes `Redis` as configuration store.
|
||||
`ConfigurationClient.java` is the example class demonstrating all 3 features.
|
||||
Kindly check [DaprPreviewClient.java](https://github.com/dapr/java-sdk/blob/master/sdk/src/main/java/io/dapr/client/DaprPreviewClient.java) for detailed description of the supported APIs.
|
||||
Check [DaprClient.java](https://github.com/dapr/java-sdk/blob/master/sdk/src/main/java/io/dapr/client/DaprClient.java) for detailed description of the supported APIs.
|
||||
|
||||
```java
|
||||
public class ConfigurationClient {
|
||||
|
|
@ -74,7 +73,7 @@ public class ConfigurationClient {
|
|||
*/
|
||||
public static void main(String[] args) throws Exception {
|
||||
System.getProperties().setProperty(Properties.API_PROTOCOL.getName(), DaprApiProtocol.HTTP.name());
|
||||
try (DaprPreviewClient client = (new DaprClientBuilder()).buildPreviewClient()) {
|
||||
try (DaprClient client = (new DaprClientBuilder()).build()) {
|
||||
System.out.println("Using Dapr client...");
|
||||
getConfigurations(client);
|
||||
subscribeConfigurationRequest(client);
|
||||
|
|
@ -84,9 +83,9 @@ public class ConfigurationClient {
|
|||
/**
|
||||
* Gets configurations for a list of keys.
|
||||
*
|
||||
* @param client DaprPreviewClient object
|
||||
* @param client DaprClient object
|
||||
*/
|
||||
public static void getConfigurations(DaprPreviewClient client) {
|
||||
public static void getConfigurations(DaprClient client) {
|
||||
System.out.println("*******trying to retrieve configurations for a list of keys********");
|
||||
GetConfigurationRequest req = new GetConfigurationRequest(CONFIG_STORE_NAME, keys);
|
||||
try {
|
||||
|
|
@ -100,9 +99,9 @@ public class ConfigurationClient {
|
|||
/**
|
||||
* Subscribe to a list of keys.
|
||||
*
|
||||
* @param client DaprPreviewClient object
|
||||
* @param client DaprClient object
|
||||
*/
|
||||
public static void subscribeConfigurationRequest(DaprPreviewClient client) {
|
||||
public static void subscribeConfigurationRequest(DaprClient client) {
|
||||
// ...
|
||||
SubscribeConfigurationRequest req = new SubscribeConfigurationRequest(
|
||||
CONFIG_STORE_NAME, Collections.singletonList("myconfig2"));
|
||||
|
|
|
|||
Loading…
Reference in New Issue