Skip to content

Commit

Permalink
Adding order history.
Browse files Browse the repository at this point in the history
  • Loading branch information
dartartem committed Mar 19, 2018
1 parent 678b811 commit add6ac9
Show file tree
Hide file tree
Showing 50 changed files with 1,011 additions and 16 deletions.
2 changes: 1 addition & 1 deletion _build-and-test-all.sh
Expand Up @@ -19,7 +19,7 @@ docker-compose -f docker-compose-${DATABASE?}.yml up -d --build cdcservice

docker-compose -f docker-compose-${DATABASE?}.yml up -d --build

./wait-for-services.sh $DOCKER_HOST_IP "8081 8082"
./wait-for-services.sh $DOCKER_HOST_IP "8081 8082 8083"

./gradlew :end-to-end-tests:cleanTest :end-to-end-tests:test

Expand Down
15 changes: 15 additions & 0 deletions buildSrc/src/main/groovy/VerifyMongoDBConfigurationPlugin.groovy
@@ -0,0 +1,15 @@
import org.gradle.api.*


class VerifyMongoDBConfigurationPlugin implements Plugin<Project> {
void apply(Project project) {
project.test {
beforeSuite { x ->
if (x.parent == null) {
if (System.getenv("SPRING_DATA_MONGODB_URI") == null)
throw new RuntimeException("Please make sure that the environment variable SPRING_DATA_MONGODB_URI is set, e.g. export SPRING_DATA_MONGODB_URI=mongodb://192.168.59.103/mydb")
}
}
}
}
}
@@ -0,0 +1,42 @@
package io.eventuate.examples.tram.ordersandcustomers.commondomain;

import io.eventuate.tram.events.common.DomainEvent;

