Skip to content

Commit

Permalink
chore : 주석처리 카프카
Browse files Browse the repository at this point in the history
  • Loading branch information
seungueonn committed Nov 23, 2023
1 parent 2e18f9a commit 79c2538
Show file tree
Hide file tree
Showing 12 changed files with 161 additions and 93 deletions.
2 changes: 2 additions & 0 deletions src/main/java/gwangjang/server/MemberServiceApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.cloud.openfeign.FeignAutoConfiguration;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.web.bind.annotation.CrossOrigin;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//package gwangjang.server.domain.subscribe.adapter;
//
//import gwangjang.server.domain.subscribe.adapter.producer.web.dto.SubscribeData;
//import gwangjang.server.domain.subscribe.adapter.producer.web.dto.SubscribersByIssueDto;
//import gwangjang.server.domain.subscribe.application.service.SubscribeReadUseCase;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.cloud.stream.messaging.Source;
//import org.springframework.messaging.support.MessageBuilder;
//import org.springframework.stereotype.Component;
//
//import java.util.List;
//
//@Component
//public class PublishSubscribeChange {
//
// @Autowired
// private Source source;
// @Autowired
// private SubscribeReadUseCase subscribeReadUseCase;
//
// public void publishMemberChange() {
// List<SubscribeData> allIssueBySubscribers = subscribeReadUseCase.getAllIssueBySubscribers();
//
// source.output().send(MessageBuilder.withPayload(allIssueBySubscribers).build());
// }
//}
Original file line number Diff line number Diff line change
@@ -1,44 +1,53 @@
package gwangjang.server.domain.subscribe.adapter.consumer.message;
import gwangjang.server.domain.auth.application.mapper.MemberMapper;
import gwangjang.server.global.feign.dto.response.MemberDto;
import gwangjang.server.domain.member.domain.entity.Member;
import gwangjang.server.domain.member.domain.service.MemberQueryService;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.function.Function;

@Configuration
@RequiredArgsConstructor
public class KeywordChannels {

private final MemberQueryService memberQueryService;
private final MemberMapper memberMapper;

//package gwangjang.server.domain.subscribe.adapter.consumer.message;
//import gwangjang.server.domain.auth.application.mapper.MemberMapper;
//import gwangjang.server.domain.subscribe.adapter.producer.web.dto.SubscribeData;
//import gwangjang.server.domain.subscribe.adapter.producer.web.dto.SubscribersByIssueDto;
//import gwangjang.server.global.feign.dto.response.MemberDto;
//import gwangjang.server.domain.member.domain.entity.Member;
//import gwangjang.server.domain.member.domain.service.MemberQueryService;
//import lombok.RequiredArgsConstructor;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//
//import java.util.List;
//import java.util.function.Consumer;
//import java.util.function.Function;
//
//@Configuration
//@RequiredArgsConstructor
//public class KeywordChannels {
//
// private final MemberQueryService memberQueryService;
// private final MemberMapper memberMapper;
//
//// @Bean
//// public Function<String, String> uppercase() { // 메시지를 받아 처리한 후 결과를 반환
//// return message -> {
//// // 메시지 처리 로직
//// return message.toUpperCase();
//// };
////}
// @Bean
// public Function<String, String> uppercase() { // 메시지를 받아 처리한 후 결과를 반환
// return message -> {
// // 메시지 처리 로직
// return message.toUpperCase();
// };
//}
// @Bean
// public Consumer<String> receiveFromCommunity(Long memberId) { //메시지를 받아 처리하는 데 사용되지만 반환 값이 없
// public Consumer<List<SubscribeData>> receiveFromKeyword() { //메시지를 받아 처리하는 데 사용되지만 반환 값이 없
// return message -> {
// // 메시지 처리 로직 ( 역직렬화 )
// System.out.println("Member Received: " + message);
//// System.out.println("Member Received: " + message);
//
//
// System.out.println("hihi"+message);
// };
// }

@Bean
public Function<String, MemberDto> receiveFromKeyword() {
return memberId -> {
// memberId를 사용하여 Member 객체를 조회
Member member = memberQueryService.getMemberBySocialId(memberId);

return memberMapper.mapToMemberDto(member);

};
}
}
//
//// @Bean
//// public Function<String, SubscribersByIssueDto> receiveFromKeyword() {
//// return memberId -> {
//// // memberId를 사용하여 Member 객체를 조회
////
////
//// Member member = memberQueryService.getMemberBySocialId(memberId);
////
//// return memberMapper.mapToMemberDto(member);
////
//// };
//// }
//}
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
package gwangjang.server.domain.subscribe.adapter.consumer.message.model;

import com.fasterxml.jackson.databind.ObjectMapper;
import gwangjang.server.global.feign.dto.response.MemberDto;
import lombok.RequiredArgsConstructor;
import org.apache.kafka.common.header.Headers;
import org.apache.kafka.common.serialization.Deserializer;

import java.util.Map;

@RequiredArgsConstructor
public class KeywordCustomDeserializer implements Deserializer<MemberDto> {

private final ObjectMapper objectMapper;

@Override
public void configure(Map<String, ?> configs, boolean isKey) {
Deserializer.super.configure(configs, isKey);
}

@Override
public MemberDto deserialize(String topic, byte[] data) {
if (data == null) {
return null;
}

try {
return objectMapper.readValue(data, MemberDto.class);
} catch (Exception e) {
throw new RuntimeException("Deserialization error: " + e.getMessage(), e);
}
}

@Override
public MemberDto deserialize(String topic, Headers headers, byte[] data) {
return Deserializer.super.deserialize(topic, headers, data);
}

@Override
public void close() {
Deserializer.super.close();
}
}
//package gwangjang.server.domain.subscribe.adapter.consumer.message.model;
//
//import com.fasterxml.jackson.databind.ObjectMapper;
//import gwangjang.server.global.feign.dto.response.MemberDto;
//import lombok.RequiredArgsConstructor;
//import org.apache.kafka.common.header.Headers;
//import org.apache.kafka.common.serialization.Deserializer;
//
//import java.util.Map;
//
//@RequiredArgsConstructor
//public class KeywordCustomDeserializer implements Deserializer<MemberDto> {
//
// private final ObjectMapper objectMapper;
//
// @Override
// public void configure(Map<String, ?> configs, boolean isKey) {
// Deserializer.super.configure(configs, isKey);
// }
//
// @Override
// public MemberDto deserialize(String topic, byte[] data) {
// if (data == null) {
// return null;
// }
//
// try {
// return objectMapper.readValue(data, MemberDto.class);
// } catch (Exception e) {
// throw new RuntimeException("Deserialization error: " + e.getMessage(), e);
// }
// }
//
// @Override
// public MemberDto deserialize(String topic, Headers headers, byte[] data) {
// return Deserializer.super.deserialize(topic, headers, data);
// }
//
// @Override
// public void close() {
// Deserializer.super.close();
// }
//}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
//package gwangjang.server.domain.subscribe.adapter.producer.message;
//import gwangjang.server.domain.subscribe.adapter.producer.web.dto.SubscribeData;
//import gwangjang.server.domain.subscribe.adapter.producer.web.dto.SubscribersByIssueDto;
//import gwangjang.server.domain.subscribe.application.service.SubscribeReadUseCase;
//import gwangjang.server.global.feign.dto.response.MemberDto;
//import lombok.RequiredArgsConstructor;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.messaging.Message;
Expand All @@ -20,17 +22,17 @@
// private final SubscribeReadUseCase subscribeReadUseCase;
//
// @Bean
// public Supplier<Message<MemberDto>> sendToKeyword() { // 메시지를 주기적으로 생성하고 보내는 데 사용
// public Supplier<Message<List<SubscribeData>>> sendToKeyword() { // 메시지를 주기적으로 생성하고 보내는 데 사용
// return () -> {
//
// log.info("send To Keyword !!!!");
//
//
// List<SubscribersByIssueDto> allIssueBySubscribers = subscribeReadUseCase.getAllIssueBySubscribers();
// List<SubscribeData> allIssueBySubscribers = subscribeReadUseCase.getAllIssueBySubscribers();
// // 메시지 생성 로직
// MemberDto memberInfo = new MemberDto("LOCAL-323","nickname", "https://img");
//// MemberDto memberInfo = new MemberDto("LOCAL-323","nickname", "https://img");
// // dto to string
// return MessageBuilder.withPayload(memberInfo).build();
// return MessageBuilder.withPayload(allIssueBySubscribers).build();
// };
// }
//
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package gwangjang.server.domain.subscribe.adapter.producer.web.dto;

import lombok.*;

@Setter
@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class SubscribeData {
private Long issueId;
private Long count;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@

import lombok.*;

import java.util.List;

@Setter
@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class SubscribersByIssueDto {
private Long issueId;
private Long count;

private List<SubscribeData> data;
}




Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package gwangjang.server.domain.subscribe.application.service;

import gwangjang.server.domain.subscribe.adapter.producer.web.dto.SubscribeData;
import gwangjang.server.domain.subscribe.adapter.producer.web.dto.SubscribersByIssueDto;
import gwangjang.server.domain.subscribe.application.dto.res.IssueBySubscribersRes;
import gwangjang.server.domain.subscribe.application.dto.res.IssueBySubscribeRecommendRes;
Expand Down Expand Up @@ -29,7 +30,7 @@ public IssueSubscribeInfoRes getSubscribeIssueInfo(Long issueId) {
return subscribeQueryService.getIssueInfo(issueId);
}

public List<SubscribersByIssueDto> getAllIssueBySubscribers() {
public List<SubscribeData> getAllIssueBySubscribers() {
return subscribeQueryService.getIssueBySubscribers();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,17 @@ public class SubscribeUseCase {

private final SubscribeMapper subscribeMapper = new SubscribeMapper();

// private final PublishSubscribeChange publishSubscribeChange;


public SubscribeRes subscribe(String socialId,Long topicId, Long issueId) {
Member member = memberQueryService.getMemberBySocialId(socialId);

if (subscribeQueryService.isAbleToSubscribe(member)) {
Subscribe save = subscribeSaveService.save(subscribeMapper.mapToSubscribe(member, issueId));

// publishSubscribeChange.publishMemberChange();

return subscribeMapper.mapToSubscribeRes(save).setSubscribe(subscribeQueryService.getSubscribers(issueId));

}else{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import gwangjang.server.domain.member.domain.entity.Member;
import gwangjang.server.domain.subscribe.adapter.producer.web.dto.MainBubbleRes;
import gwangjang.server.domain.subscribe.adapter.producer.web.dto.SubscribeData;
import gwangjang.server.domain.subscribe.adapter.producer.web.dto.SubscribersByIssueDto;
import gwangjang.server.domain.subscribe.application.dto.res.IssueBySubscribersRes;
import gwangjang.server.domain.subscribe.application.dto.res.SubscribeIssueFeignRes;
Expand All @@ -19,7 +20,7 @@ public interface SubscribeCustomRepository {
Long findSubscribeCountsByIssue(Long issueId);
List<SubscribeIssueFeignRes> findMySubscribeList(Member member);

List<SubscribersByIssueDto> getIssueBySubscribers();
List<SubscribeData> getIssueBySubscribers();



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import gwangjang.server.domain.member.domain.entity.Member;
import gwangjang.server.domain.member.domain.entity.QMember;
import gwangjang.server.domain.subscribe.adapter.producer.web.dto.MainBubbleRes;
import gwangjang.server.domain.subscribe.adapter.producer.web.dto.SubscribeData;
import gwangjang.server.domain.subscribe.adapter.producer.web.dto.SubscribersByIssueDto;
import gwangjang.server.domain.subscribe.application.dto.res.IssueBySubscribersRes;
import gwangjang.server.domain.subscribe.application.dto.res.SubscribeIssueFeignRes;
Expand Down Expand Up @@ -98,10 +99,10 @@ public List<SubscribeIssueFeignRes> findMySubscribeList(Member member) {
.fetch();
}

public List<SubscribersByIssueDto> getIssueBySubscribers() {
public List<SubscribeData> getIssueBySubscribers() {

return queryFactory
.select(Projections.constructor(SubscribersByIssueDto.class,
.select(Projections.constructor(SubscribeData.class,
subscribe.issueId,
subscribe.member.count()
))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import gwangjang.server.domain.FindKeywordFeignClient;
import gwangjang.server.domain.member.domain.entity.Member;
import gwangjang.server.domain.subscribe.adapter.producer.web.dto.MainBubbleRes;
import gwangjang.server.domain.subscribe.adapter.producer.web.dto.SubscribeData;
import gwangjang.server.domain.subscribe.adapter.producer.web.dto.SubscribersByIssueDto;
import gwangjang.server.domain.subscribe.application.dto.res.*;
import gwangjang.server.domain.subscribe.domain.entity.Subscribe;
Expand Down Expand Up @@ -115,7 +116,7 @@ public Long getSubscribers(Long issueId) {
}


public List<SubscribersByIssueDto> getIssueBySubscribers() {
public List<SubscribeData> getIssueBySubscribers() {
return subscribeRepository.getIssueBySubscribers();
}

Expand Down

0 comments on commit 79c2538

Please sign in to comment.