This file contains hidden or 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
| @Bean | |
| fun jsonDirectBinding(): Binding { | |
| return BindingBuilder | |
| .bind(jsonQueue) | |
| .to(directExchange()) | |
| .with("TO-JSON-QUEUE") | |
| .noargs() | |
| } |
This file contains hidden or 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
| @Bean | |
| fun messageConverter(objectMapper: ObjectMapper): MessageConverter { | |
| return Jackson2JsonMessageConverter(objectMapper) | |
| } |
This file contains hidden or 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
| data class Person( | |
| val name: String, | |
| val collageCompletedYear: Int?, | |
| val bornAt: LocalDate, | |
| val active: Boolean | |
| ) |
This file contains hidden or 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
| @Service | |
| class BasicListener : MessageListener { | |
| private val log = LoggerFactory.getLogger(javaClass) | |
| override fun onMessage(message: Message?) { | |
| log.info("receive message from ${message?.messageProperties?.consumerQueue}") | |
| val bodyAsString = message?.body?.let { String(it) } ?: "" | |
| log.info("body $bodyAsString") | |
| } |
This file contains hidden or 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
| @Bean | |
| fun queueBasic(): Queue { | |
| return QueueBuilder | |
| .durable("FIRST-QUEUE-BASIC") | |
| .build() | |
| } | |
| @Bean | |
| fun listenerContainer(): MessageListenerContainer { | |
| val container = SimpleMessageListenerContainer() |
This file contains hidden or 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
| @PostMapping("{exchange}/{routingKey}") | |
| fun postOnExchange( | |
| @PathVariable exchange: String, | |
| @PathVariable routingKey: String, | |
| @RequestBody message: String | |
| ): HttpEntity<Any?> { | |
| log.info("sending message $message") | |
| rabbitTemplate.convertAndSend(exchange, routingKey, message) | |
| return ResponseEntity.ok().build() | |
| } |
This file contains hidden or 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
| @Configuration | |
| class DirectConfig( | |
| private val firstQueue: Queue, | |
| private val secondQueue: Queue | |
| ) { | |
| @Bean | |
| fun directExchange(): Exchange { | |
| return ExchangeBuilder | |
| .directExchange("DIRECT-EXCHANGE-BASIC") | |
| .durable(true) |
This file contains hidden or 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
| @Configuration | |
| class QueueConfig { | |
| @Bean | |
| fun firstQueue(): Queue { | |
| return QueueBuilder | |
| .durable("FIRST-QUEUE-BASIC") | |
| .build() | |
| } | |
| @Bean |
This file contains hidden or 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
| @Configuration | |
| class FeignConfiguration( | |
| private val messageConverters: ObjectFactory<HttpMessageConverters>, | |
| @Value("\${feign-builder.client.readTimeout:10000}") | |
| private val readTimeout: Int, | |
| @Value("\${feign-builder.client.connectionTimeout:10000}") | |
| private val connectionTimeout: Int | |
| ) { | |
| fun feignDecoder(): Decoder { |
This file contains hidden or 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
| @Service | |
| class ClientService(private val feignBuilder: Feign.Builder) { | |
| private val log = LoggerFactory.getLogger(javaClass) | |
| @Cacheable("someHttpClient") | |
| fun getClient(url: String): SomeHttpClient { | |
| log.info("M=QueueBalancer, without cache") | |
| return feignBuilder.target(SomeHttpClient::class.java, url) | |
| } |