Last active
May 25, 2022 09:05
-
-
Save danielsiwiec/240f294f891defcbd11b1cd35bf6b6eb to your computer and use it in GitHub Desktop.
Order Processing - Choreography - Shipment Service
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
class ShipmentService(private val customerAddresses: MutableMap<Int, String> = mutableMapOf()) { | |
@KafkaListener(topics = [PAYMENTS]) | |
fun onOrder(order: Order) { | |
if (order.status !== PAID) return | |
sendShipment(order, customerAddresses[order.customerId] ?: throw RuntimeException("No address for customer ${order.customerId}")) | |
sendMessage(SHIPMENTS, order.withStatus(SHIPPED)) | |
} | |
@KafkaListener(topics = [CUSTOMERS]) | |
fun onCustomer(customer: Customer) { | |
customerAddresses[customer.id] = customer.address | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment