-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
81 additions
and
4 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
43 changes: 43 additions & 0 deletions
43
src/main/kotlin/tech/niklas/ariesbackend/queue/RabbitMQConfig.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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package tech.niklas.ariesbackend.queue | ||
|
||
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory | ||
import org.springframework.amqp.rabbit.connection.ConnectionFactory | ||
import org.springframework.amqp.rabbit.core.RabbitTemplate | ||
import org.springframework.beans.factory.annotation.Value | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
|
||
@Configuration | ||
class RabbitMQConfig { | ||
@Value("\${spring.rabbitmq.host}") | ||
private lateinit var host: String | ||
|
||
@Value("\${spring.rabbitmq.port}") | ||
private var port: Int = 0 | ||
|
||
@Value("\${spring.rabbitmq.username}") | ||
private lateinit var username: String | ||
|
||
@Value("\${spring.rabbitmq.password}") | ||
private lateinit var password: String | ||
|
||
@Bean | ||
fun connectionFactory(): ConnectionFactory { | ||
val connectionFactory = CachingConnectionFactory() | ||
connectionFactory.setHost(host) | ||
connectionFactory.setPort(port) | ||
connectionFactory.username = username | ||
connectionFactory.setPassword(password) | ||
return connectionFactory | ||
} | ||
|
||
@Bean | ||
fun rabbitTemplate(connectionFactory: ConnectionFactory?): RabbitTemplate? { | ||
return connectionFactory?.let { RabbitTemplate(it) } | ||
} | ||
|
||
@Bean | ||
fun dockerDeploy(): org.springframework.amqp.core.Queue { | ||
return org.springframework.amqp.core.Queue("docker.deploy", true) | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/kotlin/tech/niklas/ariesbackend/queue/RabbitMQListener.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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package tech.niklas.ariesbackend.queue | ||
|
||
import org.springframework.amqp.rabbit.annotation.RabbitListener | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class RabbitMQListener { | ||
@RabbitListener(queues = arrayOf("docker.deploy")) | ||
fun processMessage(message: String) { | ||
println("Received message: $message") | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/kotlin/tech/niklas/ariesbackend/web/RabbitController.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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package tech.niklas.ariesbackend.web | ||
|
||
import org.springframework.amqp.core.Queue | ||
import org.springframework.amqp.rabbit.core.RabbitTemplate | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.web.bind.annotation.GetMapping | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
import org.springframework.web.bind.annotation.RestController | ||
|
||
@RestController | ||
@RequestMapping("/rabbit") | ||
class RabbitController(@Autowired private val rabbitTemplate: RabbitTemplate, | ||
@Autowired private val queue: Queue) { | ||
|
||
@GetMapping("/test") | ||
fun sendMessage(): String { | ||
val message: String = "Hello Rabbit!" | ||
rabbitTemplate.convertAndSend(queue.name, message) | ||
return "Message sent successfully!" | ||
} | ||
} |