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
{ | |
"type": "record", | |
"name": "SubscriptionRequest", | |
"namespace": "com.felipeassoline.subscription.payment.api", | |
"fields": [ | |
{"name": "cardNumber", "type": ["string", "null"]}, | |
{"name": "secret", "type": ["string", "null"]}, | |
{"name": "status", "type": ["string", "null"]} | |
] | |
} |
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
cloud.stream: | |
bindings.output: | |
destination: payment-approval-topic | |
contentType: application/*+avro | |
schema: | |
avro: | |
schema-locations: classpath:avro/schema.avsc | |
schema-registry-client: | |
endpoint: http://localhost:8080 |
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
@SpringBootApplication | |
@EnableSchemaRegistryServer | |
public class SchemaRegistryServerApplication { | |
public static void main(String[] args) { | |
SpringApplication.run(SchemaRegistryServerApplication.class, args); | |
} | |
} |
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
func testWhateverINeed() { | |
// Given | |
// create here the mocked data needed to call the method below | |
// When | |
// call here the method you will test | |
// Then | |
// insert here the assertions | |
} |
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
// a keyword `suspend` define uma suspending function | |
suspend fun queryUser(id: Int): User { | |
delay(100) // simulando latência de rede ou outra operação lenta | |
return User(id = id, name = "gente.firme", email = "talentos@movile.com") | |
} |
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
interface Continuation<in T> { | |
val context: CoroutineContext | |
fun resume(value: T) | |
fun resumeWithException(exception: Throwable) | |
} |
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
suspend fun queryUser(id: Int): User { | |
delay(500) // simulando latência de rede ou outra operação lenta | |
return User(id = id, name = "gente.firme", email = "talentos@movile.com", phone = 5511000000000L) | |
} | |
suspend fun sendEmail(destination: String, body: String): Boolean { | |
println("Sending email to $destination with body: $body") | |
delay(1000) // simulando um request/operação lenta | |
val couldSentEmail = Random().nextBoolean() | |
if (couldSentEmail) { |
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
fun sendMessageToUser(userId: Int, message: String, cont: Continuation) { | |
val stateMachine = cont as? CoroutineImpl // verifica se já temos uma máquina de estados instanciada (ou seja, já passamos pelo menos uma vez por essa função) | |
?: object : CoroutineImpl { // cria uma máquina de estados que chama a própria função | |
fun resume(...) { | |
sendMessageToUser(userId, message, this) // Hooray, Callback | |
} | |
} | |
switch(stateMachine.label) { | |
case 0: // Kotlin usa labels para saber em qual passo estamos |
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
sealed class ActorCommand<out T> { | |
class REGISTER<T>(val id: Int, val name: String, val response: SendChannel<T>? = null) : ActorCommand<T>() | |
class REMOVE<T>(val id: Int, val response: SendChannel<T>? = null) : ActorCommand<T>() | |
class QUERY<T>(val response: SendChannel<T>) : ActorCommand<T>() | |
} | |
val actorJob = actor<ActorCommand<Any?>> { | |
val state = mutableMapOf<Int, String>() | |
for (msg in channel) { | |
when (msg) { |
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
// define uma função para criar um future | |
// exemplo de uso: | |
// val stringFuture = future { “yay” } | |
// println(stringFuture.get()) | |
fun <T> future(context: CoroutineContext = CommonPool, block: suspend () -> T): CompletableFuture<T> = | |
CompletableFutureCoroutine<T>(context).also { | |
block.startCoroutine(completion = it) | |
} | |
class CompletableFutureCoroutine<T>(override val context: CoroutineContext) : CompletableFuture<T>(), Continuation<T> { |