Skip to content

Commit

Permalink
update :: sync sqs template spring 2..
Browse files Browse the repository at this point in the history
  • Loading branch information
esperar committed Nov 21, 2024
1 parent 2ad4e37 commit f8614c1
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 80 deletions.
5 changes: 3 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ dependencies {
// aws
implementation(Dependencies.AWS_SES)
implementation(Dependencies.KOTLIN_SES)
implementation(Dependencies.AWS_SQS)
implementation(platform(Dependencies.IO_AWS))
implementation("org.springframework.cloud:spring-cloud-aws-messaging:2.2.6.RELEASE")
implementation("org.springframework.cloud:spring-cloud-aws-autoconfigure:2.2.6.RELEASE")



// query dsl
Expand Down
3 changes: 2 additions & 1 deletion buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ object Dependencies {
const val AWS_SES = "com.amazonaws:aws-java-sdk-ses:${DependencyVersions.AWS_SES_VERSION}"
const val KOTLIN_SES = "org.springframework.cloud:spring-cloud-starter-aws"
const val AWS_SQS = "io.awspring.cloud:spring-cloud-aws-starter-sqs"
const val IO_AWS = "io.awspring.cloud:spring-cloud-aws-dependencies:${DependencyVersions.IO_AWS}"
const val AWS_MESSAGING = "org.springframework.cloud:spring-cloud-aws-messaging:${DependencyVersions.IO_AWS}"
const val AWS_AUTOCONF = "org.springframework.cloud:spring-cloud-aws-autoconfigure::${DependencyVersions.IO_AWS}"

// querydsl
const val QUERY_DSL = "com.querydsl:querydsl-jpa:${DependencyVersions.QUERY_DSL_VERSION}"
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/DependencyVersions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ object DependencyVersions {
// aws
const val AWS_SES_VERSION = "1.12.347"
const val KOTLIN_SES_VERSION = "0.16.0"
const val IO_AWS = "3.0.1"
const val IO_AWS = "2.4.0"

// querydsl
const val QUERY_DSL_VERSION = "5.0.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.dotori.v2.domain.music.listener

import com.dotori.v2.global.publisher.EventPublisher
import com.dotori.v2.global.squirrel.MusicDotoriEvent
import io.awspring.cloud.sqs.operations.SendResult
import org.springframework.scheduling.annotation.Async
import org.springframework.stereotype.Component
import org.springframework.transaction.event.TransactionPhase
Expand All @@ -15,8 +14,8 @@ class MusicApplicationEventListener(

@Async("squirrelTaskExecutor")
@TransactionalEventListener(phase = TransactionPhase.AFTER_COMPLETION)
fun onEvent(event: MusicDotoriEvent): SendResult<String> {
return eventPublisher.publishEvent(event, event.eventType.toString())
fun onEvent(event: MusicDotoriEvent) {
eventPublisher.publishEvent(event, event.eventType.toString())
}

}
60 changes: 0 additions & 60 deletions src/main/kotlin/com/dotori/v2/global/config/SQSConfig.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.dotori.v2.global.publisher

import io.awspring.cloud.sqs.operations.SendResult

interface EventPublisher {
fun publishEvent(event: Any, eventType: String): SendResult<String>
fun publishEvent(event: Any, eventType: String)
}
25 changes: 15 additions & 10 deletions src/main/kotlin/com/dotori/v2/global/publisher/SQSEventPublisher.kt
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
package com.dotori.v2.global.publisher

import com.amazonaws.services.sqs.AmazonSQSAsync
import com.fasterxml.jackson.databind.ObjectMapper
import io.awspring.cloud.sqs.operations.SendResult
import io.awspring.cloud.sqs.operations.SqsTemplate
import org.slf4j.LoggerFactory
import org.springframework.cloud.aws.messaging.core.QueueMessagingTemplate
import org.springframework.messaging.support.MessageBuilder
import org.springframework.stereotype.Component

@Component
class SQSEventPublisher(
private val objectMapper: ObjectMapper,
private val sqsTemplate: SqsTemplate
private val amazonSQS: AmazonSQSAsync
) : EventPublisher {

override fun publishEvent(event: Any, eventType: String): SendResult<String> {
return sqsTemplate.send { sendOpsTo ->
sendOpsTo
.queue("squirrel-sqs")
.header("eventType", eventType)
.payload(objectMapper.writeValueAsString(event))
}
private val queueMessagingTemplate = QueueMessagingTemplate(amazonSQS)
private val log = LoggerFactory.getLogger(this::class.java.simpleName)

override fun publishEvent(event: Any, eventType: String) {
val message = MessageBuilder
.withPayload(objectMapper.writeValueAsString(event))
.setHeader("eventType", eventType)
.build()
log.info("publish event {} event-type {}", event, eventType)
queueMessagingTemplate.send("squirrel-sqs", message)
}

}

0 comments on commit f8614c1

Please sign in to comment.