Skip to content

Commit

Permalink
BREAKING CHANGES: modified the entire file structure
Browse files Browse the repository at this point in the history
  • Loading branch information
philipdaquin committed Oct 8, 2023
1 parent 5d0f977 commit ada49ec
Show file tree
Hide file tree
Showing 20 changed files with 68 additions and 116 deletions.
4 changes: 2 additions & 2 deletions recommendation_service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-neo4j</artifactId>
</dependency>
<dependency>
<!-- <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
</dependency> -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
package com.example.recommendation_service.friend_service.consumer;
package com.example.recommendation_service.consumer;

import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.annotation.RetryableTopic;
import org.springframework.kafka.retrytopic.FixedDelayStrategy;
import org.springframework.kafka.support.Acknowledgment;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.retry.annotation.Backoff;
import org.springframework.stereotype.Component;

import com.example.recommendation_service.friend_service.domains.Friend;
import com.example.recommendation_service.friend_service.domains.events.DomainEvent;
import com.example.recommendation_service.friend_service.service.FriendConsumerService;
import com.example.recommendation_service.domains.Friend;
import com.example.recommendation_service.domains.events.FriendDomainEvent;
import com.example.recommendation_service.service.FriendConsumerService;

@Component
public class FriendConsumer {
Expand Down Expand Up @@ -43,7 +42,7 @@ public FriendConsumer(FriendConsumerService service) {
)
@KafkaListener(topics = topic, groupId = consumerId)
public void consume(
ConsumerRecord<String, DomainEvent<Friend>> event,
ConsumerRecord<String, FriendDomainEvent<Friend>> event,
Acknowledgment ack
// @Payload DomainEvent<Friend> event
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.recommendation_service.user_service.consumer;
package com.example.recommendation_service.consumer;

import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.slf4j.Logger;
Expand All @@ -11,17 +11,16 @@
import org.springframework.retry.annotation.Backoff;
import org.springframework.stereotype.Component;

import com.example.recommendation_service.user_service.domains.events.DomainEvent;
import com.example.recommendation_service.user_service.domains.User;
import com.example.recommendation_service.user_service.service.UserConsumerService;
import com.example.recommendation_service.domains.User;
import com.example.recommendation_service.domains.events.UserDomainEvent;
import com.example.recommendation_service.service.UserConsumerService;

@Component
public class UserConsumer {

private static final Logger log = LoggerFactory.getLogger(UserConsumer.class);

private static final String topic = "user";

private final UserConsumerService service;

@Value("${spring.kafka.consumer.group-id}")
Expand All @@ -39,8 +38,7 @@ public UserConsumer(UserConsumerService service) {
)
@KafkaListener(topics = topic, groupId = consumerId)
public void consume(
//ConsumerRecord<String, DomainEvent<User>>
@Payload DomainEvent<User> event
@Payload UserDomainEvent<User> event
// ,
// Acknowledgment ack
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.recommendation_service.user_service.controller;
package com.example.recommendation_service.controller;

import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
Expand All @@ -9,9 +9,9 @@
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

import com.example.recommendation_service.domains.User;
import com.example.recommendation_service.domains.ranked.RankedUser;
import com.example.recommendation_service.repository.Neo4JUserRepository;
import com.example.recommendation_service.user_service.domains.User;
import com.example.recommendation_service.user_service.ranked.RankedUser;

import jakarta.validation.constraints.NotNull;
import reactor.core.publisher.Flux;
Expand All @@ -20,6 +20,8 @@
@RequestMapping("/api/v1")
public class UserController {



private final Neo4JUserRepository repository;

public UserController(Neo4JUserRepository repository) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.recommendation_service.friend_service.domains;
package com.example.recommendation_service.domains;
import java.util.Date;


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.recommendation_service.user_service.domains;
package com.example.recommendation_service.domains;

import java.time.Instant;
import java.util.Date;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.example.recommendation_service.domains.enums;

public enum FriendEventType {
FRIEND_ADDED,
FRIEND_REMOVED
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.recommendation_service.user_service.domains.events;
package com.example.recommendation_service.domains.enums;

public enum UserEventType {
USER_ADDED,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package com.example.recommendation_service.friend_service.domains.events;
package com.example.recommendation_service.domains.events;

import java.io.InputStream;
import java.io.Serializable;
import java.time.Instant;
import java.util.Date;

public class DomainEvent<T> implements Serializable {
import com.example.recommendation_service.domains.enums.FriendEventType;
import com.example.recommendation_service.domains.enums.UserEventType;

public class FriendDomainEvent<T> {

private T subject;
private FriendEventType eventType;
private Date createdDate = Date.from(Instant.now());
private String createdBy;

public DomainEvent(){}
public FriendDomainEvent(){}

public T getSubject() {
return subject;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package com.example.recommendation_service.user_service.domains.events;
package com.example.recommendation_service.domains.events;

import java.time.Instant;
import java.util.Date;

public class DomainEvent<T> {
import com.example.recommendation_service.domains.enums.UserEventType;
public class UserDomainEvent<T> {

private T subject;
private UserEventType eventType;
private Date createdDate = Date.from(Instant.now());
private String createdBy;

public DomainEvent(){}
public UserDomainEvent(){}

public T getSubject() {
return subject;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.example.recommendation_service.user_service.ranked;
package com.example.recommendation_service.domains.ranked;

import com.example.recommendation_service.user_service.domains.User;
import com.example.recommendation_service.domains.User;

public class RankedUser {
private User user;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.example.recommendation_service.exception;

public class IllegalRetryStateException extends RuntimeException {
public IllegalRetryStateException(String message) {
super(message);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
package com.example.recommendation_service.repository;

import java.time.Instant;
import java.util.Date;

import org.springframework.data.neo4j.repository.ReactiveNeo4jRepository;
import org.springframework.data.neo4j.repository.query.Query;
import org.springframework.data.util.Streamable;
import org.springframework.stereotype.Repository;

import com.example.recommendation_service.friend_service.domains.Friend;
import com.example.recommendation_service.user_service.domains.User;
import com.example.recommendation_service.domains.User;

import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;


// @SuppressWarnings("unused")
// @Repository
public interface Neo4JUserRepository extends ReactiveNeo4jRepository<User, Long> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.recommendation_service.friend_service.service;
package com.example.recommendation_service.service;

import java.time.Instant;

Expand All @@ -9,13 +9,13 @@
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.client.HttpClientErrorException;

import com.example.recommendation_service.friend_service.domains.Friend;
import com.example.recommendation_service.friend_service.domains.events.DomainEvent;
import com.example.recommendation_service.domains.Friend;
import com.example.recommendation_service.domains.events.FriendDomainEvent;
import com.example.recommendation_service.domains.enums.FriendEventType;
import com.example.recommendation_service.repository.Neo4JUserRepository;

import reactor.core.publisher.Mono;


@Service
@Transactional
public class FriendConsumerService {
Expand All @@ -28,7 +28,7 @@ public FriendConsumerService(Neo4JUserRepository repository) {
this.repository = repository;
}

public Mono<Friend> apply(DomainEvent<Friend> event) {
public Mono<Friend> apply(FriendDomainEvent<Friend> event) {

Friend friend = event.getSubject();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.recommendation_service.user_service.service;
package com.example.recommendation_service.service;


import java.time.Instant;
Expand All @@ -10,10 +10,9 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.example.recommendation_service.friend_service.service.FriendConsumerService;
import com.example.recommendation_service.domains.User;
import com.example.recommendation_service.domains.events.UserDomainEvent;
import com.example.recommendation_service.repository.Neo4JUserRepository;
import com.example.recommendation_service.user_service.domains.User;
import com.example.recommendation_service.user_service.domains.events.DomainEvent;

import reactor.core.publisher.Mono;

Expand All @@ -34,7 +33,7 @@ public UserConsumerService(Neo4JUserRepository repository) {
*
* @param event
*/
public Mono<User> apply(DomainEvent<User> event) {
public Mono<User> apply(UserDomainEvent<User> event) {

switch (event.getEventType()) {
case USER_ADDED:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@ spring:
on-profile: docker
kafka:

retry:
topic:
enabled: true
attempts: 10

consumer:
auto-offset-reset: earliest

group-id: recommendation-events-listener-group
key-deserializer: org.apache.kafka.common.serialization.IntegerDeserializer
value-deserializer: org.apache.kafka.common.serialization.StringDeserializer
Expand Down
4 changes: 4 additions & 0 deletions recommendation_service/src/main/resources/bootstrap.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
spring:
profiles:
group:
production: default, test, dev, prod, docker, kubernetes
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.example.recommendation_service.friend_service.service.FriendConsumerService;
import com.example.recommendation_service.user_service.domains.User;
import com.example.recommendation_service.user_service.ranked.RankedUser;
import com.example.recommendation_service.domains.User;
import com.example.recommendation_service.domains.ranked.RankedUser;
import com.example.recommendation_service.service.FriendConsumerService;

import org.neo4j.harness.Neo4j;
import org.neo4j.harness.Neo4jBuilders;
Expand Down

0 comments on commit ada49ec

Please sign in to comment.