public class CustomerCreatedEvent implements DomainEvent {
private Long customerId;
private String name;
private Money creditLimit;

public CustomerCreatedEvent() {
}

public CustomerCreatedEvent(Long customerId, String name, Money creditLimit) {
this.customerId = customerId;
this.name = name;
this.creditLimit = creditLimit;
}

public Long getCustomerId() {
return customerId;
}

public void setCustomerId(Long customerId) {
this.customerId = customerId;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public Money getCreditLimit() {
return creditLimit;
}

public void setCreditLimit(Money creditLimit) {
this.creditLimit = creditLimit;
}
}
Expand Up @@ -5,18 +5,24 @@
public class CustomerCreditReservationFailedEvent implements DomainEvent {

private Long orderId;
private OrderDetails orderDetails;

public CustomerCreditReservationFailedEvent() {
}

public CustomerCreditReservationFailedEvent(Long orderId) {
public CustomerCreditReservationFailedEvent(Long orderId, OrderDetails orderDetails) {
this.orderId = orderId;
this.orderDetails = orderDetails;
}

public Long getOrderId() {
return orderId;
}

public OrderDetails getOrderDetails() {
return orderDetails;
}

public void setOrderId(Long orderId) {
this.orderId = orderId;
}
Expand Down
Expand Up @@ -5,18 +5,24 @@
public class CustomerCreditReservedEvent implements DomainEvent {

private Long orderId;
private OrderDetails orderDetails;

public CustomerCreditReservedEvent() {
}

public CustomerCreditReservedEvent(Long orderId) {
public CustomerCreditReservedEvent(Long orderId, OrderDetails orderDetails) {
this.orderId = orderId;
this.orderDetails = orderDetails;
}

public Long getOrderId() {
return orderId;
}

public OrderDetails getOrderDetails() {
return orderDetails;
}

public void setOrderId(Long orderId) {
this.orderId = orderId;
}
Expand Down
@@ -0,0 +1,3 @@
package io.eventuate.examples.tram.ordersandcustomers.commondomain;

public enum OrderState { PENDING, APPROVED, REJECTED }
1 change: 1 addition & 0 deletions customer-backend/build.gradle
Expand Up @@ -2,6 +2,7 @@ dependencies {
compile project(":common")

compile "io.eventuate.tram.core:eventuate-tram-jdbc-kafka:$eventuateTramVersion"
compile "io.eventuate.tram.core:eventuate-tram-events:$eventuateTramVersion"

compile 'mysql:mysql-connector-java:5.1.36'
compile ('org.postgresql:postgresql:9.4-1200-jdbc41') {
Expand Down
Expand Up @@ -39,6 +39,14 @@ public Long getId() {
return id;
}

public String getName() {
return name;
}

public Money getCreditLimit() {
return creditLimit;
}

public void reserveCredit(Long orderId, Money orderTotal) {
if (availableCredit().isGreaterThanOrEqual(orderTotal)) {
creditReservations.put(orderId, orderTotal);
Expand Down
@@ -1,17 +1,31 @@
package io.eventuate.examples.tram.ordersandcustomers.customers.service;

import io.eventuate.examples.tram.ordersandcustomers.commondomain.CustomerCreatedEvent;
import io.eventuate.examples.tram.ordersandcustomers.commondomain.Money;
import io.eventuate.examples.tram.ordersandcustomers.customers.domain.Customer;
import io.eventuate.examples.tram.ordersandcustomers.customers.domain.CustomerRepository;
import io.eventuate.tram.events.publisher.DomainEventPublisher;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Collections;

public class CustomerService {

@Autowired
private CustomerRepository customerRepository;

@Autowired
private DomainEventPublisher domainEventPublisher;

public Customer createCustomer(String name, Money creditLimit) {
Customer customer = new Customer(name, creditLimit);
return customerRepository.save(customer);
customer = customerRepository.save(customer);

domainEventPublisher.publish(Customer.class,
customer.getId(),
Collections.singletonList(new CustomerCreatedEvent(customer.getId(),
customer.getName(), customer.getCreditLimit())));

return customer;
}
}
Expand Up @@ -42,7 +42,8 @@ private void orderCreatedEventHandler(DomainEventEnvelope<OrderCreatedEvent> dom
orderCreatedEvent.getOrderDetails().getOrderTotal());

CustomerCreditReservedEvent customerCreditReservedEvent =
new CustomerCreditReservedEvent(orderCreatedEvent.getOrderId());
new CustomerCreditReservedEvent(orderCreatedEvent.getOrderId(),
orderCreatedEvent.getOrderDetails());

domainEventPublisher.publish(Customer.class,
customer.getId(),
Expand All @@ -51,7 +52,9 @@ private void orderCreatedEventHandler(DomainEventEnvelope<OrderCreatedEvent> dom
} catch (CustomerCreditLimitExceededException e) {

CustomerCreditReservationFailedEvent customerCreditReservationFailedEvent =
new CustomerCreditReservationFailedEvent(orderCreatedEvent.getOrderId());
new CustomerCreditReservationFailedEvent(orderCreatedEvent.getOrderId(),
orderCreatedEvent.getOrderDetails());


domainEventPublisher.publish(Customer.class,
customer.getId(),
Expand Down
Expand Up @@ -3,14 +3,12 @@
import io.eventuate.examples.tram.ordersandcustomers.customers.web.CustomerWebConfiguration;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

@SpringBootApplication
@Import({CustomerConfiguration.class, CustomerWebConfiguration.class})
public class CustomersServiceMain {
public class CustomerServiceMain {
public static void main(String[] args) {
SpringApplication.run(CustomersServiceMain.class, args);
SpringApplication.run(CustomerServiceMain.class, args);
}
}
28 changes: 28 additions & 0 deletions docker-compose-mysql.yml
Expand Up @@ -36,6 +36,26 @@ customerservice:
EVENTUATELOCAL_KAFKA_BOOTSTRAP_SERVERS: kafka:9092
EVENTUATELOCAL_ZOOKEEPER_CONNECTION_STRING: zookeeper:2181

orderhistoryservice:
build: ./order-history-view-service/
ports:
- "8083:8080"
links:
- mongodb
- mysql
- kafka
- zookeeper
environment:
SPRING_DATA_MONGODB_URI: mongodb://mongodb/clients_and_orders
SPRING_DATASOURCE_URL: jdbc:mysql://mysql/eventuate
SPRING_DATASOURCE_USERNAME: mysqluser
SPRING_DATASOURCE_PASSWORD: mysqlpw
SPRING_DATASOURCE_DRIVER_CLASS_NAME: com.mysql.jdbc.Driver
EVENTUATELOCAL_KAFKA_BOOTSTRAP_SERVERS: kafka:9092
EVENTUATELOCAL_ZOOKEEPER_CONNECTION_STRING: zookeeper:2181
EVENTUATELOCAL_CDC_DB_USER_NAME: root
EVENTUATELOCAL_CDC_DB_PASSWORD: rootpassword

zookeeper:
image: eventuateio/eventuateio-local-zookeeper:0.17.0.RELEASE
ports:
Expand Down Expand Up @@ -65,6 +85,14 @@ mysql:
- MYSQL_USER=mysqluser
- MYSQL_PASSWORD=mysqlpw


mongodb:
image: mongo:3.0.4
hostname: mongodb
command: mongod --smallfiles
ports:
- "27017:27017"

cdcservice:
image: eventuateio/eventuate-tram-cdc-mysql-service:0.6.0.RELEASE
ports:
Expand Down
35 changes: 35 additions & 0 deletions docker-compose-postgres.yml
Expand Up @@ -54,6 +54,33 @@ customerservice:
EVENTUATELOCAL_CDC_SOURCE_TABLE_NAME: message
SPRING_PROFILES_ACTIVE: EventuatePolling

orderhistoryservice:
build: ./order-history-view-service/
ports:
- "8083:8080"
links:
- mongodb
- postgres
- kafka
- zookeeper
environment:
SPRING_DATA_MONGODB_URI: mongodb://mongodb/clients_and_orders
SPRING_DATASOURCE_URL: jdbc:postgresql://postgres/eventuate
SPRING_DATASOURCE_USERNAME: eventuate
SPRING_DATASOURCE_PASSWORD: eventuate
SPRING_DATASOURCE_TEST_ON_BORROW: "true"
SPRING_DATASOURCE_VALIDATION_QUERY: SELECT 1
SPRING_DATASOURCE_DRIVER_CLASS_NAME: org.postgresql.Driver
EVENTUATELOCAL_CDC_POLLING_INTERVAL_IN_MILLISECONDS: 500
EVENTUATELOCAL_CDC_MAX_EVENTS_PER_POLLING: 1000
EVENTUATELOCAL_CDC_MAX_ATTEMPTS_FOR_POLLING: 100
EVENTUATELOCAL_CDC_POLLING_RETRY_INTERVAL_IN_MILLISECONDS: 500
EVENTUATELOCAL_KAFKA_BOOTSTRAP_SERVERS: kafka:9092
EVENTUATELOCAL_ZOOKEEPER_CONNECTION_STRING: zookeeper:2181
EVENTUATELOCAL_CDC_BINLOG_CLIENT_ID: 1234567890
EVENTUATELOCAL_CDC_SOURCE_TABLE_NAME: message
SPRING_PROFILES_ACTIVE: EventuatePolling

zookeeper:
image: eventuateio/eventuateio-local-zookeeper:0.17.0.RELEASE
ports:
Expand Down Expand Up @@ -82,6 +109,14 @@ postgres:
POSTGRES_USER: eventuate
POSTGRES_PASSWORD: eventuate


mongodb:
image: mongo:3.0.4
hostname: mongodb
command: mongod --smallfiles
ports:
- "27017:27017"

cdcservice:
image: eventuateio/eventuate-tram-cdc-mysql-service:0.6.0.RELEASE
ports:
Expand Down
1 change: 1 addition & 0 deletions end-to-end-tests/build.gradle
@@ -1,4 +1,5 @@
dependencies {
compile project(":order-history-common")
compile project(":customer-web-api")
compile project(":order-web-api")

Expand Down

0 comments on commit add6ac9

Please sign in to comment.