Skip to content

Instantly share code, notes, and snippets.

View berndruecker's full-sized avatar

Bernd Ruecker berndruecker

View GitHub Profile
@ZeebeInboundConnector(name = "io.camunda.community:amqp:1")
public class AmqpInboundSubscription implements SubscriptionInboundConnector {
@Override
public void activate(InboundConnectorConfig config, InboundConnectorContext context) throws Exception {
initialize(context, config.getConfiguredParameters());
consumerTemplate = createConsumerTemplate();
consumerTemplate.start();
while (running) {
Exchange receive = consumerTemplate.receive( getParameters().getEndpointUri() );
@ZeebeOutboundConnector(
name = "http-json",
taskType = "io.camunda:http-json:1",
variablesToFetch = {"restUrl", "username","password", "..."})
public class RestOutboundConnectorFunction implements OutboundConnectorFunction {
//...
public class HttpJsonFunction implements OutboundConnectorFunction {
@Override
public Object execute(OutboundConnectorContext context) {
final var json = context.getVariables();
final var request = GSON.fromJson(json, HttpJsonRequest.class);
final var validator = new Validator();
request.validate(validator);
validator.validate();
@Component
public class MapDmnResult implements ExecutionListener {
@Override
public void notify(DelegateExecution execution) throws Exception {
List<String> risks = new ArrayList<String>();
Set<String> riskLevels = new HashSet<String>();
Object oDMNresult = execution.getVariable("riskDMNresult");
for (Object oResult : (List<?>) oDMNresult) {
@RestController
public class OrderFulfillmentRestController {
@Autowired
private ProcessEngine camunda;
@RequestMapping(path = "/order", method = PUT)
public String placeOrder(String orderPayload, HttpServletResponse response) throws Exception {
// TODO: Somehow extract data from orderPayload
String orderData = "todo";
@Component
public class CreateCustomerInCrmJavaDelegate implements JavaDelegate {
@Autowired
private ObjectMapper objectMapper;
@Autowired
private CrmFacade crmFacade;
public void execute(DelegateExecution execution) throws Exception {
@ZeebeWorker(type = "payment", autoComplete = true)
public Map<String, Object> retrievePayment(ActivatedJob job) {
// some work
// any exception thrown here will lead to retrying/incidents in Zeebe
if (successful) {
// some data is returned to be stored as process variable
return variables;
} else {
// problem shall be indicated to the process and can be handled via BPMN error events
throw new ZeebeBpmnError("DOESNT_WORK", "This does not work because...");
@JobWorker(type = "payment")
public void retrievePayment(ActivatedJob job) {
// Do whatever you need to, e.g. invoke a remote service
String orderId = job.getVariablesMap().get("orderId");
paymentRestClient.invoke(...);
}
@Transactional
public void paymentReceived(...) {
// ...
paymentRepository.save( payment );
orderService.markOrderPaid( payment.getOrderId(), payment.getId() );
// ...
}
private static async void BlockingJobHandler(IJobClient jobClient, IJob activatedJob)
{
Log.LogInformation("Invoke REST call...");
var response = httpClient.GetAsync("/").Result;
Log.LogInformation("...finished. Complete Job...");
await jobClient.NewCompleteJobCommand(activatedJob).Send();
counter.inc();
}