Skip to content

Commit

Permalink
Merge pull request #2 from AleksandraKrasteva/dev
Browse files Browse the repository at this point in the history
Add basic setup and functionality
  • Loading branch information
AleksandraKrasteva authored Mar 21, 2024
2 parents c056ef2 + 827a49d commit 4380308
Show file tree
Hide file tree
Showing 48 changed files with 823 additions and 314 deletions.
22 changes: 13 additions & 9 deletions JourneyService/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
FROM gradle:latest AS build
COPY . /home/gradle/src
WORKDIR /home/gradle/src
COPY . /home
WORKDIR /home
RUN gradle build --no-daemon

FROM amazoncorretto:17-al2023-jdk
FROM eclipse-temurin:17-jre-alpine as builder
WORKDIR application
COPY --from=build home/build/libs/*.jar application.jar
RUN java -Djarmode=layertools -jar application.jar extract

EXPOSE 8020
FROM eclipse-temurin:17-jre-alpine
WORKDIR application
COPY --from=builder application/dependencies/ ./
COPY --from=builder application/spring-boot-loader/ ./
COPY --from=builder application/snapshot-dependencies/ ./
COPY --from=builder application/application/ ./

RUN mkdir /app

COPY --from=build /home/gradle/src/build/libs/*.jar /app/spring-boot-application.jar

ENTRYPOINT ["java","-jar","/app/spring-boot-application.jar"]
ENTRYPOINT ["java", "org.springframework.boot.loader.launch.JarLauncher"]
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@

@Component
public class RabbitMQReceiver {
@RabbitListener(queues = "delete-journey")
public void receiveMessage(String message)
{
System.out.println("Received message in Journey service: " + message);
@RabbitListener(queues = "delete-profile-journey")
public void receiveMessage(String message) {
System.out.println("Received journeys for user:: " + message);
}
}
22 changes: 13 additions & 9 deletions PostManagement/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
FROM gradle:latest AS build
COPY . /home/gradle/src
WORKDIR /home/gradle/src
COPY . /home
WORKDIR /home
RUN gradle build --no-daemon

FROM amazoncorretto:17-al2023-jdk
FROM eclipse-temurin:17-jre-alpine as builder
WORKDIR application
COPY --from=build home/build/libs/*.jar application.jar
RUN java -Djarmode=layertools -jar application.jar extract

EXPOSE 8090
FROM eclipse-temurin:17-jre-alpine
WORKDIR application
COPY --from=builder application/dependencies/ ./
COPY --from=builder application/spring-boot-loader/ ./
COPY --from=builder application/snapshot-dependencies/ ./
COPY --from=builder application/application/ ./

RUN mkdir /app

COPY --from=build /home/gradle/src/build/libs/*.jar /app/spring-boot-application.jar

ENTRYPOINT ["java","-jar","/app/spring-boot-application.jar"]
ENTRYPOINT ["java", "org.springframework.boot.loader.launch.JarLauncher"]
2 changes: 2 additions & 0 deletions PostManagement/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-amqp'
testImplementation 'org.springframework.amqp:spring-rabbit-test'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.postgresql:postgresql'
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.skipass.postmanagement.controllers;

import com.skipass.postmanagement.domain.CreatePostRequest;
import com.skipass.postmanagement.persistance.PostEntity;
import com.skipass.postmanagement.persistance.PostRepository;
import lombok.AllArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin(origins = "http://krakend:8080")
@AllArgsConstructor
public class PostController {

private final PostRepository postRepository;

@PostMapping("/create-post")
public ResponseEntity createPost(@RequestBody CreatePostRequest request) {
PostEntity post = PostEntity.builder().text(request.getText()).userId(request.getUserId()).build();
var response = postRepository.save(post);
return ResponseEntity.ok().body(response.getId());
}

@GetMapping("/view/{userId}")
public ResponseEntity<List<PostEntity>> viewPostsForUser(@PathVariable(value = "userId") long userId) {
List<PostEntity> posts = postRepository.getPostEntitiesByUserIdIs(userId);
return ResponseEntity.ok().body(posts);
}

@DeleteMapping("/delete/{postId}")
public ResponseEntity deletePost(@PathVariable(value = "postId") long postId) {
postRepository.deleteById(postId);
return ResponseEntity.ok().build();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.skipass.postmanagement.domain;

import lombok.Builder;
import lombok.Data;

@Data
@Builder
public class CreatePostRequest {
private String text;
private Long userId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.skipass.postmanagement.messaging;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {
static final String deletePostExchangeName = "delete-post";
static final String statisticsQueueName = "delete-post-stats";

@Bean
public Queue statisticsQueue() {
return new Queue(statisticsQueueName);
}

@Bean
public FanoutExchange deletePostExchange() {
return new FanoutExchange(deletePostExchangeName);
}

@Bean
public Binding statisticsBinding() {
return BindingBuilder.bind(statisticsQueue()).to(deletePostExchange());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.skipass.postmanagement.messaging;

import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class RabbitMQProducer {
@Autowired
private RabbitTemplate rabbitTemplate;

@Autowired
private FanoutExchange deletePostExchange;

public void sendDeleteStatisticsAndReactionsForPostMessage(String message) {
rabbitTemplate.convertAndSend(
deletePostExchange.getName(), "", message);
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
package com.skipass.postmanagement.messaging;

import com.skipass.postmanagement.persistance.PostRepository;
import lombok.AllArgsConstructor;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
@AllArgsConstructor
public class RabbitMQReceiver {
@RabbitListener(queues = "delete-posts")
public void receiveMessage(String message)
{
System.out.println("Received message in Post service: " + message);

private RabbitMQProducer rabbitMQProducer;

private final PostRepository postRepository;

@RabbitListener(queues = "delete-profile-posts")
public void receiveMessage(long userId) {
System.out.println("Received delete posts for user: " + userId);
postRepository.deletePostEntitiesByUserIdIs(userId);
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.skipass.postmanagement.persistance;

import jakarta.persistence.*;
import lombok.*;

@Entity
@Data
@Builder
@Table(name = "posts")
@AllArgsConstructor
@NoArgsConstructor
public class PostEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Long id;

String text;

Long userId;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.skipass.postmanagement.persistance;

import jakarta.transaction.Transactional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository

public interface PostRepository extends JpaRepository<PostEntity, Long> {
List<PostEntity> getPostEntitiesByUserIdIs(long userId);

@Transactional
void deletePostEntitiesByUserIdIs(long userId);

}
9 changes: 8 additions & 1 deletion PostManagement/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,11 @@ spring.application.name=PostManagement
spring.rabbitmq.host=rabbitmq
spring.rabbitmq.port=5672
spring.rabbitmq.username=guest
spring.rabbitmq.password=guest
spring.rabbitmq.password=guest
#DB setup
spring.datasource.url=jdbc:postgresql://user_database:5432/posts
spring.datasource.username=postgres
spring.datasource.password=postgres
spring.jpa.hibernate.ddl-auto=update
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,5 @@
@SpringBootTest
class PostManagementApplicationTests {

@Test
void contextLoads() {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
//@Component
public class RabbitMQReceiver {
@RabbitListener(queues = "delete-reactions")
public void receiveMessage(String message)
{
System.out.println("Received message in Reactions service: " + message);
}
// @RabbitListener(queues = "delete-profile-reactions")
// public void receiveDeleteReactionsForUser(String message)
// {
// System.out.println("Received message in Reactions service: " + message);
// }
//
// @RabbitListener(queues = "delete-post-reaction")
// public void receiveDeleteReactionById(String message)
// {
// System.out.println("Received message in Reactions service: " + message);
// }
}
22 changes: 13 additions & 9 deletions StatisticsService/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
FROM gradle:latest AS build
COPY . /home/gradle/src
WORKDIR /home/gradle/src
COPY . /home
WORKDIR /home
RUN gradle build --no-daemon

FROM amazoncorretto:17-al2023-jdk
FROM eclipse-temurin:17-jre-alpine as builder
WORKDIR application
COPY --from=build home/build/libs/*.jar application.jar
RUN java -Djarmode=layertools -jar application.jar extract

EXPOSE 8030
FROM eclipse-temurin:17-jre-alpine
WORKDIR application
COPY --from=builder application/dependencies/ ./
COPY --from=builder application/spring-boot-loader/ ./
COPY --from=builder application/snapshot-dependencies/ ./
COPY --from=builder application/application/ ./

RUN mkdir /app

COPY --from=build /home/gradle/src/build/libs/*.jar /app/spring-boot-application.jar

ENTRYPOINT ["java","-jar","/app/spring-boot-application.jar"]
ENTRYPOINT ["java", "org.springframework.boot.loader.launch.JarLauncher"]
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@

@Component
public class RabbitMQReceiver {
@RabbitListener(queues = "delete-statistics")
public void receiveMessage(String message)
{
System.out.println("Received message in Statistics service: " + message);
@RabbitListener(queues = "delete-profile-statistics")
public void receiveDeleteStatisticsForUser(String message) {
System.out.println("Received delete user statistics:" + message);
}

@RabbitListener(queues = "delete-post-stats")
public void receiveDeleteStatsForPost(String message) {
System.out.println("Received delete post statistics: " + message);
}
}
Loading

0 comments on commit 4380308

Please sign in to comment.