Skip to content

Instantly share code, notes, and snippets.

@danielsiwiec
Last active May 25, 2022 09:05
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/240f294f891defcbd11b1cd35bf6b6eb to your computer and use it in GitHub Desktop.
Save danielsiwiec/240f294f891defcbd11b1cd35bf6b6eb to your computer and use it in GitHub Desktop.
Order Processing - Choreography - Shipment Service
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