Created
May 25, 2022 09:08
-
-
Save danielsiwiec/40e9ac49dccf137c5aa45cb06ae92fae to your computer and use it in GitHub Desktop.
Order Processing - Choreography - Email 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 EmailService(private val customerEmails: MutableMap<Int, String> = mutableMapOf()) { | |
@KafkaListener(topics = [ORDERS, SHIPMENTS, PAYMENTS]) | |
fun onOrder(order: Order) { | |
customerEmails[order.customerId]?.let { emailGateway.notify(it, "order now at status: ${order.status}") } | |
?: throw RuntimeException("Customer email not found") | |
} | |
@KafkaListener(topics = [CUSTOMERS]) | |
fun onCustomer(customer: Customer) { | |
customerEmails[customer.id] = customer.email | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment