-
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.
Merge pull request #1 from NiHaiden/dev-rabbit
Merge the initial rabbit configuration
- Loading branch information
Showing
14 changed files
with
158 additions
and
14 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 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
19 changes: 19 additions & 0 deletions
19
src/main/kotlin/tech/niklas/ariesbackend/model/dockerservice/WebsiteService.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,19 @@ | ||
package tech.niklas.ariesbackend.model.dockerservice | ||
|
||
import jakarta.persistence.DiscriminatorValue | ||
import jakarta.persistence.Entity | ||
import tech.niklas.ariesbackend.model.DockerMachine | ||
import tech.niklas.ariesbackend.model.DockerService | ||
import tech.niklas.ariesbackend.model.types.DatabaseType | ||
import tech.niklas.ariesbackend.model.types.ServiceType | ||
|
||
@Entity | ||
@DiscriminatorValue("website-service") | ||
class WebsiteService( | ||
serviceID: String?, | ||
serviceName: String, | ||
serviceType: ServiceType, | ||
serviceMachine: DockerMachine, | ||
serviceUrl: String | ||
) | ||
: DockerService(serviceID, serviceName, serviceType, serviceMachine) |
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
54 changes: 54 additions & 0 deletions
54
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,54 @@ | ||
package tech.niklas.ariesbackend.queue | ||
|
||
import org.springframework.amqp.core.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.amqp.support.converter.Jackson2JsonMessageConverter | ||
import org.springframework.amqp.support.converter.MessageConverter | ||
import org.springframework.beans.factory.annotation.Value | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
import org.springframework.context.annotation.Primary | ||
|
||
@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 jsonMessageConverter(): MessageConverter { | ||
return Jackson2JsonMessageConverter() | ||
} | ||
|
||
@Bean | ||
fun rabbitTemplate(connectionFactory: ConnectionFactory?): RabbitTemplate? { | ||
return connectionFactory?.let { RabbitTemplate(it) } | ||
} | ||
|
||
@Bean | ||
fun dockerDeploy(): Queue { | ||
return Queue("docker.deploy", true) | ||
} | ||
|
||
|
||
} |
8 changes: 8 additions & 0 deletions
8
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,8 @@ | ||
package tech.niklas.ariesbackend.queue | ||
|
||
import org.springframework.amqp.rabbit.annotation.RabbitListener | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class RabbitMQListener { | ||
} |
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
25 changes: 25 additions & 0 deletions
25
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,25 @@ | ||
package tech.niklas.ariesbackend.web | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper | ||
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 | ||
import tech.niklas.ariesbackend.model.DockerAgent | ||
|
||
@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!" | ||
val objectMapper: ObjectMapper = ObjectMapper() | ||
val dockerAgent: DockerAgent = DockerAgent("xxx", "machine1", "secret123", "secret.aries.dev") | ||
rabbitTemplate.convertAndSend(queue.name, objectMapper.writeValueAsString(dockerAgent)) | ||
return "Message sent successfully!" | ||
} | ||
} |
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