All Projects → eventuate-tram → Eventuate Tram Examples Customers And Orders

eventuate-tram / Eventuate Tram Examples Customers And Orders

Licence: other
An example of Choreography-based sagas in Spring Boot/JPA microservices

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Eventuate Tram Examples Customers And Orders

Docker Kubernetes By Example Java
An end-to-end Spring Boot example w container and Kubernetes
Stars: ✭ 151 (-45.29%)
Mutual labels:  microservices, spring-boot
Java Microservices Examples
Java Microservices: Spring Boot, Spring Cloud, JHipster, Spring Cloud Config, and Spring Cloud Gateway
Stars: ✭ 194 (-29.71%)
Mutual labels:  microservices, spring-boot
Spring Cloud Dubbo Together
Spring Cloud与Dubbo共存方案
Stars: ✭ 155 (-43.84%)
Mutual labels:  microservices, spring-boot
Gemini
Model Driven REST framework to automatically generate CRUD APIs
Stars: ✭ 138 (-50%)
Mutual labels:  microservices, spring-boot
Microservices Platform
基于SpringBoot2.x、SpringCloud和SpringCloudAlibaba并采用前后端分离的企业级微服务多租户系统架构。并引入组件化的思想实现高内聚低耦合,项目代码简洁注释丰富上手容易,适合学习和企业中使用。真正实现了基于RBAC、jwt和oauth2的无状态统一权限认证的解决方案,面向互联网设计同时适合B端和C端用户,支持CI/CD多环境部署,并提供应用管理方便第三方系统接入;同时还集合各种微服务治理功能和监控功能。模块包括:企业级的认证系统、开发平台、应用监控、慢sql监控、统一日志、单点登录、Redis分布式高速缓存、配置中心、分布式任务调度、接口文档、代码生成等等。
Stars: ✭ 3,274 (+1086.23%)
Mutual labels:  microservices, spring-boot
Spring Cloud Cli
Spring Cloud CLI features
Stars: ✭ 139 (-49.64%)
Mutual labels:  microservices, spring-boot
Event Sourcing Microservices Example
Learn about building microservices with event sourcing using Spring Boot and how to deploy a social network to Kubernetes using Docker Compose or Helm.
Stars: ✭ 167 (-39.49%)
Mutual labels:  microservices, spring-boot
Java Interview
At the beginning, it was the repository with questions from Java interviews. Currently, it's more like knowledge base with useful links.
Stars: ✭ 114 (-58.7%)
Mutual labels:  microservices, spring-boot
Spring Cloud Gateway Sample
Sample Spring Cloud Gateway Application
Stars: ✭ 268 (-2.9%)
Mutual labels:  microservices, spring-boot
Quickperf
QuickPerf is a testing library for Java to quickly evaluate and improve some performance-related properties
Stars: ✭ 231 (-16.3%)
Mutual labels:  microservices, spring-boot
Spring Cloud Config
External configuration (server and client) for Spring Cloud
Stars: ✭ 1,740 (+530.43%)
Mutual labels:  microservices, spring-boot
Event Stream Processing Microservices
Using Spring Cloud Stream and Spring State Machine to create event-driven microservices
Stars: ✭ 255 (-7.61%)
Mutual labels:  microservices, spring-boot
Piggymetrics
Microservice Architecture with Spring Boot, Spring Cloud and Docker
Stars: ✭ 11,161 (+3943.84%)
Mutual labels:  microservices, spring-boot
My Moments
Instagram Clone - Cloning Instagram for learning purpose
Stars: ✭ 140 (-49.28%)
Mutual labels:  microservices, spring-boot
Learning Path Spring Boot Microservices
Curated path for learning Spring Boot & Microservices based on published videos in TechPrimers
Stars: ✭ 116 (-57.97%)
Mutual labels:  microservices, spring-boot
Reactive Ms Example
An educational project to learn reactive programming with Spring 5
Stars: ✭ 157 (-43.12%)
Mutual labels:  microservices, spring-boot
Sample Spring Microservices Advanced
More advanced samples of spring boot and spring cloud microservices showing usage of such tools like api Swagger2 on Zuul, integraction with MongoDB, configuration server, testing with Spring Cloud Contract or Hoverfly
Stars: ✭ 112 (-59.42%)
Mutual labels:  microservices, spring-boot
Spring Cloud Build
Common build concerns, shared plugin configuration, etc. for Spring Cloud modules
Stars: ✭ 114 (-58.7%)
Mutual labels:  microservices, spring-boot
Digital Restaurant
DDD. Event sourcing. CQRS. REST. Modular. Microservices. Kotlin. Spring. Axon platform. Apache Kafka. RabbitMQ
Stars: ✭ 222 (-19.57%)
Mutual labels:  microservices, spring-boot
Spring Cloud Kubernetes
Kubernetes integration with Spring Cloud Discovery Client, Configuration, etc...
Stars: ✭ 2,894 (+948.55%)
Mutual labels:  microservices, spring-boot

Eventuate Tram Customers and Orders

This application demonstrates two key patterns:

The application consists of three services:

  • Order Service - manages orders
  • Customer Service - manages customers
  • Order History Service - maintains the order history

All services are implemented using Spring Boot, JPA and the https://github.com/eventuate-tram/eventuate-tram-core[Eventuate Tram framework], which provides transactional publish/subscribe.

The Order Service uses a choreography-based saga to enforce the customer's credit limit when creating orders.

The Order History Service implements a CQRS view and subscribes to domain events published by the Order Service and Customer Service

== About Sagas

