-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial @EnableDaprWorkflows implementation
Signed-off-by: salaboy <[email protected]>
- Loading branch information
Showing
8 changed files
with
153 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...rc/test/java/io/dapr/spring/boot/autoconfigure/client/DaprWorkflowsRegistrationTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package io.dapr.spring.boot.autoconfigure.client; | ||
|
||
import io.dapr.spring.boot.autoconfigure.client.workflows.TestActivity; | ||
import io.dapr.spring.boot.autoconfigure.client.workflows.TestWorkflow; | ||
import io.dapr.workflows.client.DaprWorkflowClient; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
@SpringBootTest(classes = {WorkflowTestApplication.class, DaprClientAutoConfiguration.class, TestActivity.class, TestWorkflow.class}) | ||
public class DaprWorkflowsRegistrationTests { | ||
|
||
@Autowired | ||
private DaprWorkflowClient daprWorkflowClient; | ||
|
||
@Test | ||
public void doThat(){ | ||
assertNotNull(daprWorkflowClient); | ||
|
||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...igure/src/test/java/io/dapr/spring/boot/autoconfigure/client/WorkflowTestApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package io.dapr.spring.boot.autoconfigure.client; | ||
|
||
import io.dapr.spring.workflows.config.EnableDaprWorkflows; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
@EnableDaprWorkflows | ||
public class WorkflowTestApplication { | ||
public static void main(String[] args) { | ||
SpringApplication.run(WorkflowTestApplication.class, args); | ||
|
||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...figure/src/test/java/io/dapr/spring/boot/autoconfigure/client/workflows/TestActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package io.dapr.spring.boot.autoconfigure.client.workflows; | ||
|
||
import io.dapr.workflows.runtime.WorkflowActivity; | ||
import io.dapr.workflows.runtime.WorkflowActivityContext; | ||
|
||
public class TestActivity implements WorkflowActivity { | ||
@Override | ||
public Object run(WorkflowActivityContext ctx) { | ||
return null; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...figure/src/test/java/io/dapr/spring/boot/autoconfigure/client/workflows/TestWorkflow.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package io.dapr.spring.boot.autoconfigure.client.workflows; | ||
|
||
import io.dapr.workflows.Workflow; | ||
import io.dapr.workflows.WorkflowStub; | ||
|
||
public class TestWorkflow extends Workflow { | ||
|
||
@Override | ||
public WorkflowStub create() { | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
...r-spring-workflows/src/main/java/io/dapr/spring/workflows/config/DaprWorkflowsConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package io.dapr.spring.workflows.config; | ||
|
||
import io.dapr.workflows.Workflow; | ||
import io.dapr.workflows.runtime.WorkflowActivity; | ||
import io.dapr.workflows.runtime.WorkflowRuntime; | ||
import io.dapr.workflows.runtime.WorkflowRuntimeBuilder; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.BeansException; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.context.ApplicationContextAware; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.ComponentScan; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar; | ||
|
||
import java.util.Map; | ||
|
||
@Configuration | ||
@ComponentScan("io.dapr.spring.workflows.config") | ||
public class DaprWorkflowsConfig implements ApplicationContextAware { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(DaprWorkflowsConfig.class); | ||
@Autowired | ||
private WorkflowRuntimeBuilder workflowRuntimeBuilder; | ||
|
||
private static ApplicationContext context; | ||
|
||
/** | ||
* Register workflows and activities to the workflowRuntimeBuilder. | ||
*/ | ||
public void registerWorkflowsAndActivities() { | ||
LOGGER.info("Registering Dapr Workflows and Activities"); | ||
Map<String, Workflow> workflowBeans = context.getBeansOfType(Workflow.class); | ||
for (Workflow w : workflowBeans.values()) { | ||
LOGGER.info("Dapr Workflow: '{}' registered", w.getClass().getName()); | ||
workflowRuntimeBuilder.registerWorkflow(w.getClass()); | ||
} | ||
|
||
Map<String, WorkflowActivity> workflowActivitiesBeans = context.getBeansOfType(WorkflowActivity.class); | ||
for (WorkflowActivity a : workflowActivitiesBeans.values()) { | ||
LOGGER.info("Dapr Workflow Activity: '{}' registered", a.getClass().getName()); | ||
workflowRuntimeBuilder.registerActivity(a.getClass()); | ||
} | ||
|
||
try (WorkflowRuntime runtime = workflowRuntimeBuilder.build()) { | ||
LOGGER.info("Starting workflow runtime ... "); | ||
runtime.start(false); | ||
} | ||
} | ||
|
||
@Override | ||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { | ||
context = applicationContext; | ||
registerWorkflowsAndActivities(); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...r-spring-workflows/src/main/java/io/dapr/spring/workflows/config/EnableDaprWorkflows.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package io.dapr.spring.workflows.config; | ||
|
||
|
||
import org.springframework.context.annotation.Import; | ||
|
||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
|
||
import static java.lang.annotation.ElementType.TYPE; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
@Retention(RUNTIME) | ||
@Target(TYPE) | ||
@Import(DaprWorkflowsConfig.class) | ||
public @interface EnableDaprWorkflows { | ||
} |