Skip to content

Commit

Permalink
Merge pull request #96 from soma-baekgu/feature/BG-349-kafka-record-p…
Browse files Browse the repository at this point in the history
…artitioning

[BG-349]: Kafka 파티셔너에서 알림 순서를 유지하는 형태로 파티셔닝 되도록 수정 (1h / 1h)
  • Loading branch information
GGHDMS authored Aug 23, 2024
2 parents ab983a3 + 2b49955 commit 8134d3c
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,10 @@ import java.io.Serializable

interface Notification : Serializable {
val method: NotificationMethod
val keyPrefix: String
val keyValue: String

fun getNotificationKey(): String {
return "$keyPrefix:$keyValue"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,10 @@ import com.backgu.amaker.domain.user.UserDevice
class PushNotification(
override val method: NotificationMethod,
val userDevices: List<UserDevice>,
) : Notification
) : Notification {
override val keyPrefix: String
get() = "PUSH"

override val keyValue: String
get() = userDevices.first().userId
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,10 @@ import com.backgu.amaker.domain.user.User
class UserFulfilledNotification(
val user: User,
override val method: RealTimeNotificationMethod,
) : RealTimeBasedNotification(method)
) : RealTimeBasedNotification(method) {
override val keyPrefix: String
get() = "USER"

override val keyValue: String
get() = user.id
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,10 @@ import com.backgu.amaker.domain.notifiacation.method.RealTimeNotificationMethod
open class UserNotification(
val userId: String,
override val method: RealTimeNotificationMethod,
) : RealTimeBasedNotification(method)
) : RealTimeBasedNotification(method) {
override val keyPrefix: String
get() = "USER"

override val keyValue: String
get() = userId
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,10 @@ import com.backgu.amaker.domain.notifiacation.method.RealTimeNotificationMethod
open class WorkspaceNotification(
open val workspaceId: Long,
override val method: RealTimeNotificationMethod,
) : RealTimeBasedNotification(method)
) : RealTimeBasedNotification(method) {
override val keyPrefix: String
get() = "WORKSPACE"

override val keyValue: String
get() = workspaceId.toString()
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ class KafkaNotificationEventService(
private val kafkaTemplate: KafkaTemplate<String, Notification>,
) : NotificationEventService {
override fun publishNotificationEvent(notification: Notification) {
kafkaTemplate.send(KafkaConfig.NOTIFICATION_TOPIC, notification)
kafkaTemplate.send(KafkaConfig.NOTIFICATION_TOPIC, notification.getNotificationKey(), notification)
}
}

0 comments on commit 8134d3c

Please sign in to comment.