From 6d8376cfd50d706af5b4219f20b70bad1c13f8c0 Mon Sep 17 00:00:00 2001 From: Chris Richardson Date: Tue, 31 May 2016 15:08:34 -0700 Subject: [PATCH 1/5] Use specific Java 8 Docker image --- java-spring/docker-compose.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/java-spring/docker-compose.yml b/java-spring/docker-compose.yml index 0b1e916..b7199a5 100644 --- a/java-spring/docker-compose.yml +++ b/java-spring/docker-compose.yml @@ -1,5 +1,5 @@ accountscommandside: - image: java:8 + image: java:openjdk-8u91-jdk working_dir: /app volumes: - ./accounts-command-side-service/build/libs:/app @@ -11,7 +11,7 @@ accountscommandside: EVENTUATE_API_KEY_SECRET: transactionscommandside: - image: java:8 + image: java:openjdk-8u91-jdk working_dir: /app volumes: - ./transactions-command-side-service/build/libs:/app @@ -24,11 +24,11 @@ transactionscommandside: accountsqueryside: - image: java:8 + image: java:openjdk-8u91-jdk working_dir: /app volumes: - ./accounts-query-side-service/build/libs:/app - command: java -jar /app/accounts-query-side-service.jar + command: java -jar /app/accounts-query-side-service.jar ports: - "8081:8080" links: From 3117f1240294af0f9f0b16138c36b0a4c04cb5f6 Mon Sep 17 00:00:00 2001 From: Chris Richardson Date: Mon, 6 Jun 2016 20:48:58 -0700 Subject: [PATCH 2/5] Fixed typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index de3fd0a..e6e693f 100644 --- a/README.md +++ b/README.md @@ -96,7 +96,7 @@ First, you need to tell the query side code how to connect to MongoDB: [Docker Compose](https://docs.docker.com/compose/) is a great way to run MongoDB. You can run the `docker-compose up -d mongodb` to run MongoDB. -Second, some of the tests in accounts-command-side-service, transactions-command-side-service, accounts-query-side-service and e2e-test need you need to set some environment variables that tell them how to connect to the Event Store server. +Second, some of the tests in accounts-command-side-service, transactions-command-side-service, accounts-query-side-service and e2e-test require you to set some environment variables that tell them how to connect to the Event Store server. But don't worry. The build is configured to ignore failures for those projects. From b573027fc2b07090cf022d3af882d0e88832202d Mon Sep 17 00:00:00 2001 From: Chris Richardson Date: Fri, 10 Jun 2016 16:43:14 -0700 Subject: [PATCH 3/5] Added Swagger to monolithic deployment, Added mongodb-cli.sh --- README.md | 14 +++++++++++++- java-spring/mongodb-cli.sh | 3 +-- java-spring/monolithic-service/build.gradle | 1 + .../banking/web/BankingWebConfiguration.java | 4 +++- java-spring/show-urls.sh | 7 +++++++ 5 files changed, 25 insertions(+), 4 deletions(-) create mode 100755 java-spring/show-urls.sh diff --git a/README.md b/README.md index de3fd0a..6cfa2c2 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,10 @@ First, you need to tell the query side code how to connect to MongoDB: ``` [Docker Compose](https://docs.docker.com/compose/) is a great way to run MongoDB. -You can run the `docker-compose up -d mongodb` to run MongoDB. +You can run the `docker-compose up -d mongodb` to run MongoDB and then set `SPRING_DATA_MONGODB_URI` as follows: +``` + export SPRING_DATA_MONGODB_URI=mongodb://$(docker-machine ip default)/yourdb +``` Second, some of the tests in accounts-command-side-service, transactions-command-side-service, accounts-query-side-service and e2e-test need you need to set some environment variables that tell them how to connect to the Event Store server. But don't worry. @@ -117,6 +120,15 @@ Simply use this command: java -jar monolithic-service/build/libs/monolithic-service.jar ``` +This will start the service running on port 8080 (you can change using the --server.port=9999 option). + +Once the service has started you can open the Swagger UI: http://localhost:8080/swagger-ui.html. +You can then: + +1. Create two accounts (save the account ids) +2. Create a money transfer +3. View the updated account balances + ## Running the microservices The other option is to run the services separately. diff --git a/java-spring/mongodb-cli.sh b/java-spring/mongodb-cli.sh index a99d99b..d2955c0 100755 --- a/java-spring/mongodb-cli.sh +++ b/java-spring/mongodb-cli.sh @@ -1,4 +1,3 @@ #! /bin/bash -docker run --link javaspring_mongodb_1:mongodb -i -t mongo:3.0.4 /usr/bin/mongo --host mongodb - +docker run --rm --link javaspring_mongodb_1:mongodb -i -t mongo:3.0.4 /usr/bin/mongo --host mongodb diff --git a/java-spring/monolithic-service/build.gradle b/java-spring/monolithic-service/build.gradle index 71d9f26..27ba39e 100644 --- a/java-spring/monolithic-service/build.gradle +++ b/java-spring/monolithic-service/build.gradle @@ -11,6 +11,7 @@ dependencies { compile "org.springframework.boot:spring-boot-starter-actuator" compile "net.chrisrichardson.eventstore.client:eventstore-jdbc_2.10:$eventStoreClientVersion" + compile project(":common-swagger") testCompile project(":testutil") testCompile "org.springframework.boot:spring-boot-starter-test" diff --git a/java-spring/monolithic-service/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/BankingWebConfiguration.java b/java-spring/monolithic-service/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/BankingWebConfiguration.java index a3e2253..656b2fe 100644 --- a/java-spring/monolithic-service/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/BankingWebConfiguration.java +++ b/java-spring/monolithic-service/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/BankingWebConfiguration.java @@ -1,5 +1,6 @@ package net.chrisrichardson.eventstore.javaexamples.banking.web; +import net.chrisrichardson.eventstore.javaexamples.banking.commonswagger.CommonSwaggerConfiguration; import net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.accounts.CommandSideWebAccountsConfiguration; import net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.transactions.CommandSideWebTransactionsConfiguration; import net.chrisrichardson.eventstore.javaexamples.banking.web.queryside.QuerySideWebConfiguration; @@ -14,7 +15,8 @@ import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; @Configuration -@Import({CommandSideWebAccountsConfiguration.class, CommandSideWebTransactionsConfiguration.class, JdbcEventStoreConfiguration.class, QuerySideWebConfiguration.class}) +@Import({CommandSideWebAccountsConfiguration.class, CommandSideWebTransactionsConfiguration.class, JdbcEventStoreConfiguration.class, + QuerySideWebConfiguration.class, CommonSwaggerConfiguration.class}) @EnableAutoConfiguration @ComponentScan public class BankingWebConfiguration { diff --git a/java-spring/show-urls.sh b/java-spring/show-urls.sh new file mode 100755 index 0000000..1b6aacf --- /dev/null +++ b/java-spring/show-urls.sh @@ -0,0 +1,7 @@ +#!/bin/bash -e + +IP=$(docker-machine ip default) + +echo Accounts command-side service = http://${IP}:8080/swagger-ui.html +echo Money Transfers command-side service = http://${IP}:8082/swagger-ui.html +echo Accounts query-side service = http://${IP}:8081/swagger-ui.html From e488df3d064e3ebc08ce9dfa965cb9ff93a411a4 Mon Sep 17 00:00:00 2001 From: Chris Richardson Date: Fri, 10 Jun 2016 16:45:02 -0700 Subject: [PATCH 4/5] Fixed typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6d38f43..57649cf 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ #Event-Sourcing+CQRS example application This example application is the money transfer application described in my talk [Building and deploying microservices with event sourcing, CQRS and Docker](http://plainoldobjects.com/presentations/building-and-deploying-microservices-with-event-sourcing-cqrs-and-docker/). -This talk describe a way of architecting highly scalable and available applications that is based on microservices, polyglot persistence, +This talk describes a way of architecting highly scalable and available applications that is based on microservices, polyglot persistence, event sourcing (ES) and command query responsibility segregation (CQRS). Applications consist of loosely coupled components that communicate using events. These components can be deployed either as separate services or packaged as a monolithic application for simplified development and testing. From d0bdd514069987c1b92c5dfdb83722861ea457cd Mon Sep 17 00:00:00 2001 From: Chris Richardson Date: Thu, 25 Aug 2016 12:15:54 -0700 Subject: [PATCH 5/5] Fixed typo --- java-spring/README.md | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/java-spring/README.md b/java-spring/README.md index 7434865..7909f32 100644 --- a/java-spring/README.md +++ b/java-spring/README.md @@ -7,19 +7,19 @@ This application consists of three microservices: * Account Service - the command side business logic for Accounts * Money Transfer Service - the command side business logic for Money Transfers * Query service - query side implementation of a MongoDB-based, denormalized view of Accounts and MoneyTransfers - + The Account Service consists of the following modules: * accounts-command-side-backend - the Account aggregate * accounts-command-side-web - a REST API for creating and retrieving Accounts * accounts-command-side-service - a standalone microservice - + The Money Transfer Service consists of the following modules: * transactions-command-side-backend - the MoneyTransfer aggregate * transactions-command-side-web - a REST API for creating and retrieving Money Transfers * transactions-command-side-service - a standalone microservice - + The Query Service consists the following modules: * accounts-query-side-backend - MongoDB-based, denormalized view of Accounts and MoneyTransfers @@ -28,10 +28,8 @@ The Query Service consists the following modules: # Deploying the application -These services can be deployed either as either separate standalone services using the Event Store server, or they can be deployed as a monolithic application for simpified integration testing. +These services can be deployed either as either separate standalone services using the Event Store server, or they can be deployed as a monolithic application for simplified integration testing. The three services can also be packaged as a single monolithic web application in order to be used with the embedded Event Store: * monolithic-service - all-in-one, monolithic packaging of the application - -