Skip to content

Commit 93caec4

Browse files
committed
update doc with correct command and java items; add dashboard images for python and java
Signed-off-by: Hannah Hunter <[email protected]>
1 parent 3174ad3 commit 93caec4

File tree

4 files changed

+92
-64
lines changed

4 files changed

+92
-64
lines changed
Loading
Loading
Loading

articles/azure-functions/durable-task-scheduler/quickstart-portable-durable-task-sdks.md

Lines changed: 92 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ Since the example code automatically uses the default emulator settings, you don
113113
1. Run the emulator. The container may take a few seconds to be ready.
114114
115115
```bash
116-
docker run --name dtsemulator -d -p 8080:8080 mcr.microsoft.com/dts/dts-emulator:v0.0.6
116+
docker run --name dtsemulator -d -p 8080:8080 -p 8082:8082 mcr.microsoft.com/dts/dts-emulator:v0.0.6
117117
```
118118
119119
Since the example code automatically uses the default emulator settings, you don't need to set any environment variables.
@@ -139,7 +139,7 @@ Since the example code automatically uses the default emulator settings, you don
139139
1. Run the emulator. The container may take a few seconds to be ready.
140140

141141
```bash
142-
docker run --name dtsemulator -d -p 8080:8080 mcr.microsoft.com/dts/dts-emulator:v0.0.6
142+
docker run --name dtsemulator -d -p 8080:8080 -p 8082:8082 mcr.microsoft.com/dts/dts-emulator:v0.0.6
143143
```
144144

145145
Since the example code automatically uses the default emulator settings, you don't need to set any environment variables.
@@ -331,58 +331,31 @@ Orchestration completed with status: COMPLETED
331331
332332
::: zone pivot="java"
333333
334-
1. Install the required packages.
335-
336-
```bash
337-
338-
```
339-
340-
1. Start the worker.
341-
342-
```bash
343-
344-
```
345-
346-
1. In a new terminal, run the client.
347-
348-
```bash
349-
350-
```
351-
352-
You can provide the number of work items as an argument. If no argument is provided, the example runs 10 items by default.
334+
From the `fan-out-fan-in` directory, build and run the application using Gradle.
353335
354-
```bash
355-
356-
```
336+
```bash
337+
./gradlew runFanOutFanInPattern
338+
```
357339

358340
### Understanding the output
359341

360-
When you run this sample, you receive output from both the worker and client processes.
361-
362-
#### Worker output
363-
364-
The worker output shows:
342+
When you run this sample, you receive output that shows:
365343

366344
- Registration of the orchestrator and activities.
367345
- Status messages when processing each work item in parallel, showing that they're executing concurrently.
368346
- Random delays for each work item (between 0.5 and 2 seconds) to simulate varying processing times.
369347
- A final message showing the aggregation of results.
370348

371-
#### Client output
372-
373-
The client output shows:
374-
375-
- Starting the orchestration with the specified number of work items.
376-
- The unique orchestration instance ID.
377-
- The final aggregated result, which includes:
378-
- Total number of items processed
379-
- Sum of all results (each item result is the square of its value)
380-
- Average of all results
381-
382349
#### Example output
383350

384351
```
352+
Starting a Gradle Daemon (subsequent builds will be faster)
385353
354+
> Task :runFanOutFanInPattern
355+
Durable Task worker is connecting to sidecar at localhost:8080.
356+
Started new orchestration instance
357+
Orchestration completed: [Name: 'FanOutFanIn_WordCount', ID: '<id-number>', RuntimeStatus: COMPLETED, CreatedAt: 2025-04-25T15:24:47.170Z, LastUpdatedAt: 2025-04-25T15:24:47.287Z, Input: '["Hello, world!","The quick brown fox jumps over t...', Output: '60']
358+
Output: 60
386359
```
387360

