-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update :: sync sqs template spring 2..
- Loading branch information
Showing
7 changed files
with
24 additions
and
80 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
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
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
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
This file was deleted.
Oops, something went wrong.
4 changes: 1 addition & 3 deletions
4
src/main/kotlin/com/dotori/v2/global/publisher/EventPublisher.kt
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 |
---|---|---|
@@ -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
25
src/main/kotlin/com/dotori/v2/global/publisher/SQSEventPublisher.kt
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 |
---|---|---|
@@ -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) | ||
} | ||
|
||
} |