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
SagaBuilder saga = SagaBuilder.newSaga("trip") | |
.activity("Reserve car", ReserveCarAdapter.class) | |
.compensationActivity("Cancel car", CancelCarAdapter.class) | |
.activity("Book hotel", BookHotelAdapter.class) | |
.compensationActivity("Cancel hotel", CancelHotelAdapter.class) | |
.activity("Book flight", BookFlightAdapter.class) | |
.compensationActivity("Cancel flight", CancelFlightAdapter.class) | |
.end() | |
.triggerCompensationOnAnyError(); |
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
@Configuration | |
public class CamundaEngineHistoryConfiguration extends AbstractCamundaConfiguration implements CamundaHistoryLevelAutoHandlingConfiguration { | |
@Override | |
public void preInit(SpringProcessEngineConfiguration configuration) { | |
configuration.setHistory(ProcessEngineConfiguration.HISTORY_FULL); | |
} | |
} | |
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
var camunda = new CamundaEngineClient("http://localhost:8080/engine-rest/engine/default/", null, null); | |
// Deploy the BPMN XML file from the resources | |
camunda.RepositoryService.Deploy("trip-booking", new List<object> { | |
FileParameter.FromManifestResource(Assembly.GetExecutingAssembly(), "FlowingTripBookingSaga.Models.FlowingTripBookingSaga.bpmn") | |
}); | |
// Register workers | |
registerWorker("reserve-car", externalTask => { | |
// here you can do the real thing! Like a sysout :-) |
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 Payment implements EventObserver { | |
public void eventReceived(Event event) { | |
if (event.is("OrderPlaced")) { | |
// skip the real work | |
Bus.send(new Event("PaymentReceived", payload)); | |
} | |
} | |
} | |
public class Inventory implements EventObserver { | |
public void eventReceived(Event 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 Payment implements EventObserver { | |
public void eventReceived(Event event) { | |
if (event.is("OrderPlaced") && !(Boolean)event.getPayload().get("vip")) { | |
// skip the real work | |
Bus.send(new Event("PaymentReceived", payload)); | |
} | |
} | |
} | |
public class Inventory implements EventObserver { | |
public void eventReceived(Event 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 Order implements EventObserver { | |
public void eventReceived(Event event) { | |
if (event.is("OrderPlaced")) { | |
Bus.send(new Event("RetrievePaymentCommand", event.getPayload())); | |
} | |
if (event.is("PaymentReceived")) { | |
Bus.send(new Event("FetchGoodsCommand", event.getPayload())); | |
} | |
if (event.is("GoodsFetched")) { | |
Bus.send(new Event("ShipGoodsCommand", event.getPayload())); |
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 OrderCamunda implements EventObserver { | |
private static ProcessEngine camunda; | |
public static void init() { | |
// Configure Camunda engine (in this case using in memory H2) | |
StandaloneInMemProcessEngineConfiguration conf = new StandaloneInMemProcessEngineConfiguration(); | |
conf.setJobExecutorActivate(true); | |
camunda = conf.buildProcessEngine(); | |
// Define flow | |
BpmnModelInstance flow = simpleFlowOfActivities(); |
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
private static BpmnModelInstance extendedFlowOfActivities() { | |
ProcessBuilder flow = Bpmn.createExecutableProcess("order"); | |
flow.startEvent() | |
.exclusiveGateway("split").condition("normal folks", "#{not vip}") // | |
.serviceTask().name("Retrieve payment").camundaClass(RetrievePaymentAdapter.class) // | |
.boundaryEvent().compensateEventDefinition().compensateEventDefinitionDone() // | |
.compensationStart() // | |
.serviceTask().name("refund payment").camundaClass(RefundPaymentAdapter.class) // | |
.compensationDone() // |
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
var Workers = require('camunda-worker-node'); | |
var workers = Workers('http://localhost:8080/engine-rest', { | |
workerId: 'some-worker-id' | |
}); | |
workers.registerWorker('reserve-car', [ 'someData' ], function(context, callback) { | |
var someNewData = context.variables.someData + " - added something"; | |
callback(null, { | |
variables: { | |
someNewData: someNewData |