Skip to content

Commit

Permalink
Merge pull request #28 from lotteon2/feat/scheduling-to-empty-redis-s…
Browse files Browse the repository at this point in the history
…treams

Feat/scheduling to empty redis streams - 2nd
  • Loading branch information
wakkpu authored Jan 14, 2024
2 parents b9ac8c8 + 8c0e4cf commit de2eb2b
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,40 +21,40 @@
@Profile("local")
public class DataInitializerConfig {

@Bean
CommandLineRunner initData(ReactiveMongoTemplate template) {
return args -> {
NotificationTemplate template1 = NotificationTemplate.builder()
.message("0000 아이템이 재입고되었습니다.")
.linkUrl("http://example.com/product/12345")
.notificationType(NotificationType.PRODUCT_RESTOCK)
.createdAt(Instant.now())
.updatedAt(Instant.now())
.build();

RestockNotification restockNotification1 = RestockNotification.builder()
.productId(1L)
.sizeId(1L)
.memberIds(Set.of(101L, 102L, 103L))
.build();

// Reactive operations는 non-blocking이라서 subscribe call이 필요함.
// NotificationTemplate 객체 저장 후, UserNotification에 받아온 NotificationTemplate id를 넣음
template.save(template1).flatMap(savedTemplate -> {
HashSet<String> unreadNotifications = new HashSet<>();
unreadNotifications.add(savedTemplate.getId());

UserNotification userNotification1 = UserNotification.builder()
.memberId(1L)
.createdAt(Instant.now())
.unread(unreadNotifications)
.build();

return template.save(userNotification1);
}).subscribe();

// Save the RestockNotification object
template.save(restockNotification1).subscribe();
};
}
// @Bean
// CommandLineRunner initData(ReactiveMongoTemplate template) {
// return args -> {
// NotificationTemplate template1 = NotificationTemplate.builder()
// .message("0000 아이템이 재입고되었습니다.")
// .linkUrl("http://example.com/product/12345")
// .notificationType(NotificationType.PRODUCT_RESTOCK)
// .createdAt(Instant.now())
// .updatedAt(Instant.now())
// .build();
//
// RestockNotification restockNotification1 = RestockNotification.builder()
// .productId(1L)
// .sizeId(1L)
// .memberIds(Set.of(101L, 102L, 103L))
// .build();
//
// // Reactive operations는 non-blocking이라서 subscribe call이 필요함.
// // NotificationTemplate 객체 저장 후, UserNotification에 받아온 NotificationTemplate id를 넣음
// template.save(template1).flatMap(savedTemplate -> {
// HashSet<String> unreadNotifications = new HashSet<>();
// unreadNotifications.add(savedTemplate.getId());
//
// UserNotification userNotification1 = UserNotification.builder()
// .memberId(1L)
// .createdAt(Instant.now())
// .unread(unreadNotifications)
// .build();
//
// return template.save(userNotification1);
// }).subscribe();
//
// // Save the RestockNotification object
// template.save(restockNotification1).subscribe();
// };
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class RedisConfig {

@Bean
@Profile(value = "!prod")
@Primary
public ReactiveRedisConnectionFactory standaloneRedisConnectionFactory() {
RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration();
redisStandaloneConfiguration.setHostName(
Expand All @@ -38,6 +39,7 @@ public ReactiveRedisConnectionFactory standaloneRedisConnectionFactory() {

@Bean
@Profile("prod")
@Primary
public ReactiveRedisConnectionFactory clusterRedisConnectionFactory() {
RedisClusterConfiguration clusterConfiguration = new RedisClusterConfiguration();
clusterConfiguration.setClusterNodes(
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;
import org.springframework.scheduling.annotation.EnableScheduling;

@Configuration
@EnableScheduling
public class SchedulingConfig {
}
2 changes: 1 addition & 1 deletion src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ spring:
username: root
password: 11111111
uri: mongodb://root:11111111@localhost:27017/notification-service?authSource=admin
auto-index-creation: true
auto-index-creation: false
redis:
host: redis-cluster
port: 6379
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ spring:
username: root
password: 11111111
uri: mongodb://root:11111111@localhost:27017/notification-service?authSource=admin
auto-index-creation: true
auto-index-creation: false
redis:
host: 127.0.0.1
port: 6379
Expand Down

0 comments on commit de2eb2b

Please sign in to comment.