@StreamListener(target = Sink.INPUT, condition = "(headers['messageType']?:'')=='OrderPlacedEvent'") public void orderPlacedReceived(String messageJson) throws JsonParseException, JsonMappingException, IOException { // read data Message<Order> message = new ObjectMapper().readValue(messageJson, new TypeReference<Message<Order>>() {}); Order order = message.getPayload(); // persist domain entity // (if we want to do this "transactional" this could be a step in the workflow) repository.save(order); // prepare data for workflow OrderFlowContext context = new OrderFlowContext(); context.setOrderId(order.getId()); context.setTraceId(message.getTraceId()); // and kick of a new flow instance System.out.println("New order placed, start flow. " + context.asJson()); zeebe.workflowClient().newCreateInstanceCommand() // .bpmnProcessId("order-kafka") // .latestVersion() // .payload(context.asJson()) // .send().join(); }
/** * Creates a workflow instance for the given process ID, with the given payload. * * @param processId BPMN process ID * @param payload initial payload for the instance * @return unique ID used to interact with the instance */ public long createWorkflowInstance(String processId, Map<String, Object> payload) { return clientRule .getClient() .newCreateInstanceCommand() .bpmnProcessId(processId) .latestVersion() .payload(payload) .send() .join() .getWorkflowInstanceKey(); }
public static void main(final String[] args) { final String broker = "127.0.0.1:26500"; final String bpmnProcessId = "demoProcess"; final ZeebeClientBuilder builder = ZeebeClient.newClientBuilder().brokerContactPoint(broker); try (ZeebeClient client = builder.build()) { System.out.println("Creating workflow instance"); final WorkflowInstanceEvent workflowInstanceEvent = client .newCreateInstanceCommand() .bpmnProcessId(bpmnProcessId) .latestVersion() .send() .join(); System.out.println( "Workflow instance created with key: " + workflowInstanceEvent.getWorkflowInstanceKey()); } } }
/** * Creates a workflow instance for the given process ID, with the given payload. * * @param processId BPMN process ID * @param payload initial payload for the instance * @return unique ID used to interact with the instance */ public long createWorkflowInstance(String processId, Map<String, Object> payload) { return clientRule .getClient() .newCreateInstanceCommand() .bpmnProcessId(processId) .latestVersion() .payload(payload) .send() .join() .getWorkflowInstanceKey(); }
public static void main(final String[] args) { final String broker = "127.0.0.1:26500"; final ZeebeClientBuilder builder = ZeebeClient.newClientBuilder().brokerContactPoint(broker); try (ZeebeClient client = builder.build()) { final Order order = new Order(); order.setOrderId(31243); client .newCreateInstanceCommand() .bpmnProcessId("demoProcess") .latestVersion() .payload(order) .send() .join(); client.newWorker().jobType("foo").handler(new DemoJobHandler()).open(); // run until System.in receives exit command waitUntilSystemInput("exit"); } }