Skip to content

Instantly share code, notes, and snippets.

@danielsiwiec
Last active May 25, 2022 08:54
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/11df70cea8b46984063d97fab590d136 to your computer and use it in GitHub Desktop.
Save danielsiwiec/11df70cea8b46984063d97fab590d136 to your computer and use it in GitHub Desktop.
Order Processing - Choreography - Order Service
class OrderService(private val availableSkus:MutableList<Int> = mutableListOf()) {
fun submitOrder(order: Order) {
sendMessage(
ORDERS,
order.withStatus(if (availableSkus.containsAll(order.items)) SUBMITTED else ITEMS_UNAVAILABLE)
)
}
@KafkaListener(topics = [SKUS])
fun onSku(sku: Sku) {
if (sku.onStock > 0) availableSkus.add(sku.id) else availableSkus.remove(sku.id)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment