Skip to content

Commit

Permalink
Adding service discovery
Browse files Browse the repository at this point in the history
  • Loading branch information
vr79x committed Dec 6, 2017
1 parent bc2220e commit 524fc5e
Show file tree
Hide file tree
Showing 12 changed files with 360 additions and 6 deletions.
179 changes: 179 additions & 0 deletions CART_SCHEMA/init.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
CREATE SCHEMA microservices_prod;

USE microservices_prod;

DROP TABLE IF EXISTS unit_type;
CREATE TABLE IF NOT EXISTS unit_type(ID BIGINT AUTO_INCREMENT PRIMARY KEY, UNIT_NAME VARCHAR(200) NOT NULL);

DROP TABLE IF EXISTS categories;
CREATE TABLE IF NOT EXISTS categories (
ID BIGINT AUTO_INCREMENT PRIMARY KEY,
CATEGORY_NAME VARCHAR(200) NOT NULL,
unit_type_ID BIGINT NOT NULL,
CONTROLLED BOOLEAN,
FOREIGN KEY (unit_type_ID)
REFERENCES unit_type (ID)
);

SELECT * FROM categories;

DROP TABLE IF EXISTS inventory;
CREATE TABLE IF NOT EXISTS inventory (
ID BIGINT AUTO_INCREMENT PRIMARY KEY,
PRODUCT_NAME VARCHAR(200) NOT NULL,
QUANTITY BIGINT NOT NULL,
UNIT_PRICE DOUBLE(10,4),
PURCHASE_PRICE DOUBLE(10,4),
TAX_RATE INTEGER(99),
CATEGORY_ID BIGINT NOT NULL,
BRAND_NAME VARCHAR(200),
FOREIGN KEY (CATEGORY_ID)
REFERENCES categories (ID)
);
CREATE SCHEMA microservices_invoice;

USE microservices_invoice;

DROP TABLE IF EXISTS mode_of_pay;
CREATE TABLE IF NOT EXISTS mode_of_pay (
ID BIGINT AUTO_INCREMENT PRIMARY KEY,
MODE_NAME VARCHAR(100) NOT NULL,
MODE_DESC VARCHAR(500)
);

DROP TABLE IF EXISTS invoice;
CREATE TABLE IF NOT EXISTS invoice (
ID BIGINT AUTO_INCREMENT PRIMARY KEY,
CUST_ID BIGINT NOT NULL,
ITEM_ID BIGINT NOT NULL,
QUANTITY INTEGER(5),
DATE_OF_PURCHASE DATETIME,
MODE_PAY_ID BIGINT NOT NULL,
TAX_AMT INTEGER,
CASHIER_NAME VARCHAR(500),
FOREIGN KEY (MODE_PAY_ID)
REFERENCES invoice (ID)
);


create schema microservices_cust;

USE microservices_cust;

DROP TABLE IF EXISTS customer;
CREATE TABLE IF NOT EXISTS customer(ID BIGINT AUTO_INCREMENT PRIMARY KEY, CUST_NAME VARCHAR(400) NOT NULL,
CUST_AGE INTEGER(3),MEMBERSHIP_ID BIGINT, CUST_PHONE_NUM BIGINT(10) NOT NULL, ALT_NUM BIGINT(10), PRIMARY_ADDR_ID BIGINT);


DROP TABLE IF EXISTS address;
CREATE TABLE IF NOT EXISTS address(ADDRESS_ID BIGINT AUTO_INCREMENT PRIMARY KEY, CUST_ID BIGINT NOT NULL,APARTMENT_NAME VARCHAR(500),
STREET_NAME VARCHAR(800),CITY VARCHAR(200),STATE VARCHAR(20),PIN INTEGER(10), FOREIGN KEY(CUST_ID) REFERENCES customer(ID));

/*DML---------------- */


USE microservices_prod;

INSERT INTO unit_type(UNIT_NAME) VALUES ('Per Unit');

INSERT INTO unit_type(UNIT_NAME) VALUES ('Per Kg');

SELECT * FROM unit_type;


INSERT INTO categories(unit_type_ID,CATEGORY_NAME,CONTROLLED)
VALUES (1,'CLOTHES',false);

INSERT INTO categories(unit_type_ID,CATEGORY_NAME,CONTROLLED)
VALUES (2,'VEGETABLES',false);

INSERT INTO categories(unit_type_ID,CATEGORY_NAME,CONTROLLED)
VALUES (1,'MEDICINES',true);

INSERT INTO categories(unit_type_ID,CATEGORY_NAME,CONTROLLED)
VALUES (1,'MEDICINES',true);