388361
::: zone-end
@@ -406,7 +379,19 @@ You can view the orchestration status and history via the [Durable Task Schedule
406379

407380
::: zone pivot="csharp"
408381

409-
:::image type="content" source="media/quickstart-portable-durable-task-sdks/review-dashboard.png" alt-text="Screenshot showing the orchestartion instance's details.":::
382+
:::image type="content" source="media/quickstart-portable-durable-task-sdks/review-dashboard-dotnet.png" alt-text="Screenshot showing the orchestartion instance's details for the .NET sample.":::
383+
384+
::: zone-end
385+
386+
::: zone pivot="python"
387+
388+
:::image type="content" source="media/quickstart-portable-durable-task-sdks/review-dashboard-python.png" alt-text="Screenshot showing the orchestartion instance's details for the Python sample.":::
389+
390+
::: zone-end
391+
392+
::: zone pivot="java"
393+
394+
:::image type="content" source="media/quickstart-portable-durable-task-sdks/review-dashboard-java.png" alt-text="Screenshot showing the orchestartion instance's details for the Java sample.":::
410395

411396
::: zone-end
412397

@@ -603,9 +588,7 @@ result = client.wait_for_orchestration_completion(
603588

604589
::: zone pivot="java"
605590

606-
### Worker
607-
608-
To demonstrate [the fan-out/fan-in pattern](../durable/durable-functions-overview.md#fan-in-out), the worker project orchestration creates parallel activity tasks and waits for all to complete. The orchestrator:
591+
To demonstrate [the fan-out/fan-in pattern](../durable/durable-functions-overview.md#fan-in-out), the `FanOutFanInPattern` project orchestration creates parallel activity tasks and waits for all to complete. The orchestrator:
609592

610593
1. Takes a list of work items as input.
611594
1. Fans out by creating a separate task for each work item using ``.
@@ -614,42 +597,87 @@ To demonstrate [the fan-out/fan-in pattern](../durable/durable-functions-overvie
614597
1. Fans in by aggregating all individual results using ``.
615598
1. Returns the final aggregated result to the client.
616599

617-
Using fan-out/fan-in, the orchestration creates parallel activity tasks and waits for all to complete.
618-
619-
```java
620-
621-
```
600+
The project contains:
622601

623-
#### Client
602+
- **`DurableTaskSchedulerWorkerExtensions` worker**: Defines the orchestrator and activity functions.
603+
- **`DurableTaskSchedulerClientExtension` client**: Sets up the worker host with proper connection string handling.
624604

625-
The worker uses `Microsoft.Extensions.Hosting` for proper lifecycle management.
605+
### Worker
626606

627-
```csharp
628-
using Microsoft.Extensions.Hosting;
629-
//..
607+
Using fan-out/fan-in, the orchestration creates parallel activity tasks and waits for all to complete.
630608

631-
builder.Services.AddDurableTaskWorker()
632-
.AddTasks(registry =>
633-
{
634-
registry.AddOrchestrator<ParallelProcessingOrchestration>();
635-
registry.AddActivity<ProcessWorkItemActivity>();
636-
registry.AddActivity<AggregateResultsActivity>();
609+
```java
610+
DurableTaskGrpcWorker worker = DurableTaskSchedulerWorkerExtensions.createWorkerBuilder(connectionString)
611+
.addOrchestration(new TaskOrchestrationFactory() {
612+
@Override
613+
public String getName() { return "FanOutFanIn_WordCount"; }
614+
615+
@Override
616+
public TaskOrchestration create() {
617+
return ctx -> {
618+
List<?> inputs = ctx.getInput(List.class);
619+
List<Task<Integer>> tasks = inputs.stream()
620+
.map(input -> ctx.callActivity("CountWords", input.toString(), Integer.class))
621+
.collect(Collectors.toList());
622+
List<Integer> allWordCountResults = ctx.allOf(tasks).await();
623+
int totalWordCount = allWordCountResults.stream().mapToInt(Integer::intValue).sum();
624+
ctx.complete(totalWordCount);
625+
};
626+
}
637627
})
638-
.UseDurableTaskScheduler(connectionString);
628+
.addActivity(new TaskActivityFactory() {
629+
@Override
630+
public String getName() { return "CountWords"; }
631+
632+
@Override
633+
public TaskActivity create() {
634+
return ctx -> {
635+
String input = ctx.getInput(String.class);
636+
StringTokenizer tokenizer = new StringTokenizer(input);
637+
return tokenizer.countTokens();
638+
};
639+
}
640+
})
641+
.build();
642+
643+
// Start the worker
644+
worker.start();
639645
```
640646

641-
### The client project
647+
### Client
642648

643649
The client project:
644650

645651
- Uses the same connection string logic as the worker.
646652
- Creates a list of work items to be processed in parallel.
647653
- Schedules an orchestration instance with the list as input.
648654
- Waits for the orchestration to complete and displays the aggregated results.
649-
- Uses `` for efficient polling.
655+
- Uses `waitForInstanceCompletion` for efficient polling.
650656

651657
```java
652-
658+
DurableTaskClient client = DurableTaskSchedulerClientExtensions.createClientBuilder(connectionString).build();
659+
660+
// The input is an arbitrary list of strings.
661+
List<String> listOfStrings = Arrays.asList(
662+
"Hello, world!",
663+
"The quick brown fox jumps over the lazy dog.",
664+
"If a tree falls in the forest and there is no one there to hear it, does it make a sound?",
665+
"The greatest glory in living lies not in never falling, but in rising every time we fall.",
666+
"Always remember that you are absolutely unique. Just like everyone else.");
667+
668+
// Schedule an orchestration which will reliably count the number of words in all the given sentences.
669+
String instanceId = client.scheduleNewOrchestrationInstance(
670+
"FanOutFanIn_WordCount",
671+
new NewOrchestrationInstanceOptions().setInput(listOfStrings));
672+
logger.info("Started new orchestration instance: {}", instanceId);
673+
674+
// Block until the orchestration completes. Then print the final status, which includes the output.
675+
OrchestrationMetadata completedInstance = client.waitForInstanceCompletion(
676+
instanceId,
677+
Duration.ofSeconds(30),
678+
true);
679+
logger.info("Orchestration completed: {}", completedInstance);
680+
logger.info("Output: {}", completedInstance.readOutputAs(int.class));
653681
```
654682

655683
::: zone-end

0 commit comments

Comments
 (0)