Skip to content
This repository was archived by the owner on May 21, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.xiangronglin.novel.rest.application.infratructure

import com.xiangronglin.novel.worker.api.Queue
import org.apache.activemq.ActiveMQConnectionFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.context.annotation.Bean
Expand All @@ -12,10 +13,6 @@ import org.springframework.jms.core.JmsTemplate
@Configuration
class AmqConfigurator {

companion object {
const val NOVEL_QUEUE = "novel"
}

@Autowired
private lateinit var configManager: ConfigManager

Expand All @@ -27,14 +24,14 @@ class AmqConfigurator {
connectionFactory.brokerURL = amqConfig.url
connectionFactory.userName = amqConfig.username
connectionFactory.password = amqConfig.password.value
connectionFactory.trustedPackages = listOf("com.xiangronglin.novelservice")
connectionFactory.trustedPackages = listOf("com.xiangronglin.novel")
return connectionFactory
}

@Bean
fun jmsTemplate(): JmsTemplate {
val template = JmsTemplate(connectionFactory())
template.defaultDestinationName = NOVEL_QUEUE
template.defaultDestinationName = Queue.NOVEL
return template
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.xiangronglin.novel.rest.application.service.novel

import com.xiangronglin.novel.rest.application.db.NovelRepository
import com.xiangronglin.novel.worker.api.NovelResultMessage
import com.xiangronglin.novel.worker.api.Queue
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.jms.annotation.JmsListener
import org.springframework.stereotype.Component
import java.util.*

@Component
class NovelResultListener(
@Autowired private val novelRepository: NovelRepository
) {

companion object {
private val LOG = LoggerFactory.getLogger(NovelResultListener::class.java)
}

@JmsListener(destination = Queue.NOVEL_RESULT)
fun processResult(result: NovelResultMessage) {
LOG.info("Received novel result : '$result'")

val novel = novelRepository.findById(UUID.fromString(result.novelId)).get()
novel.status = result.status.toString()
novel.fileId = result.fileKey

novelRepository.save(novel)
}
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<dependency>
<groupId>com.github.NovelService.NovelWorker</groupId>
<artifactId>novel-worker-api</artifactId>
<version>dfff744f5cd903bc62897de54d476fca68c9bfe3</version>
<version>bf59966b0335882ba1cb86cabe151c2ef7d24a15</version>
</dependency>

<!-- Kotlin -->
Expand Down