Skip to content

Commit

Permalink
Merge pull request #25 from lotteon2/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
CessnaJ authored Jan 14, 2024
2 parents 28f34dc + 41b49da commit d815a97
Show file tree
Hide file tree
Showing 14 changed files with 481 additions and 311 deletions.
9 changes: 1 addition & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,15 @@ ext {
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-webflux'
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb-reactive'
implementation 'org.springframework.boot:spring-boot-starter-data-redis-reactive'
// implementation 'de.flapdoodle.embed:de.flapdoodle.embed.mongo'

// implementation 'org.springframework.boot:spring-boot-starter-web' // non-blocking model of WebFlux 위해 제거
// implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
// implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'



implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.4.RELEASE'
implementation 'org.springframework.cloud:spring-cloud-aws-messaging:2.2.4.RELEASE'
// implementation 'org.springframework.cloud:spring-cloud-aws-messaging'
// implementation 'software.amazon.awssdk:sqs'


implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.cloud:spring-cloud-starter-zipkin:2.2.3.RELEASE'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.dailyon.notificationservice.config;


import org.springframework.context.annotation.Configuration;


public class NotificationConfig {
public static final String NOTIFICATIONS_STREAM_KEY = "notifications:stream";
}
104 changes: 104 additions & 0 deletions src/main/java/com/dailyon/notificationservice/config/RedisConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package com.dailyon.notificationservice.config;


import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

import lombok.RequiredArgsConstructor;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.Profile;
import org.springframework.core.env.Environment;
import org.springframework.data.redis.connection.*;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.core.ReactiveRedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializationContext;
import org.springframework.data.redis.serializer.StringRedisSerializer;

@Configuration
@RequiredArgsConstructor
public class RedisConfig {
private final Environment env;

@Bean
@Profile(value = "!prod")
public ReactiveRedisConnectionFactory standaloneRedisConnectionFactory() {
RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration();
redisStandaloneConfiguration.setHostName(
Objects.requireNonNull(env.getProperty("spring.redis.host")));
redisStandaloneConfiguration.setPort(
Integer.parseInt(Objects.requireNonNull(env.getProperty("spring.redis.port"))));
redisStandaloneConfiguration.setPassword(env.getProperty("spring.redis.password"));

return new LettuceConnectionFactory(redisStandaloneConfiguration);
}

@Bean
@Profile("prod")
public ReactiveRedisConnectionFactory clusterRedisConnectionFactory() {
RedisClusterConfiguration clusterConfiguration = new RedisClusterConfiguration();
clusterConfiguration.setClusterNodes(
parseRedisNodes(Objects.requireNonNull(env.getProperty("spring.redis.cluster.nodes"))));
// String password = env.getProperty("spring.redis.password"); // 필요시 추가
// if (password != null && !password.isEmpty()) {
// clusterConfiguration.setPassword(password);
// }
return new LettuceConnectionFactory(clusterConfiguration);
}

private Set<RedisNode> parseRedisNodes(String nodes) {
Set<RedisNode> redisNodes = new HashSet<>();

for (String node : Objects.requireNonNull(nodes).split(",")) {
String[] parts = node.split(":");
redisNodes.add(new RedisNode(parts[0], Integer.parseInt(parts[1])));
}
return redisNodes;
}

@Bean
@Primary
public ReactiveRedisTemplate<String, String> reactiveRedisStringTemplate(ReactiveRedisConnectionFactory factory) {
StringRedisSerializer keySerializer = new StringRedisSerializer();
StringRedisSerializer valueSerializer = new StringRedisSerializer();

RedisSerializationContext<String, String> serializationContext = RedisSerializationContext
.<String, String>newSerializationContext(keySerializer)
.hashKey(keySerializer)
.hashValue(valueSerializer)
.string(valueSerializer)
.build();

return new ReactiveRedisTemplate<>(factory, serializationContext);
}


// @Bean
// public ReactiveStringRedisTemplate reactiveStringRedisTemplate(ReactiveRedisConnectionFactory factory) {
// return new ReactiveStringRedisTemplate(factory, RedisSerializationContext.string());
// }

// @Bean
// public ReactiveRedisTemplate<String, String> reactiveStringRedisTemplate(
// ReactiveRedisConnectionFactory factory) {
// StringRedisSerializer keySerializer = new StringRedisSerializer();
// StringRedisSerializer valueSerializer = new StringRedisSerializer();

// RedisSerializationContext.RedisSerializationContextBuilder<String, String> builder =
// RedisSerializationContext.newSerializationContext(keySerializer);
// RedisSerializationContext<String, String> context = builder.value(valueSerializer).build();
// return new ReactiveRedisTemplate<>(factory, context);
// return new ReactiveStringRedisTemplate(factory, RedisSerializationContext.string());
// }



// @Bean
// public <V> ReactiveRedisTemplate<String, V> reactiveRedisTemplate(
// ReactiveRedisConnectionFactory factory, RedisSerializationContext<String, V> serializationContext) {
// return new ReactiveRedisTemplate<>(factory, serializationContext);
// }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.dailyon.notificationservice.domain.notification.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import reactor.core.publisher.Mono;

import java.util.List;
import java.util.Map;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class ExtendedNotificationData {
private List<Long> whoToNotify;
private NotificationData notificationData;
private Map<String, String> parameters;
public static ExtendedNotificationData of(List<Long> whoToNotify, NotificationData notificationData, Map<String, String> parameters) {
return ExtendedNotificationData.builder()
.whoToNotify(whoToNotify)
.notificationData(notificationData)
.parameters(parameters)
.build();
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.dailyon.notificationservice.domain.notification.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class NotificationDataWithWhoToNotify {
List<Long> whoToNotify;
NotificationData notificationData;

public static NotificationDataWithWhoToNotify create(List<Long> whoToNotify, NotificationData notificationData) {
return NotificationDataWithWhoToNotify.builder()
.whoToNotify(whoToNotify)
.notificationData(notificationData)
.build();
}
}
Loading

0 comments on commit d815a97

Please sign in to comment.