colinlucs / microservices-orchestration-amqp-example

An example project of event-driven microservices orchestration using Camunda and RabbitMQ
76 stars 39 forks source link

Event-Driven Microservices Orchestration using Camunda, Spring Boot, and RabbitMQ

This is an example project of my article: "Event-driven Orchestration: An Effective Microservices Integration using BPMN and AMQP".

Overview

This sample consists of three sub-projects:

How to Use

Prerequisite

Build

Launch the Stub Services

The following services will be launched as the integrated participants in the shopping cart fulfillment flow:

Launch the service simulator respectively as below:

$ cd microservices-orchestration-amqp-example
$ cd service-stubs/target
$ java -jar microservice-orchestration-using-camunda-amqp-stub-0.0.1-SNAPSHOT.jar --spring.profiles.active=amqp-consumer,location
$ java -jar microservice-orchestration-using-camunda-amqp-stub-0.0.1-SNAPSHOT.jar --spring.profiles.active=amqp-consumer,payment
$ java -jar microservice-orchestration-using-camunda-amqp-stub-0.0.1-SNAPSHOT.jar --spring.profiles.active=amqp-consumer,inventory
$ java -jar microservice-orchestration-using-camunda-amqp-stub-0.0.1-SNAPSHOT.jar --spring.profiles.active=amqp-consumer,order
$ java -jar microservice-orchestration-using-camunda-amqp-stub-0.0.1-SNAPSHOT.jar --spring.profiles.active=amqp-consumer,customer
$ java -jar microservice-orchestration-using-camunda-amqp-stub-0.0.1-SNAPSHOT.jar --spring.profiles.active=amqp-consumer,backoffice

Launch the Main Orchestration Service - the Shopping Cart Service

$ cd microservices-orchestration-amqp-example
$ cd shoppingcart-service/target
$ java -jar microservice-orchestration-using-camunda-amqp-0.0.1-SNAPSHOT.jar --spring.profiles.active=amqp-producer

Test Shopping Cart Fulfillment Flow

Scenario 1: Submit Shopping Cart Successfully - Transaction Committed


* Expected Response:

  * Submit Shopping Cart is successful; the shopping cart is CLOSED
  * HTTP status code: 200

```json
{
  "id": "1c93e02a-e7c6-418b-ae01-c047cefe0001",
  "entityType": "SHOPPINGCART",
  "entitySpecification": "consumerSC",
  "name": "MySchoppingCart_1c93e02a-e7c6-418b-ae01-c047cefe0001",
  "status": "CLOSED",
  "relatedEntities": [
    {
      "id": "2ed5ef8f-1ea6-4851-8541-bf7eefbffeb4",
      "entityType": "LOCATION",
      "entitySpecification": "shippingAddr",
      "name": "MyShippingAddress_1c93e02a-e7c6-418b-ae01-c047cefe0001",
      "relatedEntities": []
    },
    {
      "id": "e7af5e98-d73a-44b8-9021-e98aa448b086",
      "entityType": "PAYMENT",
      "entitySpecification": "creditCartPayment",
      "name": "MyPayment_1c93e02a-e7c6-418b-ae01-c047cefe0001",
      "relatedEntities": []
    },
    {
      "id": "7a5520fc-1287-4d82-a483-c4c1e7c39e50",
      "entityType": "PRODUCT",
      "entitySpecification": "iphoneX_Gold_128G",
      "name": "MyProduct_1c93e02a-e7c6-418b-ae01-c047cefe0001",
      "relatedEntities": []
    },
    {
      "id": "27f9de5c-e384-486c-9252-600381554310",
      "entityType": "PRODUCT",
      "entitySpecification": "iphoneX_Case",
      "name": "MyProduct_1c93e02a-e7c6-418b-ae01-c047cefe0001",
      "relatedEntities": []
    }
  ]
}

Scenario 2: Submit Shopping Cart Failed Due to Order Service Issue - Transaction Rolled Back


* Expected Response:

  * Submit Shopping Cart is failed due to the processing error in placing the order to the Order Service
  * HTTP status code: 403

```json

{
    "code": "ERR_ORDER_FAILURE",
    "message": "Unable to process order.",
    "details": "Internal Error: Unable to process order, please contact the system administrator."
}

Scenario 3: Submit Shopping Cart Failed when Location Service is down - Transaction Aborted


* Expected Response:

  * Submit Shopping Cart is failed due to the unavailability of the Location Service
  * HTTP status code: 403

```json

{
    "code": "ERR_SERVICE_UNAVAIL",
    "message": "Service Unavaialble",
    "details": "Internal Error: we are sorry, the LocationService is not reachable. Please try again later."
}