Skip to content

Commit 02f92ea

Browse files
committed
save
1 parent aa94d9c commit 02f92ea

File tree

3 files changed

+74
-47
lines changed

3 files changed

+74
-47
lines changed

azuremanaged/client/build.gradle

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ version = '1.5.0'
1919
archivesBaseName = 'durabletask-azuremanaged-client'
2020

2121
def grpcVersion = '1.59.0'
22-
def protocVersion = '3.12.0'
23-
def jacksonVersion = '2.15.3'
2422
def azureCoreVersion = '1.45.0'
2523
def azureIdentityVersion = '1.11.1'
2624
def durabletaskClientVersion = '1.5.0'

azuremanaged/worker/build.gradle

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ version = '1.5.0'
1919
archivesBaseName = 'durabletask-azuremanaged-worker'
2020

2121
def grpcVersion = '1.59.0'
22-
def protocVersion = '3.12.0'
23-
def jacksonVersion = '2.15.3'
2422
def azureCoreVersion = '1.45.0'
2523
def azureIdentityVersion = '1.11.1'
2624
def durabletaskClientVersion = '1.5.0'

samples/src/main/java/io/durabletask/samples/WebAppToDurableTaskSchedulerSample.java

Lines changed: 74 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44

55
import com.azure.core.credential.TokenCredential;
66
import com.microsoft.durabletask.*;
7-
8-
import com.microsoft.durabletask.client.azuremanaged.DurableTaskSchedulerClientExtensions;
9-
import com.microsoft.durabletask.worker.azuremanaged.DurableTaskSchedulerWorkerExtensions;
7+
import com.microsoft.durabletask.azuremanaged.client.DurableTaskSchedulerClientExtensions;
8+
import com.microsoft.durabletask.azuremanaged.worker.DurableTaskSchedulerWorkerExtensions;
109
import org.springframework.boot.SpringApplication;
1110
import org.springframework.boot.autoconfigure.SpringBootApplication;
1211
import org.springframework.web.bind.annotation.*;
@@ -65,53 +64,85 @@ public DurableTaskGrpcWorker durableTaskWorker(
6564
properties.getTaskHubName(),
6665
tokenCredential);
6766

68-
// Add orchestrations
69-
workerBuilder.addOrchestration("ProcessOrderOrchestration", ctx -> {
70-
// Get the order input as JSON string
71-
String orderJson = ctx.getInput(String.class);
72-
73-
// Process the order through multiple activities
74-
boolean isValid = ctx.callActivity("ValidateOrder", orderJson, Boolean.class).await();
75-
if (!isValid) {
76-
ctx.complete("{\"status\": \"FAILED\", \"message\": \"Order validation failed\"}");
77-
return;
78-
}
79-
80-
// Process payment
81-
String paymentResult = ctx.callActivity("ProcessPayment", orderJson, String.class).await();
82-
if (!paymentResult.contains("\"success\":true")) {
83-
ctx.complete("{\"status\": \"FAILED\", \"message\": \"Payment processing failed\"}");
84-
return;
67+
// Add orchestrations using the factory pattern
68+
workerBuilder.addOrchestration(new TaskOrchestrationFactory() {
69+
@Override
70+
public String getName() { return "ProcessOrderOrchestration"; }
71+
72+
@Override
73+
public TaskOrchestration create() {
74+
return ctx -> {
75+
// Get the order input as JSON string
76+
String orderJson = ctx.getInput(String.class);
77+
78+
// Process the order through multiple activities
79+
boolean isValid = ctx.callActivity("ValidateOrder", orderJson, Boolean.class).await();
80+
if (!isValid) {
81+
ctx.complete("{\"status\": \"FAILED\", \"message\": \"Order validation failed\"}");
82+
return;
83+
}
84+
85+
// Process payment
86+
String paymentResult = ctx.callActivity("ProcessPayment", orderJson, String.class).await();
87+
if (!paymentResult.contains("\"success\":true")) {
88+
ctx.complete("{\"status\": \"FAILED\", \"message\": \"Payment processing failed\"}");
89+
return;
90+
}
91+
92+
// Ship order
93+
String shipmentResult = ctx.callActivity("ShipOrder", orderJson, String.class).await();
94+
95+
// Return the final result
96+
ctx.complete("{\"status\": \"SUCCESS\", " +
97+
"\"payment\": " + paymentResult + ", " +
98+
"\"shipment\": " + shipmentResult + "}");
99+
};
85100
}
86-
87-
// Ship order
88-
String shipmentResult = ctx.callActivity("ShipOrder", orderJson, String.class).await();
89-
90-
// Return the final result
91-
ctx.complete("{\"status\": \"SUCCESS\", " +
92-
"\"payment\": " + paymentResult + ", " +
93-
"\"shipment\": " + shipmentResult + "}");
94101
});
95102

96-
// Add activity implementations
97-
workerBuilder.addActivity("ValidateOrder", ctx -> {
98-
String orderJson = ctx.getInput(String.class);
99-
// Simple validation - check if order contains amount and it's greater than 0
100-
return orderJson.contains("\"amount\"") && !orderJson.contains("\"amount\":0");
103+
// Add activities using the factory pattern
104+
workerBuilder.addActivity(new TaskActivityFactory() {
105+
@Override
106+
public String getName() { return "ValidateOrder"; }
107+
108+
@Override
109+
public TaskActivity create() {
110+
return ctx -> {
111+
String orderJson = ctx.getInput(String.class);
112+
// Simple validation - check if order contains amount and it's greater than 0
113+
return orderJson.contains("\"amount\"") && !orderJson.contains("\"amount\":0");
114+
};
115+
}
101116
});
102117

103-
workerBuilder.addActivity("ProcessPayment", ctx -> {
104-
String orderJson = ctx.getInput(String.class);
105-
// Simulate payment processing
106-
sleep(1000); // Simulate processing time
107-
return "{\"success\":true, \"transactionId\":\"TXN" + System.currentTimeMillis() + "\"}";
118+
workerBuilder.addActivity(new TaskActivityFactory() {
119+
@Override
120+
public String getName() { return "ProcessPayment"; }
121+
122+
@Override
123+
public TaskActivity create() {
124+
return ctx -> {
125+
String orderJson = ctx.getInput(String.class);
126+
// Simulate payment processing
127+
sleep(1000); // Simulate processing time
128+
return "{\"success\":true, \"transactionId\":\"TXN" + System.currentTimeMillis() + "\"}";
129+
};
130+
}
108131
});
109132

110-
workerBuilder.addActivity("ShipOrder", ctx -> {
111-
String orderJson = ctx.getInput(String.class);
112-
// Simulate shipping process
113-
sleep(1000); // Simulate processing time
114-
return "{\"trackingNumber\":\"TRACK" + System.currentTimeMillis() + "\"}";
133+
workerBuilder.addActivity(new TaskActivityFactory() {
134+
@Override
135+
public String getName() { return "ShipOrder"; }
136+
137+
@Override
138+
public TaskActivity create() {
139+
return ctx -> {
140+
String orderJson = ctx.getInput(String.class);
141+
// Simulate shipping process
142+
sleep(1000); // Simulate processing time
143+
return "{\"trackingNumber\":\"TRACK" + System.currentTimeMillis() + "\"}";
144+
};
145+
}
115146
});
116147

117148
return workerBuilder.build();

0 commit comments

Comments
 (0)