SELECT * FROM categories;

/*run inventory inserts in a seprate command*/
INSERT INTO inventory(
PRODUCT_NAME,
QUANTITY,
UNIT_PRICE,
PURCHASE_PRICE,
TAX_RATE,
CATEGORY_ID,BRAND_NAME) VALUES('Shirts',
50,
100,
91,
15,
2,'Louis Phillipe');

INSERT INTO inventory(
PRODUCT_NAME,
QUANTITY,
UNIT_PRICE,
PURCHASE_PRICE,
TAX_RATE,
CATEGORY_ID,BRAND_NAME) VALUES('Pants',
100,
100,
91,
15,
2,'Louis Phillipe');

INSERT INTO inventory(
PRODUCT_NAME,
QUANTITY,
UNIT_PRICE,
PURCHASE_PRICE,
TAX_RATE,
CATEGORY_ID) VALUES('Shimla Apples',
1000,
10,
9,
4,
3);

USE microservices_cust;
INSERT INTO customer(CUST_NAME, CUST_AGE, CUST_PHONE_NUM) VALUES('Hitesh Joshi',31,951911009);

INSERT INTO address(CUST_ID,APARTMENT_NAME,STREET_NAME,CITY,STATE,PIN)
VALUES (1,'Hubris Residency','HSR layout','Bangalore','Karanataka',560037);


/*run customer inserts in a separate command*/
INSERT INTO customer(CUST_NAME, CUST_AGE, CUST_PHONE_NUM) VALUES('Deepika Joshi',30,989220110);

INSERT INTO address(CUST_ID,APARTMENT_NAME,STREET_NAME,CITY,STATE,PIN)
VALUES (1,'Vijaya Residency','Allahpur','Bangalore','Karanataka',560037);

INSERT INTO address(CUST_ID,APARTMENT_NAME,STREET_NAME,CITY,STATE,PIN)
VALUES (2,'Vijaya Residency','KareemNagar','Allahbad','UP',560037);

INSERT INTO address(CUST_ID,APARTMENT_NAME,STREET_NAME,CITY,STATE,PIN)
VALUES (1,'Muir Road','Near Bus stand','Almora','Uttarakhand',262501);



UPDATE customer
SET
PRIMARY_ADDR_ID = 1
WHERE
ID = 1;

USE microservices_invoice;
insert into mode_of_pay(MODE_NAME,MODE_DESC) values('Cash','OTC cash settlement');
insert into mode_of_pay(MODE_NAME,MODE_DESC) values('Card','OTC card settlement');
insert into mode_of_pay(MODE_NAME,MODE_DESC) values('Online','Online through payment gateway');
insert into mode_of_pay(MODE_NAME,MODE_DESC) values('Wallet','OTC through wallet');

select * from mode_of_pay;

/*run invoice inserts in a seprate command*/

insert into invoice(CUST_ID,ITEM_ID,QUANTITY,DATE_OF_PURCHASE,MODE_PAY_ID,TAX_AMT,CASHIER_NAME) values(1,4,10,NOW(),2,5,'Venu Babu');
insert into invoice(CUST_ID,ITEM_ID,QUANTITY,DATE_OF_PURCHASE,MODE_PAY_ID,TAX_AMT,CASHIER_NAME) values(1,3,10,'2017-10-01 00:00:00',2,5,'Venu Babu');

select * from invoice;

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ To build and package a jar to target folder :<BR>


To start the Mysql container: <BR>
<b><code>docker run --name docker-mysql -e MYSQL_ROOT_PASSWORD=test -d mysql</code></b>
<b><code>docker run --name docker-mysql -e MYSQL_ROOT_PASSWORD=test -P -d mysql</code></b>


To Build the image from Docker File - Custom image as specified in the Dockerfile ---> (Note the .) <br>
Expand Down
4 changes: 2 additions & 2 deletions customer/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ spring:
hibernate:
ddl-auto: none
datasource:
url: jdbc:mysql://localhost:32769/microservices_cust
url: jdbc:mysql://localhost:32768/microservices_cust
username: root
password: test
# thymeleaf:
Expand All @@ -31,7 +31,7 @@ server:
eureka:
client:
serviceUrl:
defaultZone: http://eureka:1111/eureka/ # using eureka instead of localhost
defaultZone: http://localhost:32770/eureka/ # using eureka instead of localhost
instance:
leaseRenewalIntervalInSeconds: 5 # DO NOT DO THIS IN PRODUCTION

