Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Align Workflow support with Spring Boot idioms #1164

Open
salaboy opened this issue Dec 2, 2024 · 5 comments · May be fixed by #1170
Open

Align Workflow support with Spring Boot idioms #1164

salaboy opened this issue Dec 2, 2024 · 5 comments · May be fixed by #1170

Comments

@salaboy
Copy link
Contributor

salaboy commented Dec 2, 2024

Describe the proposal

We should enable a smooth Workflow authoring experience for Spring Boot developers.
Tools like Spring StateMachine, Temporal and Camunda Zeebe provide Spring Boot specific annotations for workflows/statemachines.

For reference:

In this proposal, I suggest creating a Workflow authoring and execution experience tailored to Spring Boot users. This should also be aligned with other SDKs like .Net and Go.
The main difference here, is that with Spring Boot we should aim for a higher level abstractions to provide an experience that is aligned with Spring Boot concepts and ways of working, which is not at the same level as the current Workflow APIs that provide access directly to Dapr Workflow features.

I would suggest going in a similar route as Temporal Spring Boot Integration where the workflow authoring experience provides the use the possibility to define their own business interfaces (as Spring Beans) that will be used by application developers to interact with workflow functionalities. For example:

@WorkflowInterface
public interface OrderFulfillmentWorkflow {
  @WorkflowMethod
  void createOrder(OrderDTO orderDTO);
}

This defines a Spring Bean that has business meaning. This can be injected in any Spring boot application and it defines semantically what the workflow will be doing. Inside @WorkflowMethods activities can be sequenced, hiding the complexity of workflow mechanisms.

WorkflowActivities can be also masked, as this way of calling an activity:

ctx.callActivity(PlaceOrderToKitchen.class.getName(), workflowPayload).await();

Is very odd for a spring boot user.

What I would like to do as a spring boot user is the following:

...
@Autowired
private WorkflowActivity placeOrderToKitchen;
@Autowired
private WorkflowActivity deliverOrderToCustomer; 
...
public void placePizzaOrder(Order order){
  boolean orderOk = placeOrderToKitchen.call(order, Boolean.class).wait(); // where we specify the input and output

  if( orderOk ) {
      DeliveryId id = deliverOrderToCustomer.call(order, DeliveryId.class).wait(5, Duration.Minutes);
      // If timeout send notification to customer.. 
  } else{
     // validate order and resubmit.. 
  }
  
}


@salaboy
Copy link
Contributor Author

salaboy commented Dec 5, 2024

Some TODO List related to this proposal:

  • Support DaprWorkflowClient injection / autoconfig in Spring Boot
  • Provide discovery + automatic building of workflows with @EnableDaprWorkflows (collapse WorkflowRuntimeBuilder().registerWorkflow(...) + builder.registerActivity(...) + WorkflowRuntime runtime = builder.build() at application start time)
  • Make WorkflowActivity proper managed beans, so we can inject them and inject stuff inside them.. this would be a major improvement.
  • Hide workflowClient.scheduleNewWorkflow(..., payload) behind a business interface ala Temporal WorkflowInterface + WorkflowMethod

The first two tasks would make a difference on the current experience with Spring Boot, the last two will provide a solid programming model to align with other aspects on Spring Boot, such as managing and exposing Workflows via sync and async APIs.

@salaboy
Copy link
Contributor Author

salaboy commented Dec 6, 2024

@jakesmolka I am curious about your feedback here.. I think I am will do the first two points and try to merge that into main so we can give it a try.

@jakesmolka
Copy link

Cool, this sounds great! Personally, what I was missing most was the ability to inject outer deps into the activity's business code. For instance, working with a shared internal context or client. But I stopped exploring workflows in the SDK further, when I found out it was not working yet.
This seems to be covered by your third point.

I'll watch this space and try to play around with your changes, once they are ready.

@salaboy
Copy link
Contributor Author

salaboy commented Dec 6, 2024 via email

@salaboy
Copy link
Contributor Author

salaboy commented Dec 12, 2024

@jakesmolka the PR now has the test with the beans checking with @RestTemplate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants