Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Deploy]: 운영서버 배포 24/02/21 #159

Merged
merged 11 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public AuthResponse.Token reissueToken(String accessToken, String refreshToken)

@Transactional
public void signOut(Long userId) {
User user = userQueryHandler.findByIdAndStatus(userId, Status.ACTIVE);
User user = userQueryHandler.findByIdFetch(userId);
userSignOutPolicy.validate(user);
user.withDraw();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public WebSecurityCustomizer webSecurityCustomizer() {
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http.formLogin(AbstractHttpConfigurer::disable)
.httpBasic(AbstractHttpConfigurer::disable)
.cors(it -> it.configurationSource(corsConfigurationSource()))
.cors(AbstractHttpConfigurer::disable)
.csrf(AbstractHttpConfigurer::disable)
.sessionManagement(it -> it.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.authorizeHttpRequests(it -> it.anyRequest().authenticated())
Expand All @@ -64,17 +64,4 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
.addFilterBefore(new JwtExceptionHandleFilter(), JwtAuthenticationFilter.class);
return http.build();
}

@Bean
public CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration configuration = new CorsConfiguration();
configuration.addAllowedOriginPattern("*");
configuration.setAllowedMethods(Arrays.asList("*"));
configuration.setAllowedHeaders(Arrays.asList("*"));
configuration.setAllowCredentials(true);

UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", configuration);
return source;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import com.gloddy.server.batch.messaging.producer.MessagingBatchEventProducer;
import com.gloddy.server.core.error.handler.exception.BatchBusinessException;
import com.gloddy.server.outbox.domain.handler.OutboxEventQueryHandler;
import com.gloddy.server.outbox.domain.handler.GroupOutboxEventQueryHandler;
import com.gloddy.server.outbox.domain.handler.UserOutboxEventQueryHandler;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.EnableScheduling;
Expand All @@ -17,22 +18,30 @@
public class MessagingScheduler {

private final MessagingBatchEventProducer messagingBatchEventProducer;
private final OutboxEventQueryHandler outboxEventQueryHandler;
private final GroupOutboxEventQueryHandler groupOutboxEventQueryHandler;
private final UserOutboxEventQueryHandler userOutboxEventQueryHandler;

@Transactional
@Scheduled(cron = "0 * * * * *", zone = "Asia/Seoul")
public void rePublishEvent() {
executeJob(() -> outboxEventQueryHandler.findAllByNotPublished()
.forEach(messagingBatchEventProducer::produceEvent));
public void rePublishGroupEvent() {
executeJob(() -> groupOutboxEventQueryHandler.findAllByNotPublished()
.forEach(messagingBatchEventProducer::produceEvent), "group");
}

private void executeJob(Runnable runnable) {
log.info("Messaging rePublishEvent publishGroupEndEvent 스케줄러 시작");
@Transactional
@Scheduled(cron = "0 * * * * *", zone = "Asia/Seoul")
public void rePublishUserEvent() {
executeJob(() -> userOutboxEventQueryHandler.findAllByNotPublished()
.forEach(messagingBatchEventProducer::produceEvent), "user");
}

private void executeJob(Runnable runnable, String domain) {
log.info("Messaging " + domain + " rePublishEvent 스케줄러 시작");
try {
runnable.run();
} catch (Exception e) {
throw new BatchBusinessException(e);
}
log.info("Messaging rePublishEvent publishGroupEndEvent 스케줄러 완료");
log.info("Messaging " + domain + " rePublishEvent 스케줄러 완료");
}
}
24 changes: 0 additions & 24 deletions src/main/java/com/gloddy/server/config/WebConfig.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ public class GroupMemberService {
private final GroupMemberJpaRepository userGroupJpaRepository;

public GroupResponse.GetGroups getExpectedMyGroup(Long userId) {
User findUser = userQueryHandler.findByIdAndStatus(userId, Status.ACTIVE);
User findUser = userQueryHandler.findByIdFetch(userId);
List<Group> expectedMyGroups = userGroupJpaRepository.findExpectedGroupsByUser(findUser);
return expectedMyGroups.stream()
.map(GroupResponse.GetGroup::from)
.collect(Collectors.collectingAndThen(Collectors.toList(), GroupResponse.GetGroups::new));
}

public PageResponse<GroupResponse.GetParticipatedGroup> getParticipatedMyGroup(Long userId, int page, int size) {
User findUser = userQueryHandler.findByIdAndStatus(userId, Status.ACTIVE);
User findUser = userQueryHandler.findByIdFetch(userId);
return PageResponse.from(
userGroupJpaRepository.findParticipatedGroupsByUser(findUser, PageRequest.of(page, size))
.map(GroupResponse.GetParticipatedGroup::from)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@
import static com.gloddy.server.config.AsyncConfig.EVENT_HANDLER_TASK_EXECUTOR;

import com.gloddy.server.messaging.MessagePublisher;
import com.gloddy.server.outbox.domain.Event;
import com.gloddy.server.outbox.domain.dto.OutboxEventPayload;
import com.gloddy.server.outbox.domain.handler.OutboxEventCommandHandler;
import com.gloddy.server.outbox.domain.handler.OutboxEventQueryHandler;
import com.gloddy.server.outbox.domain.GroupEvent;
import com.gloddy.server.outbox.domain.UserEvent;
import com.gloddy.server.outbox.domain.dto.GroupOutboxEventPayload;
import com.gloddy.server.outbox.domain.dto.UserOutboxEventPayload;
import com.gloddy.server.outbox.domain.handler.GroupOutboxEventCommandHandler;
import com.gloddy.server.outbox.domain.handler.GroupOutboxEventQueryHandler;
import com.gloddy.server.outbox.domain.handler.UserOutboxEventCommandHandler;
import com.gloddy.server.outbox.domain.handler.UserOutboxEventQueryHandler;
import lombok.RequiredArgsConstructor;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.event.TransactionPhase;
import org.springframework.transaction.event.TransactionalEventListener;

Expand All @@ -18,14 +23,26 @@
public class OutboxEventConsumer {

private final MessagePublisher messagePublisher;
private final OutboxEventQueryHandler outboxEventQueryHandler;
private final OutboxEventCommandHandler outboxEventCommandHandler;
private final GroupOutboxEventQueryHandler groupOutboxEventQueryHandler;
private final GroupOutboxEventCommandHandler groupOutboxEventCommandHandler;
private final UserOutboxEventCommandHandler userOutboxEventCommandHandler;
private final UserOutboxEventQueryHandler userOutboxEventQueryHandler;

@Async(EVENT_HANDLER_TASK_EXECUTOR)
@TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT)
public void handle(OutboxEventPayload payload) {
Event outboxEvent = outboxEventQueryHandler.findById(payload.getId());
@Transactional
public void handle(GroupOutboxEventPayload payload) {
GroupEvent outboxEvent = groupOutboxEventQueryHandler.findById(payload.getId());
groupOutboxEventCommandHandler.updatePublished(outboxEvent.getId());
messagePublisher.publishEvent(outboxEvent.getEvent(), outboxEvent.getEventType());
outboxEventCommandHandler.updatePublished(outboxEvent.getId());
}

@Async(EVENT_HANDLER_TASK_EXECUTOR)
@TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT)
@Transactional
public void handle(UserOutboxEventPayload payload) {
UserEvent userEvent = userOutboxEventQueryHandler.findById(payload.getId());
userOutboxEventCommandHandler.updatePublished(userEvent.getId());
messagePublisher.publishEvent(userEvent.getEvent(), userEvent.getEventType());
}
}
6 changes: 5 additions & 1 deletion src/main/java/com/gloddy/server/messaging/sns/Topic.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ public enum Topic {
APPROACHING_GROUP("모임 시작이 임박할 때", "group-article-topic"),
END_GROUP("모임이 완료됏을 때", "group-article-topic"),

GROUP_MEMBER_LEAVE("그룹 멤버가 모임을 나갔을 때", "group-member-topic");
GROUP_MEMBER_LEAVE("그룹 멤버가 모임을 나갔을 때", "group-member-topic"),
JOIN("유저가 회원가입 했을 때", "user-topic"),
UPDATE_PROFILE("유저가 프로필을 수정했을 때", "user-topic"),
UPGRADE_RELIABILITY("유저의 신뢰도가 업데이트 됐을 때", "user-topic")
;

private final String description;
private final String topicProperty;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.gloddy.server.outbox.adapter;

public interface IGroupAdapterEvent extends AdapterEvent {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.gloddy.server.outbox.adapter;

public interface IUserAdapterEvent extends AdapterEvent {
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.gloddy.server.outbox.adapter.apply.event;

import com.gloddy.server.outbox.adapter.AdapterEvent;
import java.time.LocalDateTime;

import com.gloddy.server.outbox.adapter.IGroupAdapterEvent;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
Expand All @@ -10,7 +11,7 @@
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
@Getter
public class ApplyAdapterEvent implements AdapterEvent {
public class ApplyAdapterEvent implements IGroupAdapterEvent {
private Long applyId;
private ApplyEventType eventType;
private LocalDateTime eventDateTime;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.gloddy.server.outbox.adapter.group.event;

import com.gloddy.server.outbox.adapter.AdapterEvent;
import java.time.LocalDateTime;

import com.gloddy.server.outbox.adapter.IGroupAdapterEvent;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
Expand All @@ -10,7 +11,7 @@
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
@Getter
public class GroupAdapterEvent implements AdapterEvent {
public class GroupAdapterEvent implements IGroupAdapterEvent {
private Long groupId;
private GroupEventType eventType;
private LocalDateTime eventDateTime;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.gloddy.server.outbox.adapter.group.event;

import com.gloddy.server.outbox.adapter.AdapterEvent;
import java.time.LocalDateTime;

import com.gloddy.server.outbox.adapter.IGroupAdapterEvent;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
Expand All @@ -10,7 +11,7 @@
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
@Getter
public class GroupArticleAdapterEvent implements AdapterEvent {
public class GroupArticleAdapterEvent implements IGroupAdapterEvent {
private Long articleId;
private GroupArticleEventType eventType;
private LocalDateTime eventDateTime;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.gloddy.server.outbox.adapter.group.event;

import com.gloddy.server.outbox.adapter.AdapterEvent;
import java.time.LocalDateTime;

import com.gloddy.server.outbox.adapter.IGroupAdapterEvent;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
Expand All @@ -10,7 +11,7 @@
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
@Getter
public class GroupMemberAdapterEvent implements AdapterEvent {
public class GroupMemberAdapterEvent implements IGroupAdapterEvent {
private Long groupId;
private Long userId;
private GroupMemberEventType eventType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import com.gloddy.server.outbox.adapter.group.event.GroupMemberAdapterEvent;
import com.gloddy.server.outbox.adapter.group.mapper.GroupEventMapper;
import com.gloddy.server.outbox.application.OutboxEventSaveService;
import com.gloddy.server.outbox.event.producer.OutboxEventProducer;
import lombok.RequiredArgsConstructor;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.gloddy.server.outbox.adapter.user.event;

import com.gloddy.server.outbox.adapter.AdapterEvent;
import com.gloddy.server.outbox.adapter.IUserAdapterEvent;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.time.LocalDateTime;

@AllArgsConstructor
@Getter
public class UserAdapterEvent implements IUserAdapterEvent {

private Long userId;
private UserEventType eventType;
private LocalDateTime eventDateTime;

@Override
public String getEventType() {
return eventType.name();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.gloddy.server.outbox.adapter.user.event;

import com.gloddy.server.outbox.adapter.AdapterEvent;

public enum UserEventType {
JOIN,
UPDATE_PROFILE,
UPGRADE_RELIABILITY
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.gloddy.server.outbox.adapter.user.handler;

import com.gloddy.server.outbox.adapter.user.event.UserAdapterEvent;
import com.gloddy.server.outbox.adapter.user.mapper.UserEventMapper;
import com.gloddy.server.outbox.application.OutboxEventSaveService;
import com.gloddy.server.user.event.UserCreateEvent;
import com.gloddy.server.user.event.UserProfileUpdateEvent;
import com.gloddy.server.user.event.UserReliabilityUpgradeEvent;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import org.springframework.transaction.event.TransactionPhase;
import org.springframework.transaction.event.TransactionalEventListener;

@Component
@RequiredArgsConstructor
public class UserAdapterHandler {

private final OutboxEventSaveService outboxEventSaveService;

@TransactionalEventListener(phase = TransactionPhase.BEFORE_COMMIT)
public void handle(UserCreateEvent userCreateEvent) {
UserAdapterEvent adapterEvent = UserEventMapper.toAdapterEvent(userCreateEvent);
outboxEventSaveService.save(adapterEvent);
}

@TransactionalEventListener(phase = TransactionPhase.BEFORE_COMMIT)
public void handle(UserProfileUpdateEvent userProfileUpdateEvent) {
UserAdapterEvent adapterEvent = UserEventMapper.toAdapterEvent(userProfileUpdateEvent);
outboxEventSaveService.save(adapterEvent);
}

@TransactionalEventListener(phase = TransactionPhase.BEFORE_COMMIT)
public void handle(UserReliabilityUpgradeEvent userReliabilityUpgradeEvent) {
UserAdapterEvent adapterEvent = UserEventMapper.toAdapterEvent(userReliabilityUpgradeEvent);
outboxEventSaveService.save(adapterEvent);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.gloddy.server.outbox.adapter.user.mapper;

import com.gloddy.server.outbox.adapter.user.event.UserAdapterEvent;
import com.gloddy.server.outbox.adapter.user.event.UserEventType;
import com.gloddy.server.user.event.UserCreateEvent;
import com.gloddy.server.user.event.UserProfileUpdateEvent;
import com.gloddy.server.user.event.UserReliabilityUpgradeEvent;

import java.time.LocalDateTime;

public class UserEventMapper {

public static UserAdapterEvent toAdapterEvent(UserCreateEvent userCreateEvent) {
return new UserAdapterEvent(
userCreateEvent.getUser().getId(),
UserEventType.JOIN,
LocalDateTime.now()
);
}

public static UserAdapterEvent toAdapterEvent(UserProfileUpdateEvent userProfileUpdateEvent) {
return new UserAdapterEvent(
userProfileUpdateEvent.getUserId(),
UserEventType.UPDATE_PROFILE,
LocalDateTime.now()
);
}

public static UserAdapterEvent toAdapterEvent(UserReliabilityUpgradeEvent userReliabilityUpgradeEvent) {
return new UserAdapterEvent(
userReliabilityUpgradeEvent.getUserId(),
UserEventType.UPGRADE_RELIABILITY,
LocalDateTime.now()
);
}
}
Loading
Loading