transition enricher
This commit is contained in:
33
state_machines/complex_multi_module_sm/web/.gitignore
vendored
Normal file
33
state_machines/complex_multi_module_sm/web/.gitignore
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
HELP.md
|
||||
target/
|
||||
.mvn/wrapper/maven-wrapper.jar
|
||||
!**/src/main/**/target/
|
||||
!**/src/test/**/target/
|
||||
|
||||
### STS ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
build/
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
28
state_machines/complex_multi_module_sm/web/pom.xml
Normal file
28
state_machines/complex_multi_module_sm/web/pom.xml
Normal file
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>click.kamil.complex</groupId>
|
||||
<artifactId>complex-multi-module-sm</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>web</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>click.kamil.complex</groupId>
|
||||
<artifactId>service</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-activemq</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,14 @@
|
||||
package click.kamil.web;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.jms.annotation.EnableJms;
|
||||
|
||||
@SpringBootApplication(scanBasePackages = "click.kamil")
|
||||
@EnableJms
|
||||
public class Application {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package click.kamil.web;
|
||||
|
||||
import click.kamil.domain.OrderEvent;
|
||||
import click.kamil.service.StateMachineService;
|
||||
import org.springframework.jms.annotation.JmsListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class JmsOrderListener {
|
||||
|
||||
private final StateMachineService stateMachineService;
|
||||
|
||||
// Constructor injection
|
||||
public JmsOrderListener(StateMachineService stateMachineService) {
|
||||
this.stateMachineService = stateMachineService;
|
||||
}
|
||||
|
||||
@JmsListener(destination = "order.process.queue")
|
||||
public void receiveProcessCommand(String message) {
|
||||
System.out.println("Received JMS message: " + message);
|
||||
stateMachineService.sendMessageWithOutbox(OrderEvent.PROCESS, event -> {
|
||||
System.out.println("JMS Triggered Faulty Outbox Action executed post-commit for event: " + event);
|
||||
});
|
||||
}
|
||||
|
||||
@JmsListener(destination = "order.cancel.queue")
|
||||
public void receiveCancelCommand(String message) {
|
||||
System.out.println("Received JMS message: " + message);
|
||||
stateMachineService.sendMessageWithProvider(() -> OrderEvent.CANCEL);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package click.kamil.web;
|
||||
|
||||
import click.kamil.domain.OrderEvent;
|
||||
import click.kamil.service.StateMachineService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/orders")
|
||||
public class OrderController {
|
||||
|
||||
@Autowired
|
||||
private StateMachineService stateMachineService;
|
||||
|
||||
@PostMapping("/process")
|
||||
public String processOrder() {
|
||||
stateMachineService.sendMessageWithOutbox(OrderEvent.PROCESS, event -> {
|
||||
System.out.println("Faulty Outbox Action executed post-commit for event: " + event);
|
||||
});
|
||||
return "Order process event sent within transaction";
|
||||
}
|
||||
|
||||
@PostMapping("/complete")
|
||||
public String completeOrder() {
|
||||
stateMachineService.sendMessage(OrderEvent.COMPLETE);
|
||||
return "Order complete event sent";
|
||||
}
|
||||
|
||||
@PostMapping("/cancel")
|
||||
public String cancelOrder() {
|
||||
stateMachineService.sendMessage(OrderEvent.CANCEL);
|
||||
return "Order cancel event sent";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user