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
class Order { | |
String id; | |
Customer customer; | |
List<OrderItem> items; | |
static enum GoodsDeliveryStatus { | |
NOTHING_DONE, | |
GOODS_RESERVED, | |
GOODS_PICKED | |
} |
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
class OrderSaga { | |
String orderId; | |
static enum GoodsDeliveryStatus { | |
NOTHING_DONE, | |
GOODS_RESERVED, | |
GOODS_PICKED | |
} | |
boolean paymentReceived = false; | |
GoodsDeliveryStatus deliveryStatus = GoodsDeliveryStatus.NOTHING_DONE; |
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
if (event.equals("order placed")) { | |
issueCommand("do payment"); | |
} |
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
engine.getRepositoryService().createDeployment() // | |
.addModelInstance("order.bpmn", Bpmn.createProcess("order").executable() // | |
.startEvent() | |
.serviceTask().name("A") | |
.parallelGateway("fork1") | |
.serviceTask().name("B") | |
.parallelGateway("join2") | |
.moveToNode("fork1") | |
.serviceTask().name("C") | |
.parallelGateway("fork2") |
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
public boolean handleEvent(String type, String eventName, String transactionId, JsonObject event) { | |
VariableMap correlationKeys = getCorrelationKeys(event); | |
MessageCorrelationBuilder correlation = engine.getRuntimeService().createMessageCorrelation(eventName); | |
ExecutionQuery query = engine.getRuntimeService().createExecutionQuery().messageEventSubscriptionName(eventName); | |
for (String key : correlationKeys.keySet()) { | |
correlation.processInstanceVariableEquals(key, correlationKeys.get(key)); | |
query.processVariableValueEquals(key, correlationKeys.get(key)); | |
} |
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
deploymentBuilder | |
.addModelInstance("order.bpmn", Bpmn.createExecutableProcess("Order") | |
.startEvent() | |
.businessRuleTask().name("Determine risk of fraud").camundaDecisionRef("RiskyOrder") | |
.camundaResultVariable("riskyOrder").camundaMapDecisionResult("singleEntry") | |
.serviceTask().name("Do payment").camundaClass(DoPaymentAdapter.class).camundaAsyncBefore() | |
.sendTask() .name("Initiate delivery").camundaClass(InitiateDeliveryAdapter.class) | |
.receiveTask().name("Wait for delivery").message("MessageDeliveryDone") | |
.endEvent() | |
.done() |
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
@Test | |
@Deployment(resources = { "Order.bpmn", "RiskyOrder.dmn" }) | |
public void testHappyPath() { | |
when(orderFlow.waitsAtUserTask("UserTask_ApproveOrder")) // | |
.thenReturn((task) -> task.complete(Variables.putValue("approved", true))); | |
mockRestServer | |
.expect(requestTo("https://api.stripe.com")) | |
// normal mocking... | |
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
@RunWith(SpringRunner.class) | |
@SpringBootTest(webEnvironment = WebEnvironment.NONE, // | |
classes = TestApplication.class, // | |
properties = { // | |
"camunda.bpm.job-execution.enabled=false", // | |
"camunda.bpm.auto-deployment-enabled=false"}) | |
@Deployment(resources = {"..."}) | |
public class SomeScenarioTest { | |
//... |
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
public class RetrievePaymentAdapter implements JavaDelegate { | |
public void execute(ActivityExecution ctx) { | |
// prepare message content, you can load variables from persistent flow context | |
ctx.getVariable("orderId"); | |
// ... | |
// Send command | |
publishCommand("DoPayment", payload); | |
// ant tell the engine to wait for the next event |
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
public class RetrievePaymentRestAdapter implements JavaDelegate { | |
@Inject private OrderRepository orderRepository; // e.g. using Spring | |
@Inject private RestTemplate rest; // e.g. using Spring | |
public void execute(DelegateExecution context) throws Exception { | |
// Input mapping | |
String orderId = context.getVariable("orderId"); | |
Order o = orderRepository.findOrder(orderId); | |
CreateChargeRequest request = new CreateChargeRequest(); | |
request.setAmount( o.getAmount() ); |
OlderNewer