Skip to content

Commit 6859098

Browse files
authored
Merge pull request #9 from Nasruddin/feature/elastic-search
Cleaning up
2 parents 126db5b + 4392b1b commit 6859098

29 files changed

+414
-56
lines changed

.idea/compiler.xml

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/encodings.xml

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/jarRepositories.xml

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations.xml

Lines changed: 0 additions & 10 deletions
This file was deleted.

api-gateway-service/Dockerfile

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#stage 1
2+
#Start with a base image containing Java runtime
3+
FROM openjdk:11-slim as build
4+
5+
# Add Maintainer Info
6+
LABEL maintainer="Nasruddin <[email protected]>"
7+
8+
# The application's jar file
9+
ARG JAR_FILE
10+
11+
# Add the application's jar to the container
12+
COPY ${JAR_FILE} app.jar
13+
14+
#unpackage jar file
15+
RUN mkdir -p target/dependency && (cd target/dependency; jar -xf /app.jar)
16+
17+
#stage 2
18+
#Same Java runtime
19+
FROM openjdk:11-slim
20+
21+
#Add volume pointing to /tmp
22+
VOLUME /tmp
23+
24+
#Copy unpackaged application to new container
25+
ARG DEPENDENCY=/target/dependency
26+
COPY --from=build ${DEPENDENCY}/BOOT-INF/lib /app/lib
27+
COPY --from=build ${DEPENDENCY}/META-INF /app/META-INF
28+
COPY --from=build ${DEPENDENCY}/BOOT-INF/classes /app
29+
30+
#execute the application
31+
ENTRYPOINT ["java","-cp","app:app/lib/*","com.javatab.gatewayservice.ApiGatewayServiceApplication"]

api-gateway-service/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</parent>
1111
<groupId>com.javatab</groupId>
1212
<artifactId>api-gateway-service</artifactId>
13-
<version>0.0.1-SNAPSHOT</version>
13+
<version>1.0.0</version>
1414
<name>api-gateway-service</name>
1515
<description>Gateway Service using spring cloud gateway</description>
1616
<properties>

auth-service/src/main/resources/application.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ spring:
2626
# max-attempts: 3
2727

2828
datasource:
29-
url: jdbc:postgresql://localhost:5432/testdb
29+
url: jdbc:postgresql://postgres_container1:5432/testdb
3030
username: postgres
3131
password: 123
32+
driver-class-name: org.postgresql.Driver
3233
jpa:
3334
properties:
3435
hibernate:

config-server/src/main/resources/application.yml renamed to config-server/src/main/resources/bootstrap.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ management:
2424
include: "*"
2525

