mirror of https://github.com/dapr/quickstarts.git
Update Java Workflow sample
Signed-off-by: Marc Duiker <marcduiker@users.noreply.github.com>
This commit is contained in:
parent
9334142016
commit
4385e6f761
|
|
@ -206,8 +206,6 @@ dapr run -f .
|
|||
== APP - order-processor == Workflow Status: Completed
|
||||
```
|
||||
|
||||
|
||||
|
||||
### View workflow output with Zipkin
|
||||
|
||||
For a more detailed view of the workflow activities (duration, progress etc.), try using Zipkin.
|
||||
|
|
@ -224,14 +222,14 @@ docker run -d -p 9411:9411 openzipkin/zipkin
|
|||
|
||||
### What happened?
|
||||
|
||||
When you ran `dapr run -f .`
|
||||
When you ran `dapr run -f .`:
|
||||
|
||||
1. A unique order ID for the workflow is generated (in the above example, `898fd553`) and the workflow is scheduled.
|
||||
2. The `NotifyActivity` workflow activity sends a notification saying an order for 10 cars has been received.
|
||||
3. The `CheckInventoryActivity` workflow activity checks the inventory data, determines if you can supply the ordered item, and responds with the number of cars in stock. If the inventory is sufficient the workflow continues.
|
||||
2. The `NotifyActivity` workflow activity sends a notification saying an order for 1 car has been received.
|
||||
3. The `VerifyInventoryActivity` workflow activity checks the inventory data, determines if you can supply the ordered item, and responds with the number of cars in stock. If the inventory is sufficient the workflow continues.
|
||||
4. The total cost of the order is 5000, so the workflow will not call the `RequestApprovalActivity` activity.
|
||||
5. The `ProcessPaymentActivity` workflow activity begins processing payment for order `898fd553` and confirms if successful.
|
||||
6. The `UpdateInventoryActivity` workflow activity updates the inventory with the current available cars after the order has been processed.
|
||||
7. The `NotifyActivity` workflow activity sends a notification saying that order `898fd553` has completed.
|
||||
8. The workflow terminates as completed.
|
||||
8. The workflow terminates as completed and the OrderResult is set to processed.
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ internal sealed partial class RequestApprovalActivity(ILogger<RequestApprovalAct
|
|||
{
|
||||
LogRequestApproval(logger, approvalRequest);
|
||||
|
||||
// Simulate slow processing
|
||||
// Simulate slow processing & sending the approval to the recipient
|
||||
await Task.Delay(TimeSpan.FromSeconds(2));
|
||||
|
||||
return Task.FromResult<object?>(null);
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ internal sealed partial class OrderProcessingWorkflow : Workflow<OrderPayload, O
|
|||
new ApprovalRequest(orderId, order.Name, order.Quantity, order.TotalCost));
|
||||
|
||||
var approvalResponse = await context.WaitForExternalEventAsync<ApprovalResponse>(
|
||||
eventName: "ApprovalResponse",
|
||||
eventName: "ApprovalEvent",
|
||||
timeout: TimeSpan.FromSeconds(30));
|
||||
if (!approvalResponse.IsApproved)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
# Dapr workflows
|
||||
|
||||
In this quickstart, you'll create a simple console application to demonstrate Dapr's workflow programming model and the workflow management API. The console app starts and manages the lifecycle of a workflow that stores and retrieves data in a state store.
|
||||
In this quickstart, you'll run console application to demonstrate Dapr's workflow programming model and the workflow management API. The console app starts and manages the lifecycle of a workflow that stores and retrieves data in a state store.
|
||||
|
||||
This quickstart includes one project:
|
||||
|
||||
|
|
@ -9,7 +9,7 @@ This quickstart includes one project:
|
|||
The quickstart contains 1 workflow to simulate purchasing items from a store, and 5 unique activities within the workflow. These 5 activities are as follows:
|
||||
|
||||
- NotifyActivity: This activity utilizes a logger to print out messages throughout the workflow. These messages notify the user when there is insufficient inventory, their payment couldn't be processed, and more.
|
||||
- ReserveInventoryActivity: This activity checks the state store to ensure that there is enough inventory present for purchase.
|
||||
- VerifyInventoryActivity: This activity checks the state store to ensure that there is enough inventory present for purchase.
|
||||
- RequestApprovalActivity: This activity requests approval for orders over a certain threshold
|
||||
- ProcessPaymentActivity: This activity is responsible for processing and authorizing the payment.
|
||||
- UpdateInventoryActivity: This activity updates the state store with the new remaining inventory value.
|
||||
|
|
@ -34,7 +34,7 @@ cd ..
|
|||
<!-- STEP
|
||||
name: Run order-processor service
|
||||
expected_stdout_lines:
|
||||
- '== APP - order-processor == there are now 90 cars left in stock'
|
||||
- '== APP - order-processor == there are now 9 cars left in stock'
|
||||
- '== APP - order-processor == workflow instance completed, out is: {"processed":true}'
|
||||
expected_stderr_lines:
|
||||
output_match_mode: substring
|
||||
|
|
@ -55,29 +55,36 @@ dapr run -f .
|
|||
```
|
||||
== APP - order-processor == *** Welcome to the Dapr Workflow console app sample!
|
||||
== APP - order-processor == *** Using this app, you can place orders that start workflows.
|
||||
== APP - order-processor == [main] INFO io.dapr.workflows.runtime.WorkflowRuntimeBuilder - Registered Workflow: OrderProcessingWorkflow
|
||||
== APP - order-processor == [main] INFO io.dapr.workflows.runtime.WorkflowRuntimeBuilder - Registered Activity: NotifyActivity
|
||||
== APP - order-processor == [main] INFO io.dapr.workflows.runtime.WorkflowRuntimeBuilder - Registered Activity: ProcessPaymentActivity
|
||||
== APP - order-processor == [main] INFO io.dapr.workflows.runtime.WorkflowRuntimeBuilder - Registered Activity: RequestApprovalActivity
|
||||
== APP - order-processor == [main] INFO io.dapr.workflows.runtime.WorkflowRuntimeBuilder - Registered Activity: VerifyInventoryActivity
|
||||
== APP - order-processor == [main] INFO io.dapr.workflows.runtime.WorkflowRuntimeBuilder - Registered Activity: UpdateInventoryActivity
|
||||
== APP - order-processor == [main] INFO io.dapr.workflows.runtime.WorkflowRuntimeBuilder - List of registered workflows: [io.dapr.quickstarts.workflows.OrderProcessingWorkflow]
|
||||
== APP - order-processor == [main] INFO io.dapr.workflows.runtime.WorkflowRuntimeBuilder - List of registered activites: [io.dapr.quickstarts.workflows.activities.NotifyActivity, io.dapr.quickstarts.workflows.activities.UpdateInventoryActivity, io.dapr.quickstarts.workflows.activities.ProcessPaymentActivity, io.dapr.quickstarts.workflows.activities.RequestApprovalActivity, io.dapr.quickstarts.workflows.activities.VerifyInventoryActivity]
|
||||
== APP - order-processor == [main] INFO io.dapr.workflows.runtime.WorkflowRuntimeBuilder - Successfully built dapr workflow runtime
|
||||
== APP - order-processor == Start workflow runtime
|
||||
== APP - order-processor == Oct 06, 2023 3:10:01 PM com.microsoft.durabletask.DurableTaskGrpcWorker startAndBlock
|
||||
== APP - order-processor == INFO: Durable Task worker is connecting to sidecar at 127.0.0.1:50001.
|
||||
== APP - order-processor == Feb 12, 2025 2:44:13 PM com.microsoft.durabletask.DurableTaskGrpcWorker startAndBlock
|
||||
== APP - order-processor == INFO: Durable Task worker is connecting to sidecar at 127.0.0.1:39261.
|
||||
== APP - order-processor == ==========Begin the purchase of item:==========
|
||||
== APP - order-processor == Starting order workflow, purchasing 10 of cars
|
||||
== APP - order-processor == scheduled new workflow instance of OrderProcessingWorkflow with instance ID: 397faa44-1374-4f9d-a7fe-c74160604064
|
||||
== APP - order-processor == Starting order workflow, purchasing 1 of cars
|
||||
== APP - order-processor == scheduled new workflow instance of OrderProcessingWorkflow with instance ID: d1bf548b-c854-44af-978e-90c61ed88e3c
|
||||
== APP - order-processor == [Thread-0] INFO io.dapr.workflows.WorkflowContext - Starting Workflow: io.dapr.quickstarts.workflows.OrderProcessingWorkflow
|
||||
== APP - order-processor == [Thread-0] INFO io.dapr.workflows.WorkflowContext - Instance ID(order ID): 397faa44-1374-4f9d-a7fe-c74160604064
|
||||
== APP - order-processor == [Thread-0] INFO io.dapr.workflows.WorkflowContext - Current Orchestration Time: 2023-10-06T22:10:04.769Z
|
||||
== APP - order-processor == [Thread-0] INFO io.dapr.workflows.WorkflowContext - Received Order: OrderPayload [itemName=cars, totalCost=150000, quantity=10]
|
||||
== APP - order-processor == [Thread-0] INFO io.dapr.quickstarts.workflows.activities.NotifyActivity - Received Order: OrderPayload [itemName=cars, totalCost=150000, quantity=10]
|
||||
== APP - order-processor == workflow instance 397faa44-1374-4f9d-a7fe-c74160604064 started
|
||||
== APP - order-processor == [Thread-0] INFO io.dapr.quickstarts.workflows.activities.ReserveInventoryActivity - Reserving inventory for order '397faa44-1374-4f9d-a7fe-c74160604064' of 10 cars
|
||||
== APP - order-processor == [Thread-0] INFO io.dapr.quickstarts.workflows.activities.ReserveInventoryActivity - There are 100 cars available for purchase
|
||||
== APP - order-processor == [Thread-0] INFO io.dapr.quickstarts.workflows.activities.ReserveInventoryActivity - Reserved inventory for order '397faa44-1374-4f9d-a7fe-c74160604064' of 10 cars
|
||||
== APP - order-processor == [Thread-0] INFO io.dapr.quickstarts.workflows.activities.RequestApprovalActivity - Requesting approval for order: OrderPayload [itemName=cars, totalCost=150000, quantity=10]
|
||||
== APP - order-processor == [Thread-0] INFO io.dapr.quickstarts.workflows.activities.RequestApprovalActivity - Approved requesting approval for order: OrderPayload [itemName=cars, totalCost=150000, quantity=10]
|
||||
== APP - order-processor == [Thread-0] INFO io.dapr.quickstarts.workflows.activities.ProcessPaymentActivity - Processing payment: 397faa44-1374-4f9d-a7fe-c74160604064 for 10 cars at $150000
|
||||
== APP - order-processor == [Thread-0] INFO io.dapr.quickstarts.workflows.activities.ProcessPaymentActivity - Payment for request ID '397faa44-1374-4f9d-a7fe-c74160604064' processed successfully
|
||||
== APP - order-processor == [Thread-0] INFO io.dapr.quickstarts.workflows.activities.UpdateInventoryActivity - Updating inventory for order '397faa44-1374-4f9d-a7fe-c74160604064' of 10 cars
|
||||
== APP - order-processor == [Thread-0] INFO io.dapr.quickstarts.workflows.activities.UpdateInventoryActivity - Updated inventory for order '397faa44-1374-4f9d-a7fe-c74160604064': there are now 90 cars left in stock
|
||||
== APP - order-processor == there are now 90 cars left in stock
|
||||
== APP - order-processor == [Thread-0] INFO io.dapr.quickstarts.workflows.activities.NotifyActivity - Order completed! : 397faa44-1374-4f9d-a7fe-c74160604064
|
||||
== APP - order-processor == [Thread-0] INFO io.dapr.workflows.WorkflowContext - Instance ID(order ID): d1bf548b-c854-44af-978e-90c61ed88e3c
|
||||
== APP - order-processor == [Thread-0] INFO io.dapr.workflows.WorkflowContext - Current Orchestration Time: 2025-02-12T14:44:18.154Z
|
||||
== APP - order-processor == [Thread-0] INFO io.dapr.workflows.WorkflowContext - Received Order: OrderPayload [itemName=cars, totalCost=5000, quantity=1]
|
||||
== APP - order-processor == [Thread-0] INFO io.dapr.quickstarts.workflows.activities.NotifyActivity - Received Order: OrderPayload [itemName=cars, totalCost=5000, quantity=1]
|
||||
== APP - order-processor == workflow instance d1bf548b-c854-44af-978e-90c61ed88e3c started
|
||||
== APP - order-processor == [Thread-0] INFO io.dapr.quickstarts.workflows.activities.VerifyInventoryActivity - Verifying inventory for order 'd1bf548b-c854-44af-978e-90c61ed88e3c' of 1 cars
|
||||
== APP - order-processor == [Thread-0] INFO io.dapr.quickstarts.workflows.activities.VerifyInventoryActivity - There are 10 cars available for purchase
|
||||
== APP - order-processor == [Thread-0] INFO io.dapr.quickstarts.workflows.activities.VerifyInventoryActivity - Verified inventory for order 'd1bf548b-c854-44af-978e-90c61ed88e3c' of 1 cars
|
||||
== APP - order-processor == [Thread-0] INFO io.dapr.quickstarts.workflows.activities.ProcessPaymentActivity - Processing payment: d1bf548b-c854-44af-978e-90c61ed88e3c for 1 cars at $5000
|
||||
== APP - order-processor == [Thread-0] INFO io.dapr.quickstarts.workflows.activities.ProcessPaymentActivity - Payment for request ID 'd1bf548b-c854-44af-978e-90c61ed88e3c' processed successfully
|
||||
== APP - order-processor == [Thread-0] INFO io.dapr.quickstarts.workflows.activities.UpdateInventoryActivity - Updating inventory for order 'd1bf548b-c854-44af-978e-90c61ed88e3c' of 1 cars
|
||||
== APP - order-processor == [Thread-0] INFO io.dapr.quickstarts.workflows.activities.UpdateInventoryActivity - Updated inventory for order 'd1bf548b-c854-44af-978e-90c61ed88e3c': there are now 9 cars left in stock
|
||||
== APP - order-processor == there are now 9 cars left in stock
|
||||
== APP - order-processor == [Thread-0] INFO io.dapr.quickstarts.workflows.activities.NotifyActivity - Order completed! : d1bf548b-c854-44af-978e-90c61ed88e3c
|
||||
== APP - order-processor == workflow instance completed, out is: {"processed":true}
|
||||
```
|
||||
|
||||
|
|
@ -97,15 +104,13 @@ docker run -d -p 9411:9411 openzipkin/zipkin
|
|||
|
||||
### What happened?
|
||||
|
||||
When you ran `dapr run --app-id order-processor --resources-path ../../../components/ --dapr-grpc-port 50001 -- java -jar target/OrderProcessingService-0.0.1-SNAPSHOT.jar io.dapr.quickstarts.workflows.WorkflowConsoleApp`
|
||||
|
||||
1. A unique order ID for the workflow is generated (in the above example, `95d33f7c-3af8-4960-ba11-4ecea83b0509`) and the workflow is scheduled.
|
||||
2. The `NotifyActivity` workflow activity sends a notification saying an order for 10 cars has been received.
|
||||
3. The `ReserveInventoryActivity` workflow activity checks the inventory data, determines if you can supply the ordered item, and responds with the number of cars in stock.
|
||||
4. Your workflow starts and notifies you of its status.
|
||||
5. The `RequestApprovalActivity` workflow activity requests approval for order `95d33f7c-3af8-4960-ba11-4ecea83b0509`
|
||||
6. The `ProcessPaymentActivity` workflow activity begins processing payment for order `95d33f7c-3af8-4960-ba11-4ecea83b0509` and confirms if successful.
|
||||
7. The `UpdateInventoryActivity` workflow activity updates the inventory with the current available cars after the order has been processed.
|
||||
8. The `NotifyActivity` workflow activity sends a notification saying that order `95d33f7c-3af8-4960-ba11-4ecea83b0509` has completed and processed.
|
||||
9. The workflow terminates as completed and processed.
|
||||
When you ran `dapr run -f .`:
|
||||
|
||||
1. A unique order ID for the workflow is generated (in the above example, `d1bf548b-c854-44af-978e-90c61ed88e3c`) and the workflow is scheduled.
|
||||
2. The `NotifyActivity` workflow activity sends a notification saying an order for 1 car has been received.
|
||||
3. The `VertifyInventoryActivity` workflow activity checks the inventory data, determines if you can supply the ordered item, and responds with the number of cars in stock. If the inventory is sufficient the workflow continues.
|
||||
4. The total cost of the order is 5000, so the workflow will not call the `RequestApprovalActivity` activity.
|
||||
5. The `ProcessPaymentActivity` workflow activity begins processing payment for order `d1bf548b-c854-44af-978e-90c61ed88e3c` and confirms if successful.
|
||||
6. The `UpdateInventoryActivity` workflow activity updates the inventory with the current available cars after the order has been processed.
|
||||
7. The `NotifyActivity` workflow activity sends a notification saying that order `d1bf548b-c854-44af-978e-90c61ed88e3c` has completed.
|
||||
8. The workflow terminates as completed and the orderResult is set to processed.
|
||||
|
|
|
|||
|
|
@ -1,13 +1,14 @@
|
|||
package io.dapr.quickstarts.workflows;
|
||||
|
||||
import java.time.Duration;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import io.dapr.quickstarts.workflows.activities.NotifyActivity;
|
||||
import io.dapr.quickstarts.workflows.activities.ProcessPaymentActivity;
|
||||
import io.dapr.quickstarts.workflows.activities.RequestApprovalActivity;
|
||||
import io.dapr.quickstarts.workflows.activities.ReserveInventoryActivity;
|
||||
import io.dapr.quickstarts.workflows.activities.VerifyInventoryActivity;
|
||||
import io.dapr.quickstarts.workflows.activities.UpdateInventoryActivity;
|
||||
import io.dapr.quickstarts.workflows.models.ApprovalResult;
|
||||
import io.dapr.quickstarts.workflows.models.ApprovalResponse;
|
||||
import io.dapr.quickstarts.workflows.models.InventoryRequest;
|
||||
import io.dapr.quickstarts.workflows.models.InventoryResult;
|
||||
import io.dapr.quickstarts.workflows.models.Notification;
|
||||
|
|
@ -44,7 +45,7 @@ public class OrderProcessingWorkflow extends Workflow {
|
|||
inventoryRequest.setRequestId(orderId);
|
||||
inventoryRequest.setItemName(order.getItemName());
|
||||
inventoryRequest.setQuantity(order.getQuantity());
|
||||
InventoryResult inventoryResult = ctx.callActivity(ReserveInventoryActivity.class.getName(),
|
||||
InventoryResult inventoryResult = ctx.callActivity(VerifyInventoryActivity.class.getName(),
|
||||
inventoryRequest, InventoryResult.class).await();
|
||||
|
||||
// If there is insufficient inventory, fail and let the user know
|
||||
|
|
@ -57,9 +58,11 @@ public class OrderProcessingWorkflow extends Workflow {
|
|||
|
||||
// Require orders over a certain threshold to be approved
|
||||
if (order.getTotalCost() > 5000) {
|
||||
ApprovalResult approvalResult = ctx.callActivity(RequestApprovalActivity.class.getName(),
|
||||
order, ApprovalResult.class).await();
|
||||
if (approvalResult != ApprovalResult.Approved) {
|
||||
ctx.callActivity(RequestApprovalActivity.class.getName(), order).await();
|
||||
|
||||
ApprovalResponse approvalResponse = ctx.waitForExternalEvent("approvalEvent",
|
||||
Duration.ofSeconds(30), ApprovalResponse.class).await();
|
||||
if (!approvalResponse.isApproved()) {
|
||||
notification.setMessage("Order " + order.getItemName() + " was not approved.");
|
||||
ctx.callActivity(NotifyActivity.class.getName(), notification).await();
|
||||
ctx.complete(orderResult);
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ import io.dapr.client.DaprClientBuilder;
|
|||
import io.dapr.quickstarts.workflows.activities.NotifyActivity;
|
||||
import io.dapr.quickstarts.workflows.activities.ProcessPaymentActivity;
|
||||
import io.dapr.quickstarts.workflows.activities.RequestApprovalActivity;
|
||||
import io.dapr.quickstarts.workflows.activities.ReserveInventoryActivity;
|
||||
import io.dapr.quickstarts.workflows.activities.VerifyInventoryActivity;
|
||||
import io.dapr.quickstarts.workflows.activities.UpdateInventoryActivity;
|
||||
import io.dapr.quickstarts.workflows.models.InventoryItem;
|
||||
import io.dapr.quickstarts.workflows.models.OrderPayload;
|
||||
|
|
@ -51,7 +51,7 @@ public class WorkflowConsoleApp {
|
|||
builder.registerActivity(NotifyActivity.class);
|
||||
builder.registerActivity(ProcessPaymentActivity.class);
|
||||
builder.registerActivity(RequestApprovalActivity.class);
|
||||
builder.registerActivity(ReserveInventoryActivity.class);
|
||||
builder.registerActivity(VerifyInventoryActivity.class);
|
||||
builder.registerActivity(UpdateInventoryActivity.class);
|
||||
|
||||
// Build and then start the workflow runtime pulling and executing tasks
|
||||
|
|
@ -109,19 +109,19 @@ public class WorkflowConsoleApp {
|
|||
}
|
||||
|
||||
private static InventoryItem prepareInventoryAndOrder() {
|
||||
// prepare 100 cars in inventory
|
||||
// prepare 10 cars in inventory
|
||||
InventoryItem inventory = new InventoryItem();
|
||||
inventory.setName("cars");
|
||||
inventory.setPerItemCost(15000);
|
||||
inventory.setQuantity(100);
|
||||
inventory.setPerItemCost(50000);
|
||||
inventory.setQuantity(10);
|
||||
DaprClient daprClient = new DaprClientBuilder().build();
|
||||
restockInventory(daprClient, inventory);
|
||||
|
||||
// prepare order for 10 cars
|
||||
InventoryItem order = new InventoryItem();
|
||||
order.setName("cars");
|
||||
order.setPerItemCost(15000);
|
||||
order.setQuantity(10);
|
||||
order.setPerItemCost(5000);
|
||||
order.setQuantity(1);
|
||||
return order;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ package io.dapr.quickstarts.workflows.activities;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import io.dapr.quickstarts.workflows.models.ApprovalResult;
|
||||
import io.dapr.quickstarts.workflows.models.OrderPayload;
|
||||
import io.dapr.workflows.runtime.WorkflowActivity;
|
||||
import io.dapr.workflows.runtime.WorkflowActivityContext;
|
||||
|
|
@ -16,9 +15,13 @@ public class RequestApprovalActivity implements WorkflowActivity {
|
|||
OrderPayload order = ctx.getInput(OrderPayload.class);
|
||||
logger.info("Requesting approval for order: {}", order);
|
||||
|
||||
// hard code to Approved in example
|
||||
logger.info("Approved requesting approval for order: {}", order);
|
||||
return ApprovalResult.Approved;
|
||||
// Simulate slow processing & sending the approval to the recipient
|
||||
try {
|
||||
Thread.sleep(2 * 1000);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,21 +12,21 @@ import io.dapr.quickstarts.workflows.models.InventoryResult;
|
|||
import io.dapr.workflows.runtime.WorkflowActivity;
|
||||
import io.dapr.workflows.runtime.WorkflowActivityContext;
|
||||
|
||||
public class ReserveInventoryActivity implements WorkflowActivity {
|
||||
private static Logger logger = LoggerFactory.getLogger(ReserveInventoryActivity.class);
|
||||
public class VerifyInventoryActivity implements WorkflowActivity {
|
||||
private static Logger logger = LoggerFactory.getLogger(VerifyInventoryActivity.class);
|
||||
|
||||
private static final String STATE_STORE_NAME = "statestore";
|
||||
|
||||
private DaprClient daprClient;
|
||||
|
||||
public ReserveInventoryActivity() {
|
||||
public VerifyInventoryActivity() {
|
||||
this.daprClient = new DaprClientBuilder().build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object run(WorkflowActivityContext ctx) {
|
||||
InventoryRequest inventoryRequest = ctx.getInput(InventoryRequest.class);
|
||||
logger.info("Reserving inventory for order '{}' of {} {}",
|
||||
logger.info("Verifying inventory for order '{}' of {} {}",
|
||||
inventoryRequest.getRequestId(), inventoryRequest.getQuantity(), inventoryRequest.getItemName());
|
||||
|
||||
State<InventoryItem> inventoryState = daprClient.getState(STATE_STORE_NAME, inventoryRequest.getItemName(), InventoryItem.class).block();
|
||||
|
|
@ -42,7 +42,7 @@ public class ReserveInventoryActivity implements WorkflowActivity {
|
|||
Thread.sleep(2 * 1000);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
logger.info("Reserved inventory for order '{}' of {} {}",
|
||||
logger.info("Verified inventory for order '{}' of {} {}",
|
||||
inventoryRequest.getRequestId(), inventoryRequest.getQuantity(), inventoryRequest.getItemName());
|
||||
InventoryResult inventoryResult = new InventoryResult();
|
||||
inventoryResult.setSuccess(true);
|
||||
|
|
@ -51,7 +51,7 @@ public class ReserveInventoryActivity implements WorkflowActivity {
|
|||
}
|
||||
|
||||
// Not enough items.
|
||||
logger.info("Not enough items to reserve inventory for order '{}' of {} {}",
|
||||
logger.info("Not enough items in inventory for order '{}' of {} {}",
|
||||
inventoryRequest.getRequestId(), inventoryRequest.getQuantity(), inventoryRequest.getItemName());
|
||||
InventoryResult inventoryResult = new InventoryResult();
|
||||
inventoryResult.setSuccess(false);
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
package io.dapr.quickstarts.workflows.models;
|
||||
|
||||
public class ApprovalResponse {
|
||||
private boolean approved;
|
||||
|
||||
public boolean isApproved() {
|
||||
return approved;
|
||||
}
|
||||
|
||||
public void setIsApproved(boolean isApproved) {
|
||||
this.approved = isApproved;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ApprovalResponse [isApproved=" + approved + "]";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
package io.dapr.quickstarts.workflows.models;
|
||||
|
||||
public enum ApprovalResult {
|
||||
Unspecified,
|
||||
Approved,
|
||||
Rejected
|
||||
}
|
||||
Loading…
Reference in New Issue