• Stars
    star
    215
  • Rank 178,059 (Top 4 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created almost 7 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Simple example using Camunda and Spring Boot to define a simple microservice communcating via AMQP, fully unit tested and deployable in the cloud

Camunda Platform 7

Camunda Spring Boot example including REST and AMQP, automated tested and deployable in the cloud

This example shows:

  • How to setup Camunda, Spring Boot and various test frameworks correctly in order to work. It can be used as a copy & paste template.
  • How to use AMQP and REST in your processes the Spring way.
  • How to write proper scenario tests, that test if your process impacts the outer world as you expect (and not tests that Camunda did write a proper workflow engine).
  • How this type of application can be easily deployed in the cloud (Pivotal Web Services as an example).

The business example is a very simple order fullfillment microservice (motivated by the flowing retail example):

Example overview

  • It is triggered via REST (it could have been an AMQP message or any other trigger as well, just REST is very easy to do demo requests)
  • Calls a REST service (actually, the REST service is directly implemented here for simplicity, as I did not want to rely on an external URL)
  • Sends a AMQP message and waits for a response. For simplicity, the request message will be directly treated as response

Embedded engine

With Camunda it is possible to run the engine as part of your application or microservice. This is called embedded engine. This is especially helpful in microservice architectures if you develop in Java, then the engine simply gets a library helping you to define flows with persistent state and subsequent requirements like timeout handling, retrying, compensation and so on. See Why service collaboration needs choreography AND orchestration for background reading.

Embedded engine

Walkthrough as screencast

This video gives a very quick walk through the example (15 minutes):

Walkthrough

Project setup

The project uses

Please have a look at the pom.xml for details. Also note the Application.java as Spring Boot starter class.

Configuration of Camunda

With Spring Boot Camunda gets auto-configured using defaults. You can easily change the configuration by providing classes according to the docs. In this example you can see

  • HistoryConfiguration that tells Camunda to save all historic data and audit logs.
  • IdGenerator so that Camunda uses string UUID's instead of database generated ones, which avoids deadlock risks in cluster environments.
  • Plugin to write some events to sysout. This plugin registers a listener to get notified when new workflow instances are started or existing ones are eneded. In this codebase just prints a line on the console, but it would be easy to push the event to some central tracing system. The cool thing: Such a plugin could be packaged in an own Maven depedency, as soon it is on the classpath it will be activated and influence the core engine.

Using Camunda Enterprise Edition

The example uses the community edition to allow for a quick start. It is easy to switch dependencies to use the Enterprise Edition as you can see in this commit. Just make sure you can connect to the Camunda Nexus using your enterprise credentials.

Testing

One extremly interessting piece is the JUnit test case, which does a complete run-thorugh the process, including all Java code attached to the process, but without sending any real AMQP message or REST request. The timeout of a waiting period in the process is also simulated.

    StartingByStarter starter = Scenario.run(orderProcess) //
      .startBy(() -> {
        return orderRestController.placeOrder(orderId, 547);
      });
    
    // expect the charge for retrieving payments to be created correctly and return a dummy transactionId
    mockRestServer
        .expect(requestTo("http://api.example.org:80/payment/charges")) //
        .andExpect(method(HttpMethod.POST))
        .andExpect(jsonPath("amount").value("547"))
        .andRespond(withSuccess("{\"transactionId\": \"12345\"}", MediaType.APPLICATION_JSON));
    
    when(orderProcess.waitsAtReceiveTask("ReceiveTask_WaitForGoodsShipped")).thenReturn((messageSubscription) -> {
      amqpReceiver.handleGoodsShippedEvent(orderId, "0815");
    });    

    when(orderProcess.waitsAtTimerIntermediateEvent(anyString())).thenReturn((processInstance) -> {
      processInstance.defer("PT10M", () -> {fail("Timer should have fired in the meanwhile");}); 
    });
    
    // OK - everything prepared - let's go
    Scenario scenario = starter.execute();
    
    mockRestServer.verify();

    // and very that some things happened
    assertThat(scenario.instance(orderProcess)).variables().containsEntry(ProcessConstants.VARIABLE_paymentTransactionId, "12345");
    assertThat(scenario.instance(orderProcess)).variables().containsEntry(ProcessConstants.VAR_NAME_shipmentId, "0815");

    {
      ArgumentCaptor<Message> argument = ArgumentCaptor.forClass(Message.class);
      verify(rabbitTemplate, times(1)).convertAndSend(eq("shipping"), eq("createShipment"), argument.capture());
      assertEquals(orderId, argument.getValue());
    }

    verify(orderProcess).hasFinished("EndEvent_OrderShipped");

Refer to the OrderProcessTest.java for all details. Note that the test generates a graphical report:

Test Coverage

Get started

In order to get started just

  • Clone or download this example
  • Maven build (this also runs the test cases)
mvn clean install
  • Install RabbitMQ and start it up

  • Run microservice via Java:

java -jar target/camunda-spring-boot-amqp-microservice-cloud-example-0.0.1-SNAPSHOT.jar

Now you can access:

curl --request POST -F 'orderId=1' -F 'amount=500' http://localhost:8080/order

Of course you can also use your favorite IDE.

Cloud deployment on Pivotal Web Services

You can easily deploy a Spring Boot application to various cloud providers, as you get a fat jar runnable on every JVM.

And using the Spring Cloud Connectors the application can be magically wired with cloud resources.

The example I show here is:

All metadata for the deployment are described in the manifest.yml:

---
applications:
  - name: camunda-spring-boot-amqp-microservice-cloud-example
    memory: 1G
    instances: 1
    random-route: false

services:
  - cloud-amqp
  - camunda-db

Now you can easily deploy the application using the CloudFoundry CLI. After logging in you can simply type:

mvn clean install && cf push -p target/camunda-spring-boot-amqp-microservice-cloud-example-0.0.1-SNAPSHOT.jar

There it is, now you can start a process:

url -X POST -F 'orderId=123' -F 'amount=4990' http://camunda-spring-boot-amqp-microservice-cloud-example.cfapps.io/order

And will see it in cockpit:

Cockpit

The URL to access the Camunda web applications and your REST-API depends on various factors, but will be shown via the Pivotal console:

Test Coverage

Test Coverage

More Repositories

1

flowing-retail

Sample application demonstrating an order fulfillment system decomposed into multiple independant components (e.g. microservices). Showing concrete implementation alternatives using e.g. Java, Spring Boot, Apache Kafka, Camunda, Zeebe, ...
Java
1,221
star
2

trip-booking-saga-java

Example implementation of the Saga pattern for the classic trip booking example using the lightweight open source workflow engine (Camunda).
Java
268
star
3

camunda-csharp-showcase

Showcase using Camunda BPM on .NET Platform with C# (no Java Coding required!)
C#
165
star
4

flowing-trip-booking-saga-c-sharp

Example implementation of the Saga pattern for the classic trip booking example using the lightweight open source workflow engine (Camunda) and C#.
C#
164
star
5

flowing-retail-old

REPLACED BY MORE CURRENT VRSION OF THIS EXAMPLE: https://github.com/berndruecker/flowing-retail
Java
63
star
6

ticket-booking-camunda-8

A ticket booking example using Camunda Cloud, RabbitMQ, REST and two sample apps (Java Spring Boot and NodeJS)
Java
26
star
7

trip-booking-saga-serverless

Standard example of the Saga pattern (trip booking) in a serverless world
JavaScript
22
star
8

customer-onboarding-camunda-8-springboot

A simple onboarding process example using BPMN, Camunda Cloud, Java, Spring Boot and REST
Java
21
star
9

flowing-retail-concept-java

Simple application showing the concepts using plain Java without infrastructure
Java
20
star
10

camunda-csharp-client

Small (hacky!) client library wrapping around the Camunda REST API. Use to get started or demo - but note that this code is not supported or build for production!
C#
19
star
11

kafka-camunda-spring-simple

Simple Java Spring Boot example connecting to Confluent Cloud (Kafka) and Camunda Cloud (Zeebe)
Java
14
star
12

zeebe-camunda-dmn

Sample how to use Camunda DMN decisions in a Zeebe Workflow
Java
11
star
13

oreilly-training-process-automation

Labs for the OReilly Training "Process Automation in Modern Architectures"
11
star
14

customer-onboarding-camunda-8-springboot-extended

Example onboarding process using Camunda Cloud, Java, Spring Boot, REST and AMQP
Java
10
star
15

processautomationbook.com

Website for the book "Practical Process Automation" with O'Reilly
CSS
7
star
16

camunda-7-on-pcf

Tutorial how to run Camunda on Pivotal Cloud Foundary (PCF)
Java
6
star
17

flowing-retail-camunda-intro

Order flow implemented as one simple Camunda process application. Small sister of the flowing-retail example showing the same use case as system of collaborating microservices.
Java
6
star
18

camunda-7-remote-spring-boot-example

Example showing how to connect to a remote Camunda Run from Spring boot for external taks and OpenAPI REST calls
Java
6
star
19

kafka-connect-zeebe-benchmark

Python
5
star
20

bpmn-resilience-patterns

Showing how to leverage BPMN and/or the Camunda BPM engine to improve resilience by certain patterns around retrying and timeouts
Java
5
star
21

zeebe-loadtest-kubernetes

Load tests for Zeebe which can be run on Kubernetes using Helm charts to provision everything automatically
Java
5
star
22

camunda-zipkin-springboot-demo

POC using Spring Boot to show that you also trace whole workflows from Camunda with Zipkin.
Java
5
star
23

flowing-retail-payment-rest-spring-statemachine

Flowing Retail payment service implemented using Spring StateMachine (as comparison for Camunda)
Java
5
star
24

camunda-engine-7-harvester

Simple POC to show how to gather information about multiple Camunda engines across the enterprise
Java
4
star
25

customer-onboarding-camunda-7

Quick and dirty demo for an onboarding process from the book "Practical Process Automation" using Camunda Platform and Spring Boot
Java
4
star
26

camunda-7-openapi-demo

Java
3
star
27

zeebe-aws-event-bridge

summer hackdays 2020 project to prototype an integration between zeebe cloud and AWS EventBridge
Java
3
star
28

mule-camunda-24

Showcase using Mule and camunda BPM for a simple order process
Java
3
star
29

camunda-ready-to-receive-patterns

Some samples how to handle if a workflow instance in Camunda is not yet ready-to-receive a message
Java
2
star
30

advanced-workflow-patterns

JavaScript
1
star
31

zeebe-benchmark-demo

Simple local benchmark for smoketest of Zeebe performance
Java
1
star
32

camunda-compensation-examples

Java
1
star
33

custom-process-landscape

1
star
34

camunda-8-junit-tests-playgorund

Project to play with latest Camunda Cloud Zeebe testing libraries
Java
1
star
35

zeebe-first-contact

Hello World example used for first contact live demos
Java
1
star
36

camunda-interactive-lab

Interactive lab to do a plublic exercise to get Camunda running on participant machines, communicating with a central cloud Camunda instance to showcase some things - and to play around :-)
Java
1
star