2626
eureka:
27+
instance:
28+
prefer-ip-address: true
2729
client:
2830
service-url:
29-
default-zone: http://discoveryservice:8761/eureka/
31+
defaultZone: ${EUREKA_SERVER:http://localhost:8761/eureka}
32+
fetch-registry: true
33+
register-with-eureka: true
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
version: "3.8"
2+
services:
3+
elasticsearch:
4+
image: docker.elastic.co/elasticsearch/elasticsearch:7.7.0
5+
container_name: elasticsearch
6+
environment:
7+
- node.name=elasticsearch
8+
- discovery.type=single-node
9+
- cluster.name=docker-cluster
10+
- bootstrap.memory_lock=true
11+
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
12+
ulimits:
13+
memlock:
14+
soft: -1
15+
hard: -1
16+
# volumes:
17+
# - esdata1:/usr/share/elasticsearch/data
18+
ports:
19+
- "9300:9300"
20+
- "9200:9200"
21+
networks:
22+
- backend
23+
24+
networks:
25+
backend:
26+
driver: bridge
27+
28+
#volumes:
29+
# esdata1:
30+
# driver: local

docker/docker-compose-kafka.yml

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,22 @@ services:
55
ports:
66
- "2181:2181"
77
networks:
8-
backend:
9-
aliases:
10-
- "zookeeper"
8+
- backend
119
kafkaserver:
1210
image: wurstmeister/kafka:latest
1311
ports:
1412
- "9092:9092"
1513
environment:
16-
- KAFKA_ADVERTISED_HOST_NAME=192.168.1.8
14+
- KAFKA_ADVERTISED_HOST_NAME=kafka
1715
- KAFKA_ADVERTISED_PORT=9092
1816
- KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181
19-
- KAFKA_CREATE_TOPICS=users:1:1,students:1:1,userCreatedOutput:1:1
2017
volumes:
2118
- "/var/run/docker.sock:/var/run/docker.sock"
2219
depends_on:
2320
- zookeeper
2421
networks:
25-
backend:
26-
aliases:
27-
- "kafka"
22+
- backend
2823

2924
networks:
3025
backend:
31-
driver: bridge
32-
# redisserver:
33-
# image: redis:alpine
34-
# ports:
35-
# - 6379:6379
36-
# networks:
37-
# backend:
38-
# aliases:
39-
# - "redis"
26+
driver: bridge

docker/docker-compose-postgres.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,11 @@ services:
99
- "5432:5432"
1010
volumes:
1111
- database-data:/var/lib/postgresql/data/ # persist data even if container shuts down
12+
networks:
13+
- backend
1214
volumes:
13-
database-data: # named volumes can be managed easier using docker-compose
15+
database-data: # named volumes can be managed easier using docker-compose
16+
17+
networks:
18+
backend:
19+
driver: bridge

docker/docker-compose-redis.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ services:
55
ports:
66
- "6379:6379"
77
networks:
8-
backend:
9-
aliases:
10-
- "redis"
8+
- backend
119

1210
networks:
1311
backend:

docker/docker-compose.yml

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ services:
66
ports:
77
- "8761:8761"
88
networks:
9-
backend:
10-
aliases:
11-
- "discoveryservice"
9+
- backend
1210
#healthcheck:
1311
# test: [ "CMD", "curl", "-f", "http://discoveryservice:8761/eureka/" ]
1412
# interval: 30s
@@ -22,9 +20,10 @@ services:
2220
ports:
2321
- "8071:8071"
2422
networks:
25-
backend:
26-
aliases:
27-
- "configserver"
23+
- backend
24+
environment:
25+
- JAVA_OPTS=
26+
-DEUREKA_SERVER=http://discoveryservice:8761/eureka
2827
auth-service:
2928
depends_on:
3029
- discoveryservice
@@ -34,9 +33,7 @@ services:
3433
ports:
3534
- "9100:9100"
3635
networks:
37-
backend:
38-
aliases:
39-
- "authservice"
36+
- backend
4037
apigatewayservice:
4138
depends_on:
4239
- discoveryservice
@@ -54,10 +51,7 @@ services:
5451
ports:
5552
- "8200:8200"
5653
networks:
57-
backend:
58-
aliases:
59-
- "course-service"
60-
54+
- backend
6155
networks:
6256
backend:
6357
driver: bridge

pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,7 @@
2424
<module>course-service</module>
2525
<module>api-gateway-service</module>
2626
<module>auth-service</module>
27+
<module>student-service</module>
28+
<module>search-engine</module>
2729
</modules>
2830
</project>

search-engine/Dockerfile

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#stage 1
2+
#Start with a base image containing Java runtime
3+
FROM openjdk:11-slim as build
4+
5+
# Add Maintainer Info
6+
LABEL maintainer="Nasruddin <[email protected]>"
7+
8+
# The application's jar file
9+
ARG JAR_FILE
10+
11+
# Add the application's jar to the container
12+
COPY ${JAR_FILE} app.jar
13+
14+
#unpackage jar file
15+
RUN mkdir -p target/dependency && (cd target/dependency; jar -xf /app.jar)
16+
17+
#stage 2
18+
#Same Java runtime
19+
FROM openjdk:11-slim
20+
21+
#Add volume pointing to /tmp
22+
VOLUME /tmp
23+
24+
#Copy unpackaged application to new container
25+
ARG DEPENDENCY=/target/dependency
26+
COPY --from=build ${DEPENDENCY}/BOOT-INF/lib /app/lib
27+
COPY --from=build ${DEPENDENCY}/META-INF /app/META-INF
28+
COPY --from=build ${DEPENDENCY}/BOOT-INF/classes /app
29+
30+
#execute the application
31+
ENTRYPOINT ["java","-cp","app:app/lib/*","com.javatab.searchengine.SearchEngineApplication"]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.javatab.searchengine;
2+
3+
import com.javatab.searchengine.domain.Student;
4+
import org.springframework.data.repository.reactive.ReactiveCrudRepository;
5+
import org.springframework.stereotype.Repository;
6+
import reactor.core.publisher.Flux;
7+
8+
@Repository
9+
public interface StudentRepository extends ReactiveCrudRepository<Student, String> {
10+
Flux<Student> findStudentByUsername(String username);
11+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.javatab.searchengine.api;
2+
3+
import com.javatab.searchengine.StudentRepository;
4+
import com.javatab.searchengine.domain.Student;
5+
import com.javatab.searchengine.service.StudentService;
6+
import lombok.RequiredArgsConstructor;
7+
import org.springframework.context.annotation.Bean;
8+
import org.springframework.web.bind.annotation.*;
9+
import reactor.core.publisher.Flux;
10+
import reactor.core.publisher.Mono;
11+
12+
import java.io.IOException;
13+
import java.util.function.Supplier;
14+
15+
@RestController
16+
@RequestMapping("/search")
17+
@RequiredArgsConstructor
18+
public class SearchApi {
19+
20+
private final StudentService studentService;
21+
private final StudentRepository studentRepository;
22+
23+
@PostMapping("/create-index")
24+
public Mono<Student> createStudentIndex(@RequestBody Student student) throws IOException {
25+
return studentRepository.save(student);
26+
}
27+
28+
@GetMapping("/id/{userid}")
29+
public Mono<Student> getUserById(@PathVariable("userid") String id) throws IOException {
30+
return studentRepository.findById(id);
31+
}
32+
33+
@GetMapping("/username/{username}")
34+
public Flux<Student> getUserByUsername(@PathVariable("username") String username) throws IOException {
35+
return studentRepository.findStudentByUsername(username);
36+
}
37+
}

0 commit comments

Comments
 (0)