transition enricher rabbit
This commit is contained in:
@@ -24,5 +24,9 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-activemq</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-amqp</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package click.kamil.web;
|
||||
|
||||
import click.kamil.domain.CustomStateMachineMessage;
|
||||
import click.kamil.domain.OrderEvent;
|
||||
import click.kamil.service.StateMachineService;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class RabbitOrderListener {
|
||||
|
||||
private final StateMachineService stateMachineService;
|
||||
|
||||
// Constructor Injection
|
||||
public RabbitOrderListener(StateMachineService stateMachineService) {
|
||||
this.stateMachineService = stateMachineService;
|
||||
}
|
||||
|
||||
// Listens to RabbitMQ, constructs the custom class, triggers a state transition
|
||||
@RabbitListener(queues = "order.custom.transition.queue")
|
||||
public void handleCustomTransition(String payload) {
|
||||
System.out.println("Received RabbitMQ message: " + payload);
|
||||
|
||||
// Construct our custom event containing the generic payload and the enum state
|
||||
CustomStateMachineMessage<OrderEvent, String> customMessage =
|
||||
new CustomStateMachineMessage<>(OrderEvent.PROCESS, "My Rabbit Custom Payload: " + payload);
|
||||
|
||||
// Push the custom event into the state machine to perform the transition
|
||||
stateMachineService.sendCustomMessage(customMessage);
|
||||
System.out.println("Triggered PROCESS transition via custom message over RabbitMQ");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user