mirror of https://github.com/dapr/docs.git
add java to features doc
Signed-off-by: Hannah Hunter <hannahhunter@microsoft.com>
This commit is contained in:
parent
377c28a9ef
commit
1ce09dfecb
|
@ -162,7 +162,7 @@ APIs that generate random numbers, random UUIDs, or the current date are _non-de
|
|||
|
||||
For example, instead of this:
|
||||
|
||||
{{< tabs ".NET" >}}
|
||||
{{< tabs ".NET" Java >}}
|
||||
|
||||
{{% codetab %}}
|
||||
|
||||
|
@ -175,11 +175,22 @@ string randomString = GetRandomString();
|
|||
|
||||
{{% /codetab %}}
|
||||
|
||||
{{% codetab %}}
|
||||
|
||||
```java
|
||||
// DON'T DO THIS!
|
||||
Instant currentTime = Instant.now();
|
||||
UUID newIdentifier = UUID.randomUUID();
|
||||
string randomString = GetRandomString();
|
||||
```
|
||||
|
||||
{{% /codetab %}}
|
||||
|
||||
{{< /tabs >}}
|
||||
|
||||
Do this:
|
||||
|
||||
{{< tabs ".NET" >}}
|
||||
{{< tabs ".NET" Java >}}
|
||||
|
||||
{{% codetab %}}
|
||||
|
||||
|
@ -192,6 +203,17 @@ string randomString = await context.CallActivityAsync<string>("GetRandomString")
|
|||
|
||||
{{% /codetab %}}
|
||||
|
||||
{{% codetab %}}
|
||||
|
||||
```java
|
||||
// Do this!!
|
||||
Instant currentTime = context.getCurrentInstant();
|
||||
Guid newIdentifier = context.NewGuid();
|
||||
String randomString = context.callActivity(GetRandomString.class.getName(), String.class).await();
|
||||
```
|
||||
|
||||
{{% /codetab %}}
|
||||
|
||||
{{< /tabs >}}
|
||||
|
||||
|
||||
|
@ -202,20 +224,58 @@ Instead, workflows should interact with external state _indirectly_ using workfl
|
|||
|
||||
For example, instead of this:
|
||||
|
||||
{{< tabs ".NET" Java >}}
|
||||
|
||||
{{% codetab %}}
|
||||
|
||||
```csharp
|
||||
// DON'T DO THIS!
|
||||
string configuration = Environment.GetEnvironmentVariable("MY_CONFIGURATION")!;
|
||||
string data = await new HttpClient().GetStringAsync("https://example.com/api/data");
|
||||
```
|
||||
{{% /codetab %}}
|
||||
|
||||
{{% codetab %}}
|
||||
|
||||
```java
|
||||
// DON'T DO THIS!
|
||||
String configuration = System.getenv("MY_CONFIGURATION");
|
||||
|
||||
HttpRequest request = HttpRequest.newBuilder().uri(new URI("https://postman-echo.com/post")).GET().build();
|
||||
HttpResponse<String> response = HttpClient.newBuilder().build().send(request, HttpResponse.BodyHandlers.ofString());
|
||||
```
|
||||
|
||||
{{% /codetab %}}
|
||||
|
||||
{{< /tabs >}}
|
||||
|
||||
Do this:
|
||||
|
||||
{{< tabs ".NET" Java >}}
|
||||
|
||||
{{% codetab %}}
|
||||
|
||||
```csharp
|
||||
// Do this!!
|
||||
string configuation = workflowInput.Configuration; // imaginary workflow input argument
|
||||
string data = await context.CallActivityAsync<string>("MakeHttpCall", "https://example.com/api/data");
|
||||
```
|
||||
|
||||
{{% /codetab %}}
|
||||
|
||||
{{% codetab %}}
|
||||
|
||||
```java
|
||||
// Do this!!
|
||||
String configuation = ctx.getInput(InputType.class).getConfiguration(); // imaginary workflow input argument
|
||||
String data = ctx.callActivity(MakeHttpCall.class, "https://example.com/api/data", String.class).await();
|
||||
```
|
||||
|
||||
{{% /codetab %}}
|
||||
|
||||
{{< /tabs >}}
|
||||
|
||||
|
||||
#### Workflow functions must execute only on the workflow dispatch thread.
|
||||
The implementation of each language SDK requires that all workflow function operations operate on the same thread (goroutine, etc.) that the function was scheduled on. Workflow functions must never:
|
||||
- Schedule background threads, or
|
||||
|
@ -225,20 +285,58 @@ Failure to follow this rule could result in undefined behavior. Any background p
|
|||
|
||||
For example, instead of this:
|
||||
|
||||
{{< tabs ".NET" Java >}}
|
||||
|
||||
{{% codetab %}}
|
||||
|
||||
```csharp
|
||||
// DON'T DO THIS!
|
||||
Task t = Task.Run(() => context.CallActivityAsync("DoSomething"));
|
||||
await context.CreateTimer(5000).ConfigureAwait(false);
|
||||
```
|
||||
{{% /codetab %}}
|
||||
|
||||
{{% codetab %}}
|
||||
|
||||
```java
|
||||
// DON'T DO THIS!
|
||||
new Thread(() -> {
|
||||
ctx.callActivity(DoSomethingActivity.class.getName()).await();
|
||||
}).start();
|
||||
ctx.createTimer(Duration.ofSeconds(5)).await();
|
||||
```
|
||||
|
||||
{{% /codetab %}}
|
||||
|
||||
{{< /tabs >}}
|
||||
|
||||
Do this:
|
||||
|
||||
{{< tabs ".NET" Java >}}
|
||||
|
||||
{{% codetab %}}
|
||||
|
||||
```csharp
|
||||
// Do this!!
|
||||
Task t = context.CallActivityAsync("DoSomething");
|
||||
await context.CreateTimer(5000).ConfigureAwait(true);
|
||||
```
|
||||
|
||||
{{% /codetab %}}
|
||||
|
||||
{{% codetab %}}
|
||||
|
||||
```java
|
||||
// Do this!!
|
||||
ctx.callActivity(DoSomethingActivity.class.getName()).await();
|
||||
ctx.createTimer(Duration.ofSeconds(5)).await();
|
||||
```
|
||||
|
||||
{{% /codetab %}}
|
||||
|
||||
{{< /tabs >}}
|
||||
|
||||
|
||||
### Updating workflow code
|
||||
|
||||
Make sure updates you make to the workflow code maintain its determinism. A couple examples of code updates that can break workflow determinism:
|
||||
|
|
Loading…
Reference in New Issue