Created
July 5, 2022 14:01
-
-
Save raphaeldelio/2d5fa0a98f5792d5cac688c59830c327 to your computer and use it in GitHub Desktop.
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 SumNumbersConfiguration { | |
| @Bean | |
| fun generateNumbers(): Supplier<Message<String>> = Supplier<Message<String>> { | |
| val randomNumber1 = Random.nextInt(100) | |
| val randomNumber2 = Random.nextInt(100) | |
| print("$randomNumber1+$randomNumber2=") | |
| MessageBuilder.withPayload( | |
| "$randomNumber1,$randomNumber2" | |
| ).build() | |
| } | |
| @Bean | |
| fun sumNumbers(): Consumer<Message<*>> = Consumer<Message<*>> { message -> | |
| val decodedMessage = (message.payload as ByteArray).decodeToString() | |
| println( | |
| decodedMessage.split(",") | |
| .fold(0) { total, item -> total + item.toInt() } | |
| ) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment