Skip to content

Commit 08889f5

Browse files
Merge pull request #220802 from cgillum/master
Updated Durable Functions Java samples and docs for GA release
2 parents 51d087c + c95eefe commit 08889f5

17 files changed

+507
-432
lines changed

articles/azure-functions/durable/durable-functions-bindings.md

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Bindings for Durable Functions - Azure
33
description: How to use triggers and bindings for the Durable Functions extension for Azure Functions.
44
ms.topic: conceptual
5-
ms.date: 05/27/2022
5+
ms.date: 12/07/2022
66
ms.author: azfuncdf
77
---
88

@@ -111,10 +111,8 @@ $input
111111
```java
112112
@FunctionName("HelloWorldOrchestration")
113113
public String helloWorldOrchestration(
114-
@DurableOrchestrationTrigger(name = "runtimeState") String runtimeState) {
115-
return OrchestrationRunner.loadAndRun(runtimeState, ctx -> {
116-
return String.format("Hello %s!", ctx.getInput(String.class));
117-
});
114+
@DurableOrchestrationTrigger(name = "ctx") TaskOrchestrationContext ctx) {
115+
return String.format("Hello %s!", ctx.getInput(String.class));
118116
}
119117
```
120118
---
@@ -179,12 +177,10 @@ $output
179177
```java
180178
@FunctionName("HelloWorld")
181179
public String helloWorldOrchestration(
182-
@DurableOrchestrationTrigger(name = "runtimeState") String runtimeState) {
183-
return OrchestrationRunner.loadAndRun(runtimeState, ctx -> {
184-
String input = ctx.getInput(String.class);
185-
String result = ctx.callActivity("SayHello", input, String.class).await();
186-
return result;
187-
});
180+
@DurableOrchestrationTrigger(name = "ctx") TaskOrchestrationContext ctx) {
181+
String input = ctx.getInput(String.class);
182+
String result = ctx.callActivity("SayHello", input, String.class).await();
183+
return result;
188184
}
189185
```
190186

articles/azure-functions/durable/durable-functions-custom-orchestration-status.md

Lines changed: 62 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Custom orchestration status in Durable Functions - Azure
33
description: Learn how to configure and use custom orchestration status for Durable Functions.
44
ms.topic: conceptual
5-
ms.date: 05/10/2021
5+
ms.date: 12/07/2022
66
ms.author: azfuncdf
77
ms.devlang: csharp, javascript, python
88
---
@@ -137,17 +137,15 @@ param($name)
137137
```java
138138
@FunctionName("HelloCities")
139139
public String helloCitiesOrchestrator(
140-
@DurableOrchestrationTrigger(name = "runtimeState") String runtimeState) {
141-
return OrchestrationRunner.loadAndRun(runtimeState, ctx -> {
142-
String result = "";
143-
result += ctx.callActivity("SayHello", "Tokyo", String.class).await() + ", ";
144-
ctx.setCustomStatus("Tokyo");
145-
result += ctx.callActivity("SayHello", "London", String.class).await() + ", ";
146-
ctx.setCustomStatus("London");
147-
result += ctx.callActivity("SayHello", "Seattle", String.class).await();
148-
ctx.setCustomStatus("Seattle");
149-
return result;
150-
});
140+
@DurableOrchestrationTrigger(name = "ctx") TaskOrchestrationContext ctx) {
141+
String result = "";
142+
result += ctx.callActivity("SayHello", "Tokyo", String.class).await() + ", ";
143+
ctx.setCustomStatus("Tokyo");
144+
result += ctx.callActivity("SayHello", "London", String.class).await() + ", ";
145+
ctx.setCustomStatus("London");
146+
result += ctx.callActivity("SayHello", "Seattle", String.class).await();
147+
ctx.setCustomStatus("Seattle");
148+
return result;
151149
}
152150

153151
@FunctionName("SayHello")
@@ -266,7 +264,13 @@ public HttpResponseMessage startHelloCities(
266264
String instanceId = client.scheduleNewOrchestrationInstance("HelloCities");
267265
context.getLogger().info("Created new Java orchestration with instance ID = " + instanceId);
268266

269-
OrchestrationMetadata metadata = client.waitForInstanceStart(instanceId, Duration.ofMinutes(5), true);
267+
OrchestrationMetadata metadata;
268+
try {
269+
metadata = client.waitForInstanceStart(instanceId, Duration.ofMinutes(5), true);
270+
} catch (TimeoutException ex) {
271+
return req.createResponseBuilder(HttpStatus.INTERNAL_SERVER_ERROR).build();
272+
}
273+
270274
while (metadata.readCustomStatusAs(String.class) != "London") {
271275
Thread.sleep(200);
272276
metadata = client.getInstanceMetadata(instanceId, true);
@@ -423,30 +427,28 @@ if ($userChoice -eq 3) {
423427

424428
```java
425429
@FunctionName("CityRecommender")
426-
public String cityRecommender(
427-
@DurableOrchestrationTrigger(name = "runtimeState") String runtimeState) {
428-
return OrchestrationRunner.loadAndRun(runtimeState, ctx -> {
429-
int userChoice = ctx.getInput(int.class);
430-
switch (userChoice) {
431-
case 1:
432-
ctx.setCustomStatus(new Recommendation(
433-
new String[]{ "Tokyo", "Seattle" },
434-
new String[]{ "Spring", "Summer" }));
435-
break;
436-
case 2:
437-
ctx.setCustomStatus(new Recommendation(
438-
new String[]{ "Seattle", "London" },
439-
new String[]{ "Summer" }));
440-
break;
441-
case 3:
442-
ctx.setCustomStatus(new Recommendation(
443-
new String[]{ "Tokyo", "London" },
444-
new String[]{ "Spring", "Summer" }));
445-
break;
446-
}
430+
public void cityRecommender(
431+
@DurableOrchestrationTrigger(name = "ctx") TaskOrchestrationContext ctx) {
432+
int userChoice = ctx.getInput(int.class);
433+
switch (userChoice) {
434+
case 1:
435+
ctx.setCustomStatus(new Recommendation(
436+
new String[]{ "Tokyo", "Seattle" },
437+
new String[]{ "Spring", "Summer" }));
438+
break;
439+
case 2:
440+
ctx.setCustomStatus(new Recommendation(
441+
new String[]{ "Seattle", "London" },
442+
new String[]{ "Summer" }));
443+
break;
444+
case 3:
445+
ctx.setCustomStatus(new Recommendation(
446+
new String[]{ "Tokyo", "London" },
447+
new String[]{ "Spring", "Summer" }));
448+
break;
449+
}
447450

448-
// Wait for user selection with an external event handler
449-
});
451+
// Wait for user selection with an external event
450452
}
451453

452454
class Recommendation {
@@ -578,22 +580,20 @@ return $isBookingConfirmed
578580

579581
```java
580582
@FunctionName("ReserveTicket")
581-
public String reserveTicket(
582-
@DurableOrchestrationTrigger(name = "runtimeState") String runtimeState) {
583-
return OrchestrationRunner.loadAndRun(runtimeState, ctx -> {
584-
String userID = ctx.getInput(String.class);
585-
int discount = ctx.callActivity("CalculateDiscount", userID, int.class).await();
586-
ctx.setCustomStatus(new DiscountInfo(discount, 60, "https://www.myawesomebookingweb.com"));
587-
588-
boolean isConfirmed = ctx.waitForExternalEvent("BookingConfirmed", boolean.class).await();
589-
if (isConfirmed) {
590-
ctx.setCustomStatus("Thank you for confirming your booking.");
591-
} else {
592-
ctx.setCustomStatus("There was a problem confirming your booking. Please try again.");
593-
}
583+
public boolean reserveTicket(
584+
@DurableOrchestrationTrigger(name = "ctx") TaskOrchestrationContext ctx) {
585+
String userID = ctx.getInput(String.class);
586+
int discount = ctx.callActivity("CalculateDiscount", userID, int.class).await();
587+
ctx.setCustomStatus(new DiscountInfo(discount, 60, "https://www.myawesomebookingweb.com"));
588+
589+
boolean isConfirmed = ctx.waitForExternalEvent("BookingConfirmed", boolean.class).await();
590+
if (isConfirmed) {
591+
ctx.setCustomStatus("Thank you for confirming your booking.");
592+
} else {
593+
ctx.setCustomStatus("There was a problem confirming your booking. Please try again.");
594+
}
594595

595-
return isConfirmed;
596-
});
596+
return isConfirmed;
597597
}
598598

599599
class DiscountInfo {
@@ -681,19 +681,17 @@ Set-DurableCustomStatus -CustomStatus @{ nextActions = @('A', 'B', 'C');
681681

682682
```java
683683
@FunctionName("MyCustomStatusOrchestrator")
684-
public String myCustomStatusOrchestrator(
685-
@DurableOrchestrationTrigger(name = "runtimeState") String runtimeState) {
686-
return OrchestrationRunner.loadAndRun(runtimeState, ctx -> {
687-
// ... do work ...
688-
689-
// update the status of the orchestration with some arbitrary data
690-
CustomStatusPayload payload = new CustomStatusPayload();
691-
payload.nextActions = new String[] { "A", "B", "C" };
692-
payload.foo = 2;
693-
ctx.setCustomStatus(payload);
694-
695-
// ... do more work ...
696-
});
684+
public void myCustomStatusOrchestrator(
685+
@DurableOrchestrationTrigger(name = "ctx") TaskOrchestrationContext ctx) {
686+
// ... do work ...
687+
688+
// update the status of the orchestration with some arbitrary data
689+
CustomStatusPayload payload = new CustomStatusPayload();
690+
payload.nextActions = new String[] { "A", "B", "C" };
691+
payload.foo = 2;
692+
ctx.setCustomStatus(payload);
693+
694+
// ... do more work ...
697695
}
698696

699697
class CustomStatusPayload {

articles/azure-functions/durable/durable-functions-diagnostics.md

Lines changed: 31 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Diagnostics in Durable Functions - Azure
33
description: Learn how to diagnose problems with the Durable Functions extension for Azure Functions.
44
author: cgillum
55
ms.topic: conceptual
6-
ms.date: 05/26/2022
6+
ms.date: 12/07/2022
77
ms.author: azfuncdf
88
ms.devlang: csharp, java, javascript, python
99
---
@@ -235,19 +235,17 @@ main = df.Orchestrator.create(orchestrator_function)
235235

236236
```java
237237
@FunctionName("FunctionChain")
238-
public String functionChain(
239-
@DurableOrchestrationTrigger(name = "runtimeState") String runtimeState,
238+
public void functionChain(
239+
@DurableOrchestrationTrigger(name = "ctx") TaskOrchestrationContext ctx,
240240
ExecutionContext functionContext) {
241-
return OrchestrationRunner.loadAndRun(runtimeState, ctx -> {
242-
Logger log = functionContext.getLogger();
243-
log.info("Calling F1.");
244-
ctx.callActivity("F1").await();
245-
log.info("Calling F2.");
246-
ctx.callActivity("F2").await();
247-
log.info("Calling F3.");
248-
ctx.callActivity("F3").await();
249-
log.info("Done!");
250-
});
241+
Logger log = functionContext.getLogger();
242+
log.info("Calling F1.");
243+
ctx.callActivity("F1").await();
244+
log.info("Calling F2.");
245+
ctx.callActivity("F2").await();
246+
log.info("Calling F3.");
247+
ctx.callActivity("F3").await();
248+
log.info("Done!");
251249
}
252250
```
253251

@@ -356,19 +354,17 @@ main = df.Orchestrator.create(orchestrator_function)
356354

357355
```java
358356
@FunctionName("FunctionChain")
359-
public String functionChain(
360-
@DurableOrchestrationTrigger(name = "runtimeState") String runtimeState,
357+
public void functionChain(
358+
@DurableOrchestrationTrigger(name = "ctx") TaskOrchestrationContext ctx,
361359
ExecutionContext functionContext) {
362-
return OrchestrationRunner.loadAndRun(runtimeState, ctx -> {
363-
Logger log = functionContext.getLogger();
364-
if (!ctx.getIsReplaying()) log.info("Calling F1.");
365-
ctx.callActivity("F1").await();
366-
if (!ctx.getIsReplaying()) log.info("Calling F2.");
367-
ctx.callActivity("F2").await();
368-
if (!ctx.getIsReplaying()) log.info("Calling F3.");
369-
ctx.callActivity("F3").await();
370-
log.info("Done!");
371-
});
360+
Logger log = functionContext.getLogger();
361+
if (!ctx.getIsReplaying()) log.info("Calling F1.");
362+
ctx.callActivity("F1").await();
363+
if (!ctx.getIsReplaying()) log.info("Calling F2.");
364+
ctx.callActivity("F2").await();
365+
if (!ctx.getIsReplaying()) log.info("Calling F3.");
366+
ctx.callActivity("F3").await();
367+
log.info("Done!");
372368
}
373369
```
374370

@@ -446,19 +442,17 @@ main = df.Orchestrator.create(orchestrator_function)
446442

447443
```java
448444
@FunctionName("SetStatusTest")
449-
public String setStatusTest(
450-
@DurableOrchestrationTrigger(name = "runtimeState") String runtimeState) {
451-
return OrchestrationRunner.loadAndRun(runtimeState, ctx -> {
452-
// ...do work...
453-
454-
// update the status of the orchestration with some arbitrary data
455-
ctx.setCustomStatus(new Object() {
456-
public final double completionPercentage = 90.0;
457-
public final String status = "Updating database records";
458-
});
459-
460-
// ...do more work...
445+
public void setStatusTest(
446+
@DurableOrchestrationTrigger(name = "ctx") TaskOrchestrationContext ctx) {
447+
// ...do work...
448+
449+
// update the status of the orchestration with some arbitrary data
450+
ctx.setCustomStatus(new Object() {
451+
public final double completionPercentage = 90.0;
452+
public final String status = "Updating database records";
461453
});
454+
455+
// ...do more work...
462456
}
463457
```
464458

0 commit comments

Comments
 (0)