Skip to content

Commit

Permalink
Merge pull request #33 from kusitms-28th-Meetup-E/feat/rabbit
Browse files Browse the repository at this point in the history
feat : rabbitMQ 구현
  • Loading branch information
eojinny authored Nov 23, 2023
2 parents f3b2e28 + e5e152e commit 692e645
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 32 deletions.
5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ ext {
dependencies {

implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'junit:junit:4.13.1'
runtimeOnly 'com.mysql:mysql-connector-j'

implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client:4.0.2'
Expand Down Expand Up @@ -86,6 +87,10 @@ dependencies {
testImplementation 'org.springframework.amqp:spring-rabbit-test'
implementation 'org.springframework.boot:spring-boot-starter-amqp:2.5.4'

testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.mockito:mockito-core'
testImplementation 'org.mockito:mockito-core:3.11.2'

}

dependencyManagement {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public IssueSubscribeInfoRes getSubscribeIssueInfo(Long issueId) {
public List<SubscribeData> getAllIssueBySubscribers() {
return subscribeQueryService.getIssueBySubscribers();
}
//issue Id , counT값 보재문
// 키워드로 보내서
// 메인 url 연결
//키워드랑 영역이랑 맵핑해서



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,28 @@
import gwangjang.server.domain.auth.application.mapper.MemberMapper;
import gwangjang.server.domain.member.domain.entity.Member;
import gwangjang.server.domain.member.domain.service.MemberQueryService;
import gwangjang.server.domain.subscribe.adapter.producer.web.dto.SubscribeData;
import gwangjang.server.domain.subscribe.domain.service.SubscribeQueryService;
import gwangjang.server.global.feign.dto.response.MemberDto;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class MemberFeignUseCase {

private final MemberQueryService memberQueryService;
private final SubscribeQueryService subscribeQueryService;
private final MemberMapper memberMapper = new MemberMapper();


public MemberDto getMemberDto(String socialId) {
Member member = memberQueryService.getMemberBySocialId(socialId);
return memberMapper.mapToMemberDto(member);
}
public List<SubscribeData> getAllIssueBySubscribers() {
return subscribeQueryService.getIssueBySubscribers();
}
}
37 changes: 37 additions & 0 deletions src/main/java/gwangjang/server/global/rabbitMQ/Email.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package gwangjang.server.global.rabbitMQ;

public class Email {

private String to;
private String body;

public Email() {
}

public Email(String to, String body) {
this.to = to;
this.body = body;
}

public String getTo() {
return to;
}

public void setTo(String to) {
this.to = to;
}

public String getBody() {
return body;
}

public void setBody(String body) {
this.body = body;
}

@Override
public String toString() {
return String.format("Email{to=%s, body=%s}", getTo(), getBody());
}

}
31 changes: 31 additions & 0 deletions src/main/java/gwangjang/server/global/rabbitMQ/EmailMsgSender.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package gwangjang.server.global.rabbitMQ;

import gwangjang.server.domain.subscribe.adapter.producer.web.dto.SubscribeData;
import gwangjang.server.domain.subscribe.domain.service.SubscribeQueryService;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EmailMsgSender {

@Autowired
private RabbitTemplate rabbitTemplate;
@Autowired
private SubscribeQueryService subscribeQueryService;

@Autowired
private TopicExchange topic;

public void sendEmail(String routingKey, Email email){
rabbitTemplate.convertAndSend(topic.getName(), routingKey, email);
}
public void sendSubscribeData(String routingKey) {
List<SubscribeData> subscribeDataList = subscribeQueryService.getIssueBySubscribers();
SubscribeDataMessage message = new SubscribeDataMessage(subscribeDataList);
rabbitTemplate.convertAndSend(topic.getName(), routingKey, message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ public RabbitTemplate rabbitTemplate(final ConnectionFactory connectionFactory)
rabbitTemplate.setMessageConverter(producerJackson2MessageConverter());
return rabbitTemplate;
}
}
}
31 changes: 0 additions & 31 deletions src/main/java/gwangjang/server/global/rabbitMQ/Receiver.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package gwangjang.server.global.rabbitMQ;

import gwangjang.server.domain.subscribe.adapter.producer.web.dto.SubscribeData;

import java.io.Serializable;
import java.util.List;

public class SubscribeDataMessage implements Serializable {
private List<SubscribeData> subscribeDataList;

public SubscribeDataMessage() {
// Default constructor needed for deserialization
}

public SubscribeDataMessage(List<SubscribeData> subscribeDataList) {
this.subscribeDataList = subscribeDataList;
}

public List<SubscribeData> getSubscribeDataList() {
return subscribeDataList;
}

public void setSubscribeDataList(List<SubscribeData> subscribeDataList) {
this.subscribeDataList = subscribeDataList;
}
}

0 comments on commit 692e645

Please sign in to comment.