Expand Down
36 changes: 36 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
eureka:
image: springcloud/eureka
container_name: eureka
ports:
- "1111:1111"
net: "microservicesnet"
customer1:
image: hiteshjoshi1/microservice-docker-cart-example
container_name: customer1
hostname: customer1
net: "microservicesnet"
ports:
- "2222:8080"
volumes:
- C:\\Users\\hitjoshi\\Desktop\\Microservices\\ci_output:/data
command: -jar -Dspring.datasource.url=jdbc:mysql://docker-mysql/microservices_cust -Dspring.datasource.password=test /data/customer-0.0.1-SNAPSHOT.jar
inventory1:
image: hiteshjoshi1/microservice-docker-cart-example
container_name: inventory1
hostname: inventory1
net: "microservicesnet"
ports:
- "3333:8080"
volumes:
- C:\\Users\\hitjoshi\\Desktop\\Microservices\\ci_output:/data
command: -jar -Dspring.datasource.url=jdbc:mysql://docker-mysql/microservices_prod -Dspring.datasource.password=test /data/inventory-0.0.1-SNAPSHOT.jar
invoice1:
image: hiteshjoshi1/microservice-docker-cart-example
container_name: invoice1
hostname: invoice1
net: "microservicesnet"
ports:
- "4444:8080"
volumes:
- C:\\Users\\hitjoshi\\Desktop\\Microservices\\ci_output:/data
command: -jar -Dspring.datasource.url=jdbc:mysql://docker-mysql/microservices_invoice -Dspring.datasource.password=test /data/invoice-0.0.1-SNAPSHOT.jar
2 changes: 1 addition & 1 deletion inventory/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ VOLUME /tmp
ADD /target/inventory-0.0.1-SNAPSHOT.jar app.jar
EXPOSE 8080
RUN bash -c 'touch /app.jar'
ENTRYPOINT ["java","-Dspring.datasource.url=jdbc:mysql://docker-mysql/microservices_prod","-Dspring.datasource.username=root","-Dspring.datasource.password=test","-jar","/app.jar"]
ENTRYPOINT ["java","-Dspring.datasource.url=jdbc:mysql://docker-mysql/microservices_invoice","-Dspring.datasource.username=root","-Dspring.datasource.password=test","-jar","/app.jar"]
4 changes: 2 additions & 2 deletions invoice/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM java:8
VOLUME /tmp
ADD /target/inventory-0.0.1-SNAPSHOT.jar app.jar
ADD /target/invoice-0.0.1-SNAPSHOT.jar app.jar
EXPOSE 8080
RUN bash -c 'touch /app.jar'
ENTRYPOINT ["java","-Dspring.datasource.url=jdbc:mysql://docker-mysql/microservices_prod","-Dspring.datasource.username=root","-Dspring.datasource.password=test","-jar","/app.jar"]
ENTRYPOINT ["java","-Dspring.datasource.url=jdbc:mysql://docker-mysql/microservices_invoice","-Dspring.datasource.username=root","-Dspring.datasource.password=test","-jar","/app.jar"]
24 changes: 24 additions & 0 deletions servicediscovery/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
target/
!.mvn/wrapper/maven-wrapper.jar

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr

### NetBeans ###
nbproject/private/
build/
nbbuild/
dist/
nbdist/
.nb-gradle/
6 changes: 6 additions & 0 deletions servicediscovery/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM java:8
VOLUME /tmp
ADD /target/servicediscovery-0.0.1-SNAPSHOT.jar app.jar
EXPOSE 1111
RUN bash -c 'touch /app.jar'
ENTRYPOINT ["java","-jar","/app.jar"]
64 changes: 64 additions & 0 deletions servicediscovery/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.hitesh.microservices</groupId>
<artifactId>servicediscovery</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>servicediscovery</name>
<description>Eureka Service</description>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>Edgware.RELEASE</spring-cloud.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>


<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>


</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.hitesh.microservices.servicediscovery;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

@SpringBootApplication
@EnableEurekaServer
public class ServiceDiscoveryApplication {

public static void main(String[] args) {
SpringApplication.run(ServiceDiscoveryApplication.class, args);
}
}
15 changes: 15 additions & 0 deletions servicediscovery/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Configure this Discovery Server
eureka:
instance:
hostname: localhost
client: # Not a client, don't register with yourself
registerWithEureka: false
fetchRegistry: false

server:
port: 1111 # HTTP (Tomcat) port

# Discovery Server Dashboard uses FreeMarker. Don't want Thymeleaf templates
spring:
thymeleaf:
enabled: false # Disable Thymeleaf
Loading

0 comments on commit 524fc5e

Please sign in to comment.