Skip to content

Instantly share code, notes, and snippets.

@danielsiwiec
Created May 25, 2022 09:08
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/40e9ac49dccf137c5aa45cb06ae92fae to your computer and use it in GitHub Desktop.
Save danielsiwiec/40e9ac49dccf137c5aa45cb06ae92fae to your computer and use it in GitHub Desktop.
Order Processing - Choreography - Email Service
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