multi
This commit is contained in:
12
state_machines/multi_module_sample/api-module/build.gradle
Normal file
12
state_machines/multi_module_sample/api-module/build.gradle
Normal file
@@ -0,0 +1,12 @@
|
||||
plugins {
|
||||
id 'java'
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'org.springframework.boot:spring-boot-starter-web:3.2.0'
|
||||
implementation 'org.springframework.statemachine:spring-statemachine-core:3.2.0'
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package click.kamil.multi.api;
|
||||
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
@RequestMapping("/orders")
|
||||
public interface OrderApi {
|
||||
|
||||
@PostMapping("/submit")
|
||||
void submitOrder(@RequestBody String orderId);
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package click.kamil.multi.api;
|
||||
|
||||
import org.springframework.statemachine.StateContext;
|
||||
import org.springframework.statemachine.action.Action;
|
||||
|
||||
public interface ProcessAction extends Action<String, String> {
|
||||
|
||||
@Override
|
||||
default void execute(StateContext<String, String> context) {
|
||||
System.out.println("Processing order: " + context.getMessageHeader("orderId"));
|
||||
}
|
||||
}
|
||||
13
state_machines/multi_module_sample/core-module/build.gradle
Normal file
13
state_machines/multi_module_sample/core-module/build.gradle
Normal file
@@ -0,0 +1,13 @@
|
||||
plugins {
|
||||
id 'java'
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation project(':state_machines:multi_module_sample:api-module')
|
||||
implementation 'org.springframework.boot:spring-boot-starter-web:3.2.0'
|
||||
implementation 'org.springframework.statemachine:spring-statemachine-core:3.2.0'
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package click.kamil.multi.core;
|
||||
|
||||
import click.kamil.multi.api.OrderApi;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.statemachine.StateMachine;
|
||||
import org.springframework.statemachine.config.StateMachineFactory;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
public class OrderController implements OrderApi {
|
||||
|
||||
private final StateMachineFactory<String, String> factory;
|
||||
|
||||
@Override
|
||||
public void submitOrder(String orderId) {
|
||||
StateMachine<String, String> sm = factory.getStateMachine(orderId);
|
||||
sm.sendEvent("SUBMIT");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package click.kamil.multi.core;
|
||||
|
||||
import click.kamil.multi.api.ProcessAction;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.statemachine.config.EnableStateMachineFactory;
|
||||
import org.springframework.statemachine.config.StateMachineConfigurerAdapter;
|
||||
import org.springframework.statemachine.config.builders.StateMachineStateConfigurer;
|
||||
import org.springframework.statemachine.config.builders.StateMachineTransitionConfigurer;
|
||||
|
||||
@Configuration
|
||||
@EnableStateMachineFactory
|
||||
public class OrderStateMachineConfig extends StateMachineConfigurerAdapter<String, String> {
|
||||
|
||||
@Override
|
||||
public void configure(StateMachineStateConfigurer<String, String> states) throws Exception {
|
||||
states
|
||||
.withStates()
|
||||
.initial("NEW")
|
||||
.state("PROCESSING")
|
||||
.end("COMPLETED");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configure(StateMachineTransitionConfigurer<String, String> transitions) throws Exception {
|
||||
transitions
|
||||
.withExternal()
|
||||
.source("NEW")
|
||||
.target("PROCESSING")
|
||||
.event("SUBMIT")
|
||||
.action(processAction())
|
||||
.and()
|
||||
.withExternal()
|
||||
.source("PROCESSING")
|
||||
.target("COMPLETED")
|
||||
.event("FINISH");
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ProcessAction processAction() {
|
||||
return new ProcessAction() {};
|
||||
}
|
||||
}
|
||||
3
state_machines/multi_module_sample/settings.gradle
Normal file
3
state_machines/multi_module_sample/settings.gradle
Normal file
@@ -0,0 +1,3 @@
|
||||
rootProject.name = 'multi-module-sample'
|
||||
include 'api-module'
|
||||
include 'core-module'
|
||||
Reference in New Issue
Block a user