-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from lotteon2/develop
Develop
- Loading branch information
Showing
14 changed files
with
481 additions
and
311 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/main/java/com/dailyon/notificationservice/config/NotificationConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
104
src/main/java/com/dailyon/notificationservice/config/RedisConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
// } | ||
} |
28 changes: 28 additions & 0 deletions
28
...ava/com/dailyon/notificationservice/domain/notification/dto/ExtendedNotificationData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
|
24 changes: 24 additions & 0 deletions
24
.../dailyon/notificationservice/domain/notification/dto/NotificationDataWithWhoToNotify.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
Oops, something went wrong.