Skip to content

Instantly share code, notes, and snippets.

@danielsiwiec
Created May 25, 2022 08:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielsiwiec/d46d6cd172194025e8e13447c0779205 to your computer and use it in GitHub Desktop.
Save danielsiwiec/d46d6cd172194025e8e13447c0779205 to your computer and use it in GitHub Desktop.
Order Processing - Choreography - Inventory Service
class InventoryService(private val inventory: MutableMap<Int, Sku> = mutableMapOf()) {
@KafkaListener(topics = [SHIPMENTS])
fun onOrder(order: Order) {
if (order.status !== SHIPPED) return
order.items.forEach {
inventory.computeIfPresent(it) { _, v -> v.decrementStock().also { sku -> sendMessage(SKUS, sku) } }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment