Skip to content

Instantly share code, notes, and snippets.

@raphaeldelio
Created July 5, 2022 14:01
Show Gist options
  • Select an option

  • Save raphaeldelio/2d5fa0a98f5792d5cac688c59830c327 to your computer and use it in GitHub Desktop.

Select an option

Save raphaeldelio/2d5fa0a98f5792d5cac688c59830c327 to your computer and use it in GitHub Desktop.
@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