http://microservices.io/patterns/data/saga.html[Sagas] are a mechanism for maintaining data consistency in a http://microservices.io/patterns/microservices.html[microservice architecture]. A saga is a sequence of transactions, each of which is local to a service.

There are two main ways to coordinate sagas: orchestration and choreography. This example uses choreography-based sagas, which use domain events for coordination. Each step of a saga updates the local database and publishes a domain event. The domain event is processed by an event handler, which performs the next local transaction.

To learn more about why you need sagas if you are using microservices:

=== The Create Order saga

The saga for creating an Order consists of the follow steps:

  1. The Order Service creates an Order in a PENDING state and publishes an OrderCreated event
  2. The Customer Service receives the event attempts to reserve credit for that Order. It publishes either a Credit Reserved event or a CreditLimitExceeded event.
  3. The Order Service receives the event and changes the state of the order to either APPROVED or REJECTED.

== About Command Query Responsibility Segregation (CQRS)

The http://microservices.io/patterns/data/cqrs.html[CQRS pattern] implements queries that retrieves data from multiple services. It maintains a queryable replica of the data by subscribing to domain events published by the services that own the data.

In this example, the Order History Service maintains a CQRS view in MongoDB by subscribing to domain events published by the Order Service and Customer Service. The CQRS view stores each customer as a MongoDB document that contains information the customer and their orders.

To learn more about why you need CQRS if you are using microservices:

== Transactional messaging with Eventuate Tram

The services uses the https://github.com/eventuate-tram/eventuate-tram-core[Eventuate Tram framework] to communicate asynchronously using events. The flow for publishing a domain event using Eventuate Tram is as follows:

  1. Eventuate Tram inserts events into the MESSAGE table as part of the ACID transaction that updates the JPA entity.
  2. The Eventuate Tram CDC service tracks inserts into the MESSAGE table using the MySQL binlog (or Postgres WAL) and publishes messages to Apache Kafka.
  3. A service subscribes to the events, updates its database, and possibly publishes more events.

== Architecture

The following diagram shows the architecture of the Customers and Orders application.

image::./images/Eventuate_Tram_Customer_and_Order_Architecture.png[]

The application consists of three services: Customer Service, Order Service, and Order History Service

=== Customer Service

The Customer Service implements a REST API for managing customers. The service persists the Customer JPA entity in a MySQL/Postgres database. Using Eventuate Tram, it publishes Customer domain events that are consumed by the Order Service.

For more information, see the link:./customer-service-canvas.adoc[microservice canvas for the Customer Service].

image::./customer-service-canvas.png[width=300]

=== Order Service

The Order Service implements REST API for managing orders. The service persists the Order JPA entity in MySQL/Postgres database. Using Eventuate Tram, it publishes Order domain events that are consumed by the Customer Service.

For more information, see the link:./order-service-canvas.adoc[microservice canvas for the Order Service].

image::./order-service-canvas.png[width=300]

=== Order History Service

The Order History Service implements REST API for querying a customer's order history This service subscribes to events published by the Order Service and Customer Service and updates a MongoDB-based CQRS view.

For more information, see the link:./order-history-service-canvas.adoc[microservice canvas for the Order History Service].

image::./order-history-service-canvas.png[width=300]

== Building and running

Note: you do not need to install Gradle since it will be downloaded automatically. You just need to have Java 8 installed.

First, build the application

./gradlew assemble

Next, launch the services using https://docs.docker.com/compose/[Docker Compose]:

./gradlew mysqlbinlogComposeBuild mysqlbinlogComposeUp

Note:

If the containers aren't accessible via localhost - e.g. you are using Docker Toolbox, you will have to use ${DOCKER_HOST_IP} instead of localhost. See this http://eventuate.io/docs/usingdocker.html[guide to setting DOCKER_HOST_IP] for more information.

You can also run the Postgres version using ./gradlew postgrespollingComposeUp or ./gradlew postgreswalComposeUp

== Using the application

Once the application has started, you can use the application via the Swagger UI:

  • Customer Service - http://localhost:8082/swagger-ui.html
  • Order Service - http://localhost:8081/swagger-ui.html
  • Order History Service - http://localhost:8083/swagger-ui.html

You can also use curl to interact with the services. First, let's create a customer:

$ curl -X POST --header "Content-Type: application/json" -d '{
  "creditLimit": {
    "amount": 5
  },
  "name": "Jane Doe"
}' http://localhost:8082/customers

HTTP/1.1 200
Content-Type: application/json;charset=UTF-8

{
  "customerId": 1
}

Next, create an order:

$ curl -X POST --header "Content-Type: application/json" -d '{
  "customerId": 1,
  "orderTotal": {
    "amount": 4
  }
}' http://localhost:8081/orders

HTTP/1.1 200
Content-Type: application/json;charset=UTF-8

{
  "orderId": 1
}

Next, check the status of the Order in the Order Service:

$ curl -X GET http://localhost:8081/orders/1

HTTP/1.1 200
Content-Type: application/json;charset=UTF-8

{
  "orderId": 1,
  "orderState": "APPROVED"
}

Finally, look at the customer's order history in the Order History Service:

$ curl -X GET --header "Accept: */*" "http://localhost:8083/customers/1"

HTTP/1.1 200
Content-Type: application/json;charset=UTF-8

{
  "id": 1,
  "orders": {
    "1": {
      "state": "APPROVED",
      "orderTotal": {
        "amount": 4
      }
    }
  },
  "name": "Chris",
  "creditLimit": {
    "amount": 100
  }
}

== Got questions?

Don't hesitate to create an issue